MCPcopy Create free account
hub / github.com/pytorch/executorch / quantize_and_lower_module

Function quantize_and_lower_module

backends/vulkan/test/test_vulkan_passes.py:42–70  ·  view source on GitHub ↗
(
    model: torch.nn.Module,
    sample_inputs: Tuple[torch.Tensor],
    quantizer: Quantizer,
    dynamic_shapes=None,
)

Source from the content-addressed store, hash-verified

40
41
42def quantize_and_lower_module(
43 model: torch.nn.Module,
44 sample_inputs: Tuple[torch.Tensor],
45 quantizer: Quantizer,
46 dynamic_shapes=None,
47) -> EdgeProgramManager:
48 edge_compile_config = EdgeCompileConfig(
49 _skip_dim_order=False, # TODO(T182928844): Delegate dim order op to backend.
50 _check_ir_validity=False,
51 )
52
53 program = torch.export.export(
54 model, sample_inputs, dynamic_shapes=dynamic_shapes, strict=True
55 ).module()
56
57 program = prepare_pt2e(program, quantizer) # pyre-ignore
58 # Calibrate
59 program(*sample_inputs)
60
61 program = convert_pt2e(program)
62
63 program = torch.export.export(program, sample_inputs, dynamic_shapes=dynamic_shapes)
64
65 edge_program = to_edge(
66 program,
67 compile_config=edge_compile_config,
68 )
69
70 return edge_program
71
72
73def get_target_canonical_name(node: torch.fx.Node) -> Optional[str]:

Calls 4

EdgeCompileConfigClass · 0.90
to_edgeFunction · 0.90
moduleMethod · 0.80
exportMethod · 0.45

Tested by

no test coverage detected