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

Function main

examples/xnnpack/quantization/example.py:114–201  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

112
113
114def main() -> None:
115 parser = argparse.ArgumentParser()
116 parser.add_argument(
117 "-m",
118 "--model_name",
119 required=True,
120 help=f"Provide model name. Valid ones: {list(MODEL_NAME_TO_OPTIONS.keys())}",
121 )
122 parser.add_argument(
123 "-ve",
124 "--verify",
125 action="store_true",
126 required=False,
127 default=False,
128 help="flag for verifying XNNPACKQuantizer against fx graph mode quantization",
129 )
130 parser.add_argument(
131 "-s",
132 "--so_library",
133 required=False,
134 help="shared library for quantized operators",
135 )
136
137 args = parser.parse_args()
138 # See if we have quantized op out variants registered
139 has_out_ops = True
140 try:
141 _ = torch.ops.quantized_decomposed.add.out
142 except AttributeError:
143 logging.info("No registered quantized ops")
144 has_out_ops = False
145 if not has_out_ops:
146 if args.so_library:
147 torch.ops.load_library(args.so_library)
148 else:
149 raise RuntimeError(
150 "Need to specify shared library path to register quantized ops (and their out variants) into"
151 "EXIR. The required shared library is defined as `quantized_ops_aot_lib` in "
152 "kernels/quantized/CMakeLists.txt if you are using CMake build, or `aot_lib` in "
153 "kernels/quantized/targets.bzl for buck2. One example path would be cmake-out/kernels/quantized/"
154 "libquantized_ops_aot_lib.[so|dylib]."
155 )
156 if not args.verify and args.model_name not in MODEL_NAME_TO_OPTIONS:
157 raise RuntimeError(
158 f"Model {args.model_name} is not a valid name. or not quantizable right now, "
159 "please contact executorch team if you want to learn why or how to support "
160 "quantization for the requested model"
161 f"Available models are {list(MODEL_NAME_TO_OPTIONS.keys())}."
162 )
163
164 start = time.perf_counter()
165 model, example_inputs, _, _ = EagerModelFactory.create_model(
166 *MODEL_NAME_TO_MODEL[args.model_name]
167 )
168 end = time.perf_counter()
169 # logging.info(f"Model init time: {end - start}s")
170 if args.verify:
171 start = time.perf_counter()

Callers 1

example.pyFile · 0.70

Calls 12

quantizeFunction · 0.90
EdgeCompileConfigClass · 0.90
export_to_edgeFunction · 0.90
save_pte_programFunction · 0.90
keysMethod · 0.80
infoMethod · 0.80
moduleMethod · 0.80
create_modelMethod · 0.45
exportMethod · 0.45
to_executorchMethod · 0.45

Tested by

no test coverage detected