# qairt.api.compiler

## qairt.api.compiler.config

- *class* qairt.api.compiler.config.CompileConfig(*\*args: Any*, *\*\*kwargs: Any*)

    - Configuration for AOT compilation.

Example:

config_sm8550 = CompileConfig(backend="HTP", soc_details="chipset:SM8550")
    
    htp_graph_config = HtpGraphConfig(name="graph_A", optimization_type=3)
    config_O3 = CompileConfig(backend="HTP", graph_custom_configs=[htp_graph_config])
    Copy to clipboard

Note

Custom Configs -  Each &lt;prefix&gt;\_custom\_configs maps to backend specific settings that can be
set for QNN API components. Each backend has its own suite of customizable settings.
Use `qairt.api.common.backends.htp.list_options()` to see the list of available options
for HTP.

- backend*: [qairt.api.configs.common.BackendType](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-configs.html#qairt.api.configs.common.BackendType) | str*

    - 

- backend\_binary\_path*: Optional[str]*  *= None*

    - Name or path of the binary file to save a backend-specific context binary to with .bin file extension.
The file name is expected to have the suffix \_backend. If not provided, the suffix would be added.
File name can be, for example, myqpc.bin or myqpc (without the .bin extension).
If not provided, no backend binary is created. If absolute path is provided, binary is saved in this path.

- compiler\_custom\_configs*: Optional[[AicCompilerConfig](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-aic.html#qairt.api.common.backends.aic.config.AicCompilerConfig)]*  *= None*

    - Set this field to enable configurations that are passed by the backend to the compiler.
Note this option is currently only applicable to the AIC Backend.
Use `qairt.api.common.backends.aic.config.AicCompilerConfig.list_config_options` to see valid fields.

- context\_custom\_configs*: Optional[Union[List[[HtpContextConfig](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp.html#qairt.api.common.backends.htp.config.HtpContextConfig)], List[[HtpMcpContextConfig](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp_mcp.html#qairt.api.common.backends.htp_mcp.config.HtpMcpContextConfig)]]]*  *= None*

    - Context configuration options specific to a backend.
Only HTP and HTP MCP backend options are supported.
See [`qairt.api.common.backends.htp.config.HtpContextConfig`](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp.html#qairt.api.common.backends.htp.config.HtpContextConfig) and
[`qairt.api.common.backends.htp_mcp.config.HtpMcpContextConfig`](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp_mcp.html#qairt.api.common.backends.htp_mcp.config.HtpMcpContextConfig) for options

- data\_format\_config*: Optional[Union[str, PathLike]]*  *= None*

    - Path to a JSON config file, specifying the data formats of certain tensors.

- debug*: bool*  *= False*

    - Enable debug mode.

- device\_custom\_configs*: Optional[Union[List[[HtpDeviceConfig](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp.html#qairt.api.common.backends.htp.config.HtpDeviceConfig)], List[[HtpMcpDeviceConfig](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp_mcp.html#qairt.api.common.backends.htp_mcp.config.HtpMcpDeviceConfig)]]]*  *= None*

    - Device configuration options specific to a backend.
Only HTP and HTP MCP backend options are supported.
See [`qairt.api.common.backends.htp.config.HtpDeviceConfig`](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp.html#qairt.api.common.backends.htp.config.HtpDeviceConfig)
and [`qairt.api.common.backends.htp_mcp.config.HtpMcpDeviceConfig`](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp_mcp.html#qairt.api.common.backends.htp_mcp.config.HtpMcpDeviceConfig) for options.

- enable\_intermediate\_outputs*: Optional[bool]*  *= None*

    - Enable all intermediate nodes to be produced along with default outputs in the saved context.
Note that options enable\_intermediate\_outputs and set\_output\_tensors are mutually exclusive.
Only one of the options can be specified at a time.

- *classmethod* from\_backend\_extensions(*backend: str*, *path: Union[str, PathLike]*, *\**, *passthrough: bool = False*, *\*\*kwargs: Any*) → [CompileConfig](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-compiler.html#qairt.api.compiler.config.CompileConfig)

    - Create a CompileConfig from a backend extensions JSON file.

This is a convenience classmethod for expert users who want to create a
`CompileConfig` entirely from a backend extensions file.

- Parameters

    - - **backend** – The backend type (must be `"HTP"`).
- **path** – Path to the backend extensions JSON file.
- **passthrough** – If `True`, the raw JSON dict is stored as-is and passed directly
to the context binary generator without mapping. See
[`populate_from_backend_extensions()`](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-compiler.html#qairt.api.compiler.config.CompileConfig.populate_from_backend_extensions) for details.
- **\*\*kwargs** – Additional keyword arguments passed to the `CompileConfig` constructor
(e.g., `soc_details`, `log_level`, `debug`).

- Returns

    - A new `CompileConfig` instance with HTP config fields populated from the file.

- Raises

    - - **ValueError** – If the backend is not HTP.
- **FileNotFoundError** – If the file does not exist.

Example

config = CompileConfig.from_backend_extensions("HTP", "htp_extensions.json")
    
    # With additional options:
    config = CompileConfig.from_backend_extensions(
        "HTP", "htp_extensions.json", log_level="debug"
    )
    Copy to clipboard

- graph\_custom\_configs*: Optional[Union[List[[HtpGraphConfig](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp.html#qairt.api.common.backends.htp.config.HtpGraphConfig)], List[[HtpMcpGraphConfig](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp_mcp.html#qairt.api.common.backends.htp_mcp.config.HtpMcpGraphConfig)]]]*  *= None*

    - Graph configuration options specific to a backend.
Currently only used for HTP backend. See [`qairt.api.common.backends.htp.config.HtpGraphConfig`](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp.html#qairt.api.common.backends.htp.config.HtpGraphConfig)
and [`qairt.api.common.backends.htp_mcp.config.HtpMcpGraphConfig`](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp_mcp.html#qairt.api.common.backends.htp_mcp.config.HtpMcpGraphConfig) for options.

- group\_context\_config*: Optional[[HtpGroupContextConfig](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp.html#qairt.api.common.backends.htp.config.HtpGroupContextConfig)]*  *= None*

    - Group context configuration for the compiler. Only HTP backend configurations are supported.

- io\_tensor\_mem\_type*: Optional[Literal['raw', 'memhandle']]*  *= 'raw'*

    - “raw” and “memhandle”.

- Type

    - Select memory type for input or output tensors. Possible options are

- log\_level*: Optional[str]*  *= 'error'*

    - Log level for the compiler. Standard logging levels are supported.

- memory\_custom\_config*: Optional[[HtpMemoryConfig](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-common-backends-htp.html#qairt.api.common.backends.htp.config.HtpMemoryConfig)]*  *= None*

    - Memory backend configuration for the compiler. Only HTP backend configurations are supported.

- model\_post\_init(*\_CompileConfig\_\_context*)

    - 

- op\_packages*: Optional[List[qti.aisw.tools.core.modules.api.definitions.common.OpPackageIdentifier]]*  *= None*

    - List of custom op package identifiers to be used for compilation.

- populate\_from\_backend\_extensions(*path: Union[str, PathLike]*, *\**, *passthrough: bool = False*) → [CompileConfig](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-compiler.html#qairt.api.compiler.config.CompileConfig)

    - Populate HTP config fields from a backend extensions JSON file.

This is an expert option for users who already have a backend extensions config file
(the same format consumed by `qnn-context-binary-generator`) and want to load it
directly into a `CompileConfig` without manually mapping each option.

If any HTP config fields are already set on this config, they will be **overwritten**
by the values from the file.

- Parameters

    - - **path** – Path to the backend extensions JSON file.
- **passthrough** – If `True`, the raw JSON dict is stored as-is and passed directly
to the context binary generator without mapping to `Htp*Config` objects.
The compile config will **not** contain mapped HTP config properties.
Use this as a debug option when you want to avoid any mapping errors.
The backend config must be fully qualified as it will not be validated.

- Returns

    - This `CompileConfig` instance (for chaining).

- Raises

    - - **ValueError** – If the backend is not HTP.
- **FileNotFoundError** – If the file does not exist.

Example

config = CompileConfig(backend="HTP", soc_details="chipset:SM8550")
    config.populate_from_backend_extensions("htp_extensions.json")
    
    # Passthrough mode (no mapping, raw dict passed to backend):
    config = CompileConfig(backend="HTP")
    config.populate_from_backend_extensions("htp_extensions.json", passthrough=True)
    Copy to clipboard

- serialize(*info*)

    - Serialize the model to a dictionary. Set backend\_extensions to True to serialize
only backend extensions. Use config.model\_dump() to call this function indirectly.

Examples

from qairt.api.compiler.config import CompilerConfig
    
    # to dump the entire config
    config_dict = config.model_dump()
    
    # to dump just the backend extensions
    config_dict = config.model_dump(context={"backend_extensions": True})
    Copy to clipboard

- set\_mode(*mode: str*, *\*\*kwargs*)

    - Define a mode for compilation. Only weight sharing is supported.

This option is most effective when no custom configs have been set and soc details are set with the
chipset.

- Parameters

    - - **mode** – Mode to be set. Currently only weight\_sharing is supported.
- **kwargs** – Keyword arguments for the mode. For mode == weight\_sharing, see
[`qairt.api.compiler.config.CompilerModeSetters.set_weight_sharing()`](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-compiler.html#qairt.api.compiler.config.CompilerModeSetters.set_weight_sharing) for
the arguments that can be provided.

- set\_output\_tensors*: Optional[List[str]]*  *= None*

    - A comma-separated list of intermediate output tensor names, for which the outputs
will be written in addition to final graph output tensors.  The syntax is: graphName0:tensorName0,
tensorName1;graphName1:tensorName0,tensorName1. In case of a single graph, its name is not necessary and
a list of comma separated tensor names can be provided, e.g.: tensorName0,tensorName1

- soc\_details*: Optional[Union[qti.aisw.tools.core.utilities.devices.api.device\_definitions.SocDetails, str]]*  *= None*

    - Device specification to use for compilation. Can be specified as a spec string
in the form “chipset:value;dsp\_arch:value;soc\_model:value|…”. This option
will be ignored if any device custom configurations are set.

- to\_backend\_extension\_json(*\**, *indent: int = 4*) → str

    - Serialize the backend extensions portion of this config to a JSON string.

This is a convenience wrapper around
`json.dumps(self.model_dump(context={"backend_extensions": True}), indent=indent)`.

Example

cfg = CompileConfig.from_backend_extensions("HTP", "backend_extensions.json")
    Path("new_backend_ext.json").write_text(cfg.to_backend_extension_json())
    Copy to clipboard

- Parameters

    - **indent** – JSON indentation level (default 4).

- Returns

    - JSON string representing the backend extensions config.

- *class* qairt.api.compiler.config.CompilerModeSetters

    - Class to set different compilation modes.

- *static* set\_weight\_sharing(*config: [CompileConfig](https://docs.qualcomm.com/doc/80-87189-2/topic/qairt-api-compiler.html#qairt.api.compiler.config.CompileConfig)*, *\*\*kwargs*)

    - Sets graph, device and core config options to enable weight sharing on the HTP backend.

Expects the config to contain soc details which have been resolved.

- Parameters

    - - **config** – The Compile config instance
- **graph\_names** – A list of graph names to be used for weight sharing. If this is not provided
then “ensure\_graphs” will be set in the config. This property will signal to other
APIs that the graph names should be inferred from the model.
- **soc\_model** – The soc model to use for weight sharing. If this is not provided then the soc model
will be inferred from the soc details.
- **dsp\_arch** – The dsp arch to use for weight sharing. If this is not provided then the dsp arch
will be inferred from the soc details.
- **hvx\_threads** – The number of hvx threads to associate with the dsp arch
- **vtcm\_size\_in\_mb** – The vtcm size in megabytes
- **fp16** – A boolean indicate if fp16 should be enabled

- *class* qairt.api.compiler.config.CompilerModes(*value*)

    - An enumeration.

- WEIGHT\_SHARING *= 'weight\_sharing'*

    - 

- *static* list\_options()

    -

Last Published: May 26, 2026

[Previous Topic
qairt.api.common](https://docs.qualcomm.com/bundle/publicresource/80-87189-2/topics/qairt-api-common.md) [Next Topic
qairt.api.configs](https://docs.qualcomm.com/bundle/publicresource/80-87189-2/topics/qairt-api-configs.md)