Skip to content

Commit

Permalink
Back out "allow passing dynamic shape information in examples dir" (p…
Browse files Browse the repository at this point in the history
…ytorch#1485)

Summary:
Pull Request resolved: pytorch#1485

D52301732 broke a bunch of OSS CI jobs. Revert it for now.

Reviewed By: larryliu0820

Differential Revision: D52418263

fbshipit-source-id: 1c86682250bb9fb4e99c0984d81e62952a9bc2f1
  • Loading branch information
dbort authored and facebook-github-bot committed Dec 26, 2023
1 parent 9d9ba29 commit 7464600
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 50 deletions.
2 changes: 1 addition & 1 deletion backends/apple/mps/test/test_mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def run_model(
):
logging.info(f"Step 1: Retrieving model: {model}...")
if model_type == MODEL_TYPE.EXIR_DEFAULT_MODEL:
m, m_inputs, _ = EagerModelFactory.create_model(*MODEL_NAME_TO_MODEL[model])
m, m_inputs = EagerModelFactory.create_model(*MODEL_NAME_TO_MODEL[model])
elif model_type == MODEL_TYPE.EXIR_TEST_MODEL:
m, m_inputs = EXIR_MODEL_NAME_TO_MODEL.get(model)()
elif model_type == MODEL_TYPE.MPS_TEST_MODEL:
Expand Down
2 changes: 1 addition & 1 deletion examples/apple/coreml/scripts/export_and_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def save_processed_bytes(processed_bytes, model_name, compute_units):
f"Valid compute units are {compute_units}."
)

model, example_inputs, _ = EagerModelFactory.create_model(
model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL[args.model_name]
)

Expand Down
2 changes: 1 addition & 1 deletion examples/apple/mps/scripts/mps_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
if args.model_name not in MODEL_NAME_TO_MODEL:
raise RuntimeError(f"Available models are {list(MODEL_NAME_TO_MODEL.keys())}.")

model, example_inputs, _ = EagerModelFactory.create_model(
model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL[args.model_name]
)

Expand Down
2 changes: 1 addition & 1 deletion examples/models/llama2/export_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main() -> None:

args = parser.parse_args()

model, example_inputs, _ = EagerModelFactory.create_model(
model, example_inputs = EagerModelFactory.create_model(
"llama2", "Llama2Model", checkpoint=args.checkpoint, params=args.params
)

Expand Down
11 changes: 2 additions & 9 deletions examples/models/model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EagerModelFactory:
@staticmethod
def create_model(
module_name, model_class_name, **kwargs
) -> Tuple[torch.nn.Module, Any, Any]:
) -> Tuple[torch.nn.Module, Any]:
"""
Create an instance of a model class that implements EagerModelBase and retrieve related data.
Expand All @@ -41,14 +41,7 @@ def create_model(
if hasattr(module, model_class_name):
model_class = getattr(module, model_class_name)
model = model_class(**kwargs)
if hasattr(model, "get_dynamic_shapes"):
return (
model.get_eager_model(),
model.get_example_inputs(),
model.get_dynamic_shapes(),
)
else:
return model.get_eager_model(), model.get_example_inputs(), None
return model.get_eager_model(), model.get_example_inputs()

raise ValueError(
f"Model class '{model_class_name}' not found in module '{module_name}'."
Expand Down
24 changes: 2 additions & 22 deletions examples/portable/scripts/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
import argparse
import logging

from executorch.examples.portable.utils import export_to_edge
from executorch.exir.capture import EdgeCompileConfig

from executorch.exir.capture._config import ExecutorchBackendConfig

from ...models import MODEL_NAME_TO_MODEL
Expand Down Expand Up @@ -47,29 +44,12 @@ def main() -> None:
f"Available models are {list(MODEL_NAME_TO_MODEL.keys())}."
)

model, example_inputs, dynamic_shapes = EagerModelFactory.create_model(
model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL[args.model_name]
)

config = ExecutorchBackendConfig(extract_constant_segment=args.constant_segment)
if (
dynamic_shapes is not None
): # capture_pre_autograd_graph does not work with dynamic shapes
edge_manager = export_to_edge(
model,
example_inputs,
dynamic_shapes=dynamic_shapes,
edge_compile_config=EdgeCompileConfig(
_check_ir_validity=False,
),
)
prog = edge_manager.to_executorch(
ExecutorchBackendConfig(extract_constant_segment=True)
)
else:
prog = export_to_exec_prog(
model, example_inputs, dynamic_shapes=dynamic_shapes, backend_config=config
)
prog = export_to_exec_prog(model, example_inputs, backend_config=config)
save_pte_program(prog.buffer, args.model_name, args.output_dir)


Expand Down
4 changes: 2 additions & 2 deletions examples/portable/scripts/export_and_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def export_composite_module_with_lower_graph():
"Running the example to export a composite module with lowered graph..."
)

m, m_inputs, _ = EagerModelFactory.create_model(*MODEL_NAME_TO_MODEL["add_mul"])
m, m_inputs = EagerModelFactory.create_model(*MODEL_NAME_TO_MODEL["add_mul"])
m_compile_spec = m.get_compile_spec()

# pre-autograd export. eventually this will become torch.export
Expand Down Expand Up @@ -168,7 +168,7 @@ def export_and_lower_the_whole_graph():
"""
logging.info("Running the example to export and lower the whole graph...")

m, m_inputs, _ = EagerModelFactory.create_model(*MODEL_NAME_TO_MODEL["add_mul"])
m, m_inputs = EagerModelFactory.create_model(*MODEL_NAME_TO_MODEL["add_mul"])
m_compile_spec = m.get_compile_spec()

m_inputs = m.get_example_inputs()
Expand Down
16 changes: 8 additions & 8 deletions examples/portable/test/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def validate_tensor_allclose(eager_output, executorch_output, rtol=1e-5, atol=1e
return result

def test_mv3_export_to_executorch(self):
eager_model, example_inputs, _ = EagerModelFactory.create_model(
eager_model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL["mv3"]
)
eager_model = eager_model.eval()
Expand All @@ -75,7 +75,7 @@ def test_mv3_export_to_executorch(self):
)

def test_mv2_export_to_executorch(self):
eager_model, example_inputs, _ = EagerModelFactory.create_model(
eager_model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL["mv2"]
)
eager_model = eager_model.eval()
Expand All @@ -85,7 +85,7 @@ def test_mv2_export_to_executorch(self):
)

def test_vit_export_to_executorch(self):
eager_model, example_inputs, _ = EagerModelFactory.create_model(
eager_model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL["vit"]
)
eager_model = eager_model.eval()
Expand All @@ -95,7 +95,7 @@ def test_vit_export_to_executorch(self):
)

def test_w2l_export_to_executorch(self):
eager_model, example_inputs, _ = EagerModelFactory.create_model(
eager_model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL["w2l"]
)
eager_model = eager_model.eval()
Expand All @@ -105,7 +105,7 @@ def test_w2l_export_to_executorch(self):
)

def test_ic3_export_to_executorch(self):
eager_model, example_inputs, _ = EagerModelFactory.create_model(
eager_model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL["ic3"]
)
eager_model = eager_model.eval()
Expand All @@ -115,7 +115,7 @@ def test_ic3_export_to_executorch(self):
)

def test_resnet18_export_to_executorch(self):
eager_model, example_inputs, _ = EagerModelFactory.create_model(
eager_model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL["resnet18"]
)
eager_model = eager_model.eval()
Expand All @@ -125,7 +125,7 @@ def test_resnet18_export_to_executorch(self):
)

def test_resnet50_export_to_executorch(self):
eager_model, example_inputs, _ = EagerModelFactory.create_model(
eager_model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL["resnet50"]
)
eager_model = eager_model.eval()
Expand All @@ -135,7 +135,7 @@ def test_resnet50_export_to_executorch(self):
)

def test_dl3_export_to_executorch(self):
eager_model, example_inputs, _ = EagerModelFactory.create_model(
eager_model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL["dl3"]
)
eager_model = eager_model.eval()
Expand Down
2 changes: 1 addition & 1 deletion examples/qualcomm/scripts/export_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
f"Available models are {list(MODEL_NAME_TO_MODEL.keys())}."
)

model, example_inputs, _ = EagerModelFactory.create_model(
model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL[args.model_name]
)

Expand Down
2 changes: 1 addition & 1 deletion examples/sdk/scripts/export_bundled_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def main() -> None:
f"Available models are {list(MODEL_NAME_TO_MODEL.keys())}."
)

model, example_inputs, _ = EagerModelFactory.create_model(
model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL[args.model_name]
)

Expand Down
2 changes: 1 addition & 1 deletion examples/sdk/scripts/gen_sample_etrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def main() -> None:
f"Available models are {list(MODEL_NAME_TO_MODEL.keys())}."
)

model, example_inputs, _ = EagerModelFactory.create_model(
model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL[args.model_name]
)

Expand Down
2 changes: 1 addition & 1 deletion examples/xnnpack/aot_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
f"Available models are {list(MODEL_NAME_TO_OPTIONS.keys())}."
)

model, example_inputs, _ = EagerModelFactory.create_model(
model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL[args.model_name]
)

Expand Down
2 changes: 1 addition & 1 deletion examples/xnnpack/quantization/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def main() -> None:
)

start = time.perf_counter()
model, example_inputs, _ = EagerModelFactory.create_model(
model, example_inputs = EagerModelFactory.create_model(
*MODEL_NAME_TO_MODEL[args.model_name]
)
end = time.perf_counter()
Expand Down

0 comments on commit 7464600

Please sign in to comment.