qai_hub.submit_compile_job
- submit_compile_job(model, device, name=None, input_specs=None, options='', single_compile=True, calibration_data=None, retry=True, project=None)
Submits a compile job.
- Parameters:
model (
Union[Model,TopLevelTracedModule,ScriptModule,ExportedProgram,ModelProto,bytes,str,Path,None]) – Model to compile. The model must be a PyTorch or an ONNX / ONNX wrappable model (i.e., QNN Context Binary).device (
Device|list[Device]) – Devices for which to compile the input model.name (
Optional[str]) – Optional name for the job. Job names need not be unique.input_specs (
Optional[Mapping[str,tuple[int,...] |tuple[tuple[int,...],str]]]) –Required if
modelis a PyTorch model. Keys inDict(which is ordered in Python 3.7+) define the input names for the target model (e.g., TFLite model) created from this profile job, and may be different from the names in PyTorch model.An input shape can either be a
tuple[int, ...](e.g.,(1, 2, 3)) or atuple[tuple[int, ...], str](e.g.,((1, 2, 3), "int32"))). The latter form can be used to specify the type of the input. If a type is not specified, it defaults to"float32". Currently, only"float32","int8","int16","int32","int64","uint8", and"uint16"are accepted types.For example, a PyTorch module with
forward(self, x, y)may haveinput_specs=dict(a=(1,2), b=(1, 3)). When using the resulting target model (e.g., a TFLite model) from this profile job, the inputs must have keysaandb, notxandy. Similarly, if this target model is used in an inference job (seesubmit_inference_job()), the dataset must have entriesa,bin this order, notx,yIf
modelis an ONNX model,input_specsare optional.input_specscan be used to overwrite the model’s input names and the dynamic extents for the input shapes. Ifinput_specsis notNone, it must be compatible with the model, or the server will return an error.options (
str) – Cli-like flag options. See Compile Options.single_compile (
bool) – IfTrue, submits a single compile job that creates an asset compatible with all devices. IfFalse, create a compile job for each device.calibration_data (
Union[Dataset,Mapping[str,list[ndarray]],str,None]) – Data, Dataset, or Dataset ID to use for post-training quantization. PTQ will be applied to the model during translation.retry (
bool) – If job creation fails due to rate-limiting, keep retrying periodically until creation succeeds.
- Returns:
job – Returns the compile jobs. Always one job if single_compile is
True, and possibly multiple jobs if it isFalse.- Return type:
CompileJob | list[CompileJob]
Examples
Submit a traced Torch model for compile on an Samsung Galaxy S23:
import qai_hub as hub import torch client = hub.Client() pt_model = torch.jit.load("mobilenet.pt") input_specs = (1, 3, 224, 224) model = client.upload_model(pt_model) job = client.submit_compile_job(model, device=hub.Device("Samsung Galaxy S23"), name="mobilenet (1, 3, 224, 224)", input_specs=dict(x=input_specs))
For more examples, see Compiling Models.