Skip to content
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

Use quantize_and_export_to_jarvis in more places #3686

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions backends/cadence/aot/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@


def export_program(
model: Callable,
model: torch.nn.Module,
Copy link
Contributor

Choose a reason for hiding this comment

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

This line seems to be duplicated from #3676, is that a mistake? Are these stacked incorrectly?

inputs: Any,
pt2_quant: bool = False,
) -> ExportedProgram:
# we don't support training mode. Make it eval
# We don't support training mode. Make it eval
if hasattr(model, "eval"):
if pt2_quant:
# pyre-fixme[6]: Incompatible parameter type.
# If the model is already a GraphModule (most likely from quantization),
# it can't call eval. Call the suggested torch.ao.quantization API instead,
# which only does dropout and batchnorm.
if isinstance(model, torch.fx.GraphModule):
torch.ao.quantization.move_exported_model_to_eval(model)
else:
# pyre-fixme[16]: Anonymous callable has no attribute `eval`.
model.eval()

# if it's already an ExportedProgram, just return it
Expand All @@ -46,11 +46,10 @@ def export_program(
def export_to_edge(
model: Callable,
inputs: Any,
pt2_quant: bool = False,
dump_graphs: bool = False,
) -> Tuple[EdgeProgramManager, ExportedProgram]:
# Export the model into an ExportedProgram.
expo_program = export_program(model, inputs, pt2_quant)
expo_program = export_program(model, inputs)

if dump_graphs:
logging.info(f"Exported graph:\n{expo_program.graph_module.graph}")
Expand Down
4 changes: 1 addition & 3 deletions backends/cadence/aot/export_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ def export_model(
QuantFusion(patterns)(converted_model)

# Get edge program (note: the name will change to export_to_cadence in future PRs)
edge_prog_manager, expo_prog = export_to_edge(
converted_model, example_inputs, pt2_quant=True
)
edge_prog_manager, expo_prog = export_to_edge(converted_model, example_inputs)

# Run a couple required passes for quant/dequant ops
cadence_prog_manager = edge_prog_manager.transform(
Expand Down
Loading