Skip to content

Commit da993fd

Browse files
gmagogsfmfacebook-github-bot
authored andcommitted
Add transform_exported_program stub to ease renaming of transform method (#135)
Summary: Pull Request resolved: #135 To avoid using co-dev mode, I am adding a helper that automatically tries both _transform and transform on ExportedProgram. Then I will be able to change OSS code without breaking internal tests. Reviewed By: angelayi Differential Revision: D48668701 fbshipit-source-id: 20758420a20c9d0134ed88882838a3f7b1039e51
1 parent e6bdec2 commit da993fd

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

docs/website/docs/tutorials/exporting_to_executorch.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ ExportedProgram:
9292
```
9393

9494
At this point, users can choose to run additional passes through the
95-
`exported_program.transform(passes)` function. A tutorial on how to write
95+
`exported_program._transform(passes)` function. A tutorial on how to write
9696
transformations can be found [here](./passes.md).
9797

9898
Additionally, users can run quantization at this step. A tutorial for doing so can be found [here](./quantization_flow.md).
@@ -128,7 +128,7 @@ ExportedProgram:
128128
```
129129

130130
Users can also choose to run additional passes through the
131-
`exported_program.transform(passes)` function. A tutorial on how to write
131+
`exported_program._transform(passes)` function. A tutorial on how to write
132132
transformations can be found [here](./passes.md). Note that since the graph is
133133
now in Edge Dialect, all passes must also result in a valid Edge Dialect graph
134134
(specifically one thing to point out is that the operators are now in the

exir/capture/_capture.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from executorch.exir.capture._config import CaptureConfig
1616
from executorch.exir.error import ExportError, ExportErrorType, InternalError
1717
from executorch.exir.program import ExirExportedProgram, MultiMethodExirExportedProgram
18+
from executorch.exir.program._program import transform_exported_program
1819
from executorch.exir.tracer import (
1920
_default_decomposition_table,
2021
dispatch_trace,
@@ -82,7 +83,7 @@ def capture(
8283
# TODO remove this later
8384
with patch("torch._export.DECOMP_TABLE", _default_decomposition_table()):
8485
ep = export(f, args, constraints=constraints)
85-
ep = ep.transform(ReplaceViewOpsWithViewCopyOpsPass())
86+
ep = transform_exported_program(ep, ReplaceViewOpsWithViewCopyOpsPass())
8687
if not config._unlift:
8788
return ExirExportedProgram(ep, False)
8889
graph_module = ep.module()

exir/program/_program.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
Val = Any
3535

3636

37+
# Stub to ease migration from `transform` to private `_transform`
38+
def transform_exported_program(ep, *passes: PassType) -> ExportedProgram:
39+
if hasattr(ep, "_transform"):
40+
return ep._transform(*passes)
41+
else:
42+
return ep.transform(*passes)
43+
44+
3745
@compatibility(is_backward_compatible=False)
3846
class ExirExportedProgram:
3947
def __init__(
@@ -48,7 +56,9 @@ def __init__(
4856
self.after_to_edge_passes = after_to_edge_passes
4957

5058
def transform(self, *passes: PassType) -> "ExirExportedProgram":
51-
self.exported_program = self.exported_program.transform(*passes)
59+
self.exported_program = transform_exported_program(
60+
self.exported_program, *passes
61+
)
5262
return self
5363

5464
def __call__(self, *args: Any) -> Any:
@@ -76,7 +86,7 @@ def to_executorch(
7686
raise RuntimeError("Must run to_edge before to_executorch.")
7787
config = config or ExecutorchBackendConfig()
7888
ep = self.exported_program
79-
new_prog = ep.transform(*edge_to_executorch_passes(config))
89+
new_prog = transform_exported_program(ep, *edge_to_executorch_passes(config))
8090
new_prog = ExirExportedProgram(new_prog, self.after_to_edge_passes)
8191
executorch_prog = ExecutorchProgram(
8292
new_prog,

0 commit comments

Comments
 (0)