Skip to content

[ez][release blocker fix] Insert linalg_vector_norm into decomp table used for Edge export #9938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025

Conversation

SS-JIA
Copy link
Contributor

@SS-JIA SS-JIA commented Apr 7, 2025

Summary:

Context

Addresses this release blocker issue. Some models cannot export because they use linalg_vector_norm which is not currently an ATen operator.

I initially tried adding the op to the core decomp table, but the decomp is not passing pytorch correctness tests. Please see pytorch/pytorch#150241 for more details.

Changes

Since we currently cannot include the op in PyTorch's decomp table, instead we can insert the op into the edge decomp table directly.

This PR is a simple change to add linalg_vector_norm directly to the edge decomp table.

Test Plan:
Tested exporting and running a model with the linalg_vector_norm op via the following script.

import torch
from executorch.exir import to_edge_transform_and_lower, EdgeCompileConfig
from torch.export import Dim, export

from executorch.extension.pybindings.portable_lib import (  # @manual
    _load_for_executorch_from_buffer,
)

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x):
        return torch.linalg.vector_norm(x, 2)

model = Model()
inputs = (torch.randn(1,1,16,16),)
dynamic_shapes = {
    "x": {
        2: Dim("h", min=16, max=1024),
        3: Dim("w", min=16, max=1024),
    }
}

exported_program = export(model, inputs, dynamic_shapes=dynamic_shapes)
executorch_program = to_edge_transform_and_lower(
    exported_program,
    compile_config=EdgeCompileConfig(_check_ir_validity=False),
).to_executorch()


executorch_module = _load_for_executorch_from_buffer(
    executorch_program.buffer
)

model_output = executorch_module.run_method(
    "forward", tuple(inputs)
)

print(model_output)

Copy link

pytorch-bot bot commented Apr 7, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/9938

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures

As of commit 60b6d51 with merge base f28b5db (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 7, 2025
Copy link

github-actions bot commented Apr 7, 2025

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copy link
Contributor

@guangy10 guangy10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a unit test for it? Something you mentioned in the test plan can be placed to the test to prevent regression

…le used for Edge export

Summary:
## Context

Addresses this [release blocker](https://github.com/orgs/pytorch/projects/99/views/1?pane=issue&itemId=104088363&issue=pytorch%7Cpytorch%7C150207) issue. Some models cannot export because they use `linalg_vector_norm` which is not currently an ATen operator.

I initially tried adding the op to the core decomp table, but the decomp is not passing pytorch correctness tests. Please see pytorch/pytorch#150241 for more details.

## Changes

Since we currently cannot include the op in PyTorch's decomp table, instead we can insert the op into the edge decomp table directly.

This PR is a simple change to add `linalg_vector_norm` directly to the edge decomp table.

Test Plan:
Tested exporting and running a model with the `linalg_vector_norm` op via the following script.

```
import torch
from executorch.exir import to_edge_transform_and_lower, EdgeCompileConfig
from torch.export import Dim, export

from executorch.extension.pybindings.portable_lib import (  # @Manual
    _load_for_executorch_from_buffer,
)

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x):
        return torch.linalg.vector_norm(x, 2)

model = Model()
inputs = (torch.randn(1,1,16,16),)
dynamic_shapes = {
    "x": {
        2: Dim("h", min=16, max=1024),
        3: Dim("w", min=16, max=1024),
    }
}

exported_program = export(model, inputs, dynamic_shapes=dynamic_shapes)
executorch_program = to_edge_transform_and_lower(
    exported_program,
    compile_config=EdgeCompileConfig(_check_ir_validity=False),
).to_executorch()


executorch_module = _load_for_executorch_from_buffer(
    executorch_program.buffer
)

model_output = executorch_module.run_method(
    "forward", tuple(inputs)
)

print(model_output)
```
@SS-JIA
Copy link
Contributor Author

SS-JIA commented Apr 9, 2025

Fix test by swapping to another non core op.

@SS-JIA SS-JIA merged commit c2e3e17 into main Apr 9, 2025
82 of 159 checks passed
@SS-JIA SS-JIA deleted the pr9938 branch April 9, 2025 17:48
@SS-JIA
Copy link
Contributor Author

SS-JIA commented Apr 9, 2025

@pytorchbot cherry-pick --onto release/0.6 -c critical

pytorchbot pushed a commit that referenced this pull request Apr 9, 2025
…le used for Edge export (#9938)

Summary:
## Context

Addresses this [release
blocker](https://github.com/orgs/pytorch/projects/99/views/1?pane=issue&itemId=104088363&issue=pytorch%7Cpytorch%7C150207)
issue. Some models cannot export because they use `linalg_vector_norm`
which is not currently an ATen operator.

I initially tried adding the op to the core decomp table, but the decomp
is not passing pytorch correctness tests. Please see
pytorch/pytorch#150241 for more details.

## Changes

Since we currently cannot include the op in PyTorch's decomp table,
instead we can insert the op into the edge decomp table directly.

This PR is a simple change to add `linalg_vector_norm` directly to the
edge decomp table.

Test Plan:
Tested exporting and running a model with the `linalg_vector_norm` op
via the following script.

```
import torch
from executorch.exir import to_edge_transform_and_lower, EdgeCompileConfig
from torch.export import Dim, export

from executorch.extension.pybindings.portable_lib import (  # @Manual
    _load_for_executorch_from_buffer,
)

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x):
        return torch.linalg.vector_norm(x, 2)

model = Model()
inputs = (torch.randn(1,1,16,16),)
dynamic_shapes = {
    "x": {
        2: Dim("h", min=16, max=1024),
        3: Dim("w", min=16, max=1024),
    }
}

exported_program = export(model, inputs, dynamic_shapes=dynamic_shapes)
executorch_program = to_edge_transform_and_lower(
    exported_program,
    compile_config=EdgeCompileConfig(_check_ir_validity=False),
).to_executorch()

executorch_module = _load_for_executorch_from_buffer(
    executorch_program.buffer
)

model_output = executorch_module.run_method(
    "forward", tuple(inputs)
)

print(model_output)
```

(cherry picked from commit c2e3e17)
@pytorchbot
Copy link
Collaborator

Cherry picking #9938

The cherry pick PR is at #9999 and it is recommended to link a critical cherry pick PR with an issue. The following tracker issues are updated:

Details for Dev Infra team Raised by workflow job

SS-JIA added a commit that referenced this pull request Apr 10, 2025
Summary:
## Context

#9938 made it so that `linalg_vector_norm` is now decomposed when exporting to Edge. However, this broke some tests in the arm delegate which does not expect the op to be decomposed.

## Changes

Add `linalg_vector_norm` to the list of ops not to decompose in the arm partitioner.

Test Plan:
## Test Plan

Check CI that failing test is recovered.
kimishpatel added a commit that referenced this pull request Apr 10, 2025
…nalg_vector_norm` into decomp table used for Edge export (#9938)

## Context

Addresses this [release
blocker](https://github.com/orgs/pytorch/projects/99/views/1?pane=issue&itemId=104088363&issue=pytorch%7Cpytorch%7C150207)
issue. Some models cannot export because they use `linalg_vector_norm`
which is not currently an ATen operator.

I initially tried adding the op to the core decomp table, but the decomp
is not passing pytorch correctness tests. Please see
pytorch/pytorch#150241 for more details.

## Changes

Since we currently cannot include the op in PyTorch's decomp table,
instead we can insert the op into the edge decomp table directly.

This PR is a simple change to add `linalg_vector_norm` directly to the
edge decomp table.


Internal:
<< DO NOT EDIT BELOW THIS LINE >>

**GitHub Author**: Sicheng Stephen Jia <[email protected]> (Meta Employee)
**GitHub Repo**: [pytorch/executorch](https://github.com/pytorch/executorch)
**GitHub Pull Request**: [#9938](#9938)

Initially generated by: https://www.internalfb.com/intern/sandcastle/job/4503601401156690/

This was imported as part of a Diff Train.
Please review this as soon as possible. Since it is a direct copy of a commit on
GitHub, there shouldn't be much to do.

diff-train-source-id: c2e3e17

Differential Revision: [D72729066](https://our.internmc.facebook.com/intern/diff/D72729066/)

[ghstack-poisoned]
SS-JIA added a commit that referenced this pull request Apr 10, 2025
Summary:
## Context

#9938 made it so that `linalg_vector_norm` is now decomposed when exporting to Edge. However, this broke some tests in the arm delegate because export passes cannot handle the decomposed operator sequence. To account for this, add `xfail` for the failing tests since `linalg_vector_norm` is not supported in TOSA yet.


## Changes

Add `xfail` for `norm` tests in `test_torch_functions.py`

Test Plan:
## Test Plan

Check CI that failing test is recovered.
SS-JIA added a commit that referenced this pull request Apr 10, 2025
Summary:
## Context

#9938 made it so that
`linalg_vector_norm` is now decomposed when exporting to Edge. However,
this broke some tests in the arm delegate because export passes cannot
handle the decomposed operator sequence. To account for this, add
`xfail` for the failing tests since `linalg_vector_norm` is not
supported in TOSA yet.


## Changes

Add `xfail` for `norm` tests in `test_torch_functions.py`

Test Plan:
## Test Plan

Check CI that failing test is recovered.
pytorchbot pushed a commit that referenced this pull request Apr 10, 2025
Summary:
## Context

#9938 made it so that
`linalg_vector_norm` is now decomposed when exporting to Edge. However,
this broke some tests in the arm delegate because export passes cannot
handle the decomposed operator sequence. To account for this, add
`xfail` for the failing tests since `linalg_vector_norm` is not
supported in TOSA yet.

## Changes

Add `xfail` for `norm` tests in `test_torch_functions.py`

Test Plan:
## Test Plan

Check CI that failing test is recovered.

(cherry picked from commit f2a08da)
metascroy pushed a commit that referenced this pull request Apr 10, 2025
Summary:
## Context

#9938 made it so that
`linalg_vector_norm` is now decomposed when exporting to Edge. However,
this broke some tests in the arm delegate because export passes cannot
handle the decomposed operator sequence. To account for this, add
`xfail` for the failing tests since `linalg_vector_norm` is not
supported in TOSA yet.


## Changes

Add `xfail` for `norm` tests in `test_torch_functions.py`

Test Plan:
## Test Plan

Check CI that failing test is recovered.

Co-authored-by: Sicheng Stephen Jia <[email protected]>
kirklandsign pushed a commit that referenced this pull request Apr 11, 2025
…le used for Edge export (#9938)

Summary:
## Context

Addresses this [release
blocker](https://github.com/orgs/pytorch/projects/99/views/1?pane=issue&itemId=104088363&issue=pytorch%7Cpytorch%7C150207)
issue. Some models cannot export because they use `linalg_vector_norm`
which is not currently an ATen operator.

I initially tried adding the op to the core decomp table, but the decomp
is not passing pytorch correctness tests. Please see
pytorch/pytorch#150241 for more details.

## Changes

Since we currently cannot include the op in PyTorch's decomp table,
instead we can insert the op into the edge decomp table directly.

This PR is a simple change to add `linalg_vector_norm` directly to the
edge decomp table.

Test Plan:
Tested exporting and running a model with the `linalg_vector_norm` op
via the following script.

```
import torch
from executorch.exir import to_edge_transform_and_lower, EdgeCompileConfig
from torch.export import Dim, export

from executorch.extension.pybindings.portable_lib import (  # @Manual
    _load_for_executorch_from_buffer,
)

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x):
        return torch.linalg.vector_norm(x, 2)

model = Model()
inputs = (torch.randn(1,1,16,16),)
dynamic_shapes = {
    "x": {
        2: Dim("h", min=16, max=1024),
        3: Dim("w", min=16, max=1024),
    }
}

exported_program = export(model, inputs, dynamic_shapes=dynamic_shapes)
executorch_program = to_edge_transform_and_lower(
    exported_program,
    compile_config=EdgeCompileConfig(_check_ir_validity=False),
).to_executorch()


executorch_module = _load_for_executorch_from_buffer(
    executorch_program.buffer
)

model_output = executorch_module.run_method(
    "forward", tuple(inputs)
)

print(model_output)
```
kirklandsign pushed a commit that referenced this pull request Apr 11, 2025
Summary:
## Context

#9938 made it so that
`linalg_vector_norm` is now decomposed when exporting to Edge. However,
this broke some tests in the arm delegate because export passes cannot
handle the decomposed operator sequence. To account for this, add
`xfail` for the failing tests since `linalg_vector_norm` is not
supported in TOSA yet.


## Changes

Add `xfail` for `norm` tests in `test_torch_functions.py`

Test Plan:
## Test Plan

Check CI that failing test is recovered.
keyprocedure pushed a commit to keyprocedure/executorch that referenced this pull request Apr 21, 2025
…le used for Edge export (pytorch#9938)

Summary:
## Context

Addresses this [release
blocker](https://github.com/orgs/pytorch/projects/99/views/1?pane=issue&itemId=104088363&issue=pytorch%7Cpytorch%7C150207)
issue. Some models cannot export because they use `linalg_vector_norm`
which is not currently an ATen operator.

I initially tried adding the op to the core decomp table, but the decomp
is not passing pytorch correctness tests. Please see
pytorch/pytorch#150241 for more details.

## Changes

Since we currently cannot include the op in PyTorch's decomp table,
instead we can insert the op into the edge decomp table directly.

This PR is a simple change to add `linalg_vector_norm` directly to the
edge decomp table.

Test Plan:
Tested exporting and running a model with the `linalg_vector_norm` op
via the following script.

```
import torch
from executorch.exir import to_edge_transform_and_lower, EdgeCompileConfig
from torch.export import Dim, export

from executorch.extension.pybindings.portable_lib import (  # @Manual
    _load_for_executorch_from_buffer,
)

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x):
        return torch.linalg.vector_norm(x, 2)

model = Model()
inputs = (torch.randn(1,1,16,16),)
dynamic_shapes = {
    "x": {
        2: Dim("h", min=16, max=1024),
        3: Dim("w", min=16, max=1024),
    }
}

exported_program = export(model, inputs, dynamic_shapes=dynamic_shapes)
executorch_program = to_edge_transform_and_lower(
    exported_program,
    compile_config=EdgeCompileConfig(_check_ir_validity=False),
).to_executorch()


executorch_module = _load_for_executorch_from_buffer(
    executorch_program.buffer
)

model_output = executorch_module.run_method(
    "forward", tuple(inputs)
)

print(model_output)
```
keyprocedure pushed a commit to keyprocedure/executorch that referenced this pull request Apr 21, 2025
Summary:
## Context

pytorch#9938 made it so that
`linalg_vector_norm` is now decomposed when exporting to Edge. However,
this broke some tests in the arm delegate because export passes cannot
handle the decomposed operator sequence. To account for this, add
`xfail` for the failing tests since `linalg_vector_norm` is not
supported in TOSA yet.


## Changes

Add `xfail` for `norm` tests in `test_torch_functions.py`

Test Plan:
## Test Plan

Check CI that failing test is recovered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants