()
| 25 | |
| 26 | |
| 27 | def main() -> None: |
| 28 | parser = argparse.ArgumentParser() |
| 29 | parser.add_argument( |
| 30 | "-m", |
| 31 | "--model_name", |
| 32 | required=True, |
| 33 | help=f"provide a model name. Valid ones: {list(MODEL_NAME_TO_MODEL.keys())}", |
| 34 | ) |
| 35 | parser.add_argument( |
| 36 | "-g", |
| 37 | "--generate_etrecord", |
| 38 | action="store_true", |
| 39 | required=True, |
| 40 | help="Generate ETRecord metadata to link with runtime results (used for profiling)", |
| 41 | ) |
| 42 | |
| 43 | parser.add_argument( |
| 44 | "-f", |
| 45 | "--output_folder", |
| 46 | type=str, |
| 47 | default="", |
| 48 | help="The folder to store the exported program", |
| 49 | ) |
| 50 | |
| 51 | parser.add_argument( |
| 52 | "--soc", |
| 53 | type=str, |
| 54 | default="SM8650", |
| 55 | help="Specify the SoC model.", |
| 56 | ) |
| 57 | |
| 58 | parser.add_argument( |
| 59 | "-q", |
| 60 | "--quantization", |
| 61 | choices=["ptq", "qat"], |
| 62 | help="Run post-traininig quantization.", |
| 63 | ) |
| 64 | |
| 65 | args = parser.parse_args() |
| 66 | |
| 67 | if args.model_name not in MODEL_NAME_TO_MODEL: |
| 68 | raise RuntimeError( |
| 69 | f"Model {args.model_name} is not a valid name. " |
| 70 | f"Available models are {list(MODEL_NAME_TO_MODEL.keys())}." |
| 71 | ) |
| 72 | |
| 73 | # Get model and example inputs |
| 74 | model, example_inputs, _, _ = EagerModelFactory.create_model( |
| 75 | *MODEL_NAME_TO_MODEL[args.model_name] |
| 76 | ) |
| 77 | |
| 78 | # Get quantizer |
| 79 | if args.quantization: |
| 80 | print("Quantizing model...") |
| 81 | # It is the model quantization path |
| 82 | quantizer = QnnQuantizer( |
| 83 | backend=QnnExecuTorchBackendType.kHtpBackend, |
| 84 | soc_model=get_soc_to_chipset_map()[args.soc], |
no test coverage detected