A function to generate an ExecuTorch binary for Qualcomm platforms. Attributes: model (torch.nn.Module): The model to be converted into an ExecuTorch binary. qnn_config: (QnnConfig): A config class that saves qnn lowering and execution configuration. file_name (str)
(
model: torch.nn.Module, # noqa: B006
qnn_config: QnnConfig,
file_name: str,
dataset: List[torch.Tensor] | Callable[[torch.fx.GraphModule], None],
quant_dtype: Optional[QuantDtype] = None,
custom_quantizer: Optional[QnnQuantizer] = None,
metadata=None,
qnn_intermediate_debugger: QNNIntermediateDebugger = None,
passes_job=None,
passes_dependency=None,
qat_training_data=None,
op_package_options: QnnExecuTorchOpPackageOptions = None,
)
| 500 | |
| 501 | |
| 502 | def build_executorch_binary( |
| 503 | model: torch.nn.Module, # noqa: B006 |
| 504 | qnn_config: QnnConfig, |
| 505 | file_name: str, |
| 506 | dataset: List[torch.Tensor] | Callable[[torch.fx.GraphModule], None], |
| 507 | quant_dtype: Optional[QuantDtype] = None, |
| 508 | custom_quantizer: Optional[QnnQuantizer] = None, |
| 509 | metadata=None, |
| 510 | qnn_intermediate_debugger: QNNIntermediateDebugger = None, |
| 511 | passes_job=None, |
| 512 | passes_dependency=None, |
| 513 | qat_training_data=None, |
| 514 | op_package_options: QnnExecuTorchOpPackageOptions = None, |
| 515 | ): |
| 516 | """ |
| 517 | A function to generate an ExecuTorch binary for Qualcomm platforms. |
| 518 | |
| 519 | Attributes: |
| 520 | model (torch.nn.Module): The model to be converted into an ExecuTorch binary. |
| 521 | qnn_config: (QnnConfig): A config class that saves qnn lowering and execution configuration. |
| 522 | file_name (str): Name for the output binary file (.pte). |
| 523 | dataset (List[torch.Tensor] | Callable): A dataset for quantization calibration. |
| 524 | quant_dtype (QuantDtype, optional): Data type for quantization. |
| 525 | custom_quantizer (Callable, optional): Custom quantizer. |
| 526 | metadata (dict, optional): An optional dictionary that maps each method name to a constant value in eager mode. |
| 527 | passes_job (OrderedDict, optional): Custom passes job in to_edge_transform_and_lower, users can enable/disable specific passes or modify their attributes. |
| 528 | passes_dependency (Dict, optional): A dictionary mapping each pass to its corresponding list of dependencies. |
| 529 | qat_training_data (List[torch.Tensor], optional): A dataset for quantization aware training(QAT). Typically is a pair of tensors, such as [features, ground truth]. |
| 530 | op_package_options: Optional structure to specify op packages |
| 531 | loaded and used by the backend. |
| 532 | |
| 533 | Returns: |
| 534 | None: The function writes the output to a specified .pte file. |
| 535 | """ |
| 536 | if qnn_config.pre_gen_pte: |
| 537 | logging.info( |
| 538 | f"Skip build_executorch_binary, using {file_name} under {qnn_config.pre_gen_pte}." |
| 539 | ) |
| 540 | return |
| 541 | |
| 542 | sample_input = dataset[0] |
| 543 | if ( |
| 544 | qnn_config.backend == QnnExecuTorchBackendType.kGpuBackend |
| 545 | and not qnn_config.online_prepare |
| 546 | ): |
| 547 | raise RuntimeError( |
| 548 | "Currently GPU backend only supports online_prepare. Please add --online_prepare flag." |
| 549 | ) |
| 550 | if ( |
| 551 | qnn_config.backend == QnnExecuTorchBackendType.kLpaiBackend |
| 552 | and qnn_config.online_prepare |
| 553 | ): |
| 554 | raise RuntimeError("Currently LPAI backend only supports offline_prepare.") |
| 555 | backend_options = { |
| 556 | QnnExecuTorchBackendType.kLpaiBackend: generate_lpai_compiler_spec( |
| 557 | target_env=get_lpai_target_env(qnn_config) |
| 558 | ), |
| 559 | QnnExecuTorchBackendType.kGpuBackend: generate_gpu_compiler_spec(), |
no test coverage detected