Skip to navigation

aitune.triton

View as Markdown

Generate Triton model repositories from artifacts and existing model files.

Subpackages

Submodules

Package Contents

Classes

NameDescription
DynamicBatcherDynamic batching with preferred sizes, priorities, and queue policies.
ExecutionAcceleratorONNX Runtime execution accelerator and backend-specific string parameters.
InstanceGroupModel instance count, device placement, profiles, and rate limiting.
ModelAnalyzerConfigUser options for the Model Analyzer config generated during publication.
ModelWarmupNamed warmup sample with protobuf-shaped input data specifications.
ONNXRuntimeModelConfigTriton configuration specialized for ONNX Runtime artifacts.
QueuePolicyRequest timeout and queue capacity policy; times are in microseconds.
SequenceBatcherSequence scheduling using Triton protobuf fields for controls and state.
TensorRTModelConfigTriton configuration specialized for serialized TensorRT plans.
TorchAOTIModelConfigTriton configuration specialized for AOTInductor PT2 packages.
TritonDataTypeTensor element types supported by AITune artifacts and Triton.
TritonTensorConfigOne input or output in a Triton model configuration.

Functions

NameDescription
publishPublish a tuned artifact or an existing model file to a Triton repository.

Data

PublicationError

API

class aitune.triton.DynamicBatcher()

Bases: _Options

Dynamic batching with preferred sizes, priorities, and queue policies.

default_priority_level
NonNegativeInt = 0
default_queue_policy
QueuePolicy | None = None
max_queue_delay_microseconds
NonNegativeInt = 0
preferred_batch_size
tuple[PositiveInt, ...] = ()
preserve_ordering
bool = False
priority_levels
NonNegativeInt = 0
priority_queue_policy
dict[int, QueuePolicy] = Field(default_factory=dict)
aitune.triton.DynamicBatcher._validate_priorities() -> aitune.triton.config.options.DynamicBatcher

Require configured priority levels and defaults to agree.

class aitune.triton.ExecutionAccelerator()

Bases: _Options

ONNX Runtime execution accelerator and backend-specific string parameters.

name
str = Field(min_length=1)
parameters
dict[str, str] = Field(default_factory=dict)
class aitune.triton.InstanceGroup()

Bases: _Options

Model instance count, device placement, profiles, and rate limiting.

count
PositiveInt = 1
gpus
tuple[NonNegativeInt, ...] = ()
host_policy
str | None = None
kind
Literal['KIND_AUTO', 'KIND_CPU', 'KIND_GPU', 'KIND_MODEL'] = 'KIND_AUTO'
name
str | None = None
passive
bool = False
profile
tuple[str, ...] = ()
rate_limiter
dict[str, Any] | None = None
secondary_devices
tuple[dict[str, Any], ...] = ()
aitune.triton.InstanceGroup._validate_devices() -> aitune.triton.config.options.InstanceGroup

Reject GPU identifiers on CPU or model-managed instances.

class aitune.triton.ModelAnalyzerConfig()

Bases: BaseModel

User options for the Model Analyzer config generated during publication.

latency_budget_ms
int | None = Field(default=None, ge=1, strict=True)
latency_percentile
Literal[90, 95, 99] = Field(default=95)
model_config
class aitune.triton.ModelWarmup()

Bases: _Options

Named warmup sample with protobuf-shaped input data specifications.

Each input specifies data_type, dims, and one of zero_data, random_data, or input_data_file. Files live under the model’s warmup directory.

batch_size
PositiveInt = 1
count
NonNegativeInt = 0
inputs
dict[str, dict[str, Any]] = Field(min_length=1)
name
str = Field(min_length=1)
class aitune.triton.ONNXRuntimeModelConfig()

Bases: BaseModelConfig

Triton configuration specialized for ONNX Runtime artifacts.

cpu_execution_accelerators
tuple[ExecutionAccelerator, ...] = ()
execution_provider
Literal['cuda', 'tensorrt']
gpu_execution_accelerators
tuple[ExecutionAccelerator, ...] = ()
platform
Literal['onnxruntime_onnx'] = 'onnxruntime_onnx'
aitune.triton.ONNXRuntimeModelConfig._artifact_options(
) -> dict[str, typing.Any]
classmethod

Read the execution provider selected for ONNX Runtime.

aitune.triton.ONNXRuntimeModelConfig.to_protobuf() -> tritonclient.grpc.model_config_pb2.ModelConfig

Preserve ONNX Runtime TensorRT provider selection.

class aitune.triton.QueuePolicy()

Bases: _Options

Request timeout and queue capacity policy; times are in microseconds.

allow_timeout_override
bool = False
default_timeout_microseconds
NonNegativeInt = 0
max_queue_size
NonNegativeInt = 0
timeout_action
Literal['REJECT', 'DELAY'] = 'REJECT'
class aitune.triton.SequenceBatcher()

Bases: _Options

Sequence scheduling using Triton protobuf fields for controls and state.

direct and oldest select mutually exclusive strategies. Nested mappings use the ModelSequenceBatching schema and are checked when the model config is built.

control_input
tuple[dict[str, Any], ...] = ()
direct
dict[str, Any] | None = None
iterative_sequence
bool = False
max_sequence_idle_microseconds
NonNegativeInt | None = None
oldest
dict[str, Any] | None = None
state
tuple[dict[str, Any], ...] = ()
aitune.triton.SequenceBatcher._validate_strategy() -> aitune.triton.config.options.SequenceBatcher

Allow at most one sequence scheduler strategy.

class aitune.triton.TensorRTModelConfig()

Bases: BaseModelConfig

Triton configuration specialized for serialized TensorRT plans.

cuda_graphs
bool = False
eager_batching
bool | None = None
gather_kernel_buffer_threshold
NonNegativeInt | None = None
optimization_profile_indices
tuple[StrictInt, ...]
platform
Literal['tensorrt_plan'] = 'tensorrt_plan'
aitune.triton.TensorRTModelConfig._artifact_options(
) -> dict[str, typing.Any]
classmethod

Read plan profile metadata and TensorRT runtime settings.

aitune.triton.TensorRTModelConfig._validate_profiles(
indices: tuple[int, ...]
) -> tuple[int, ...]
classmethod

Accept a non-empty set of distinct non-negative profile indices.

aitune.triton.TensorRTModelConfig.to_protobuf() -> tritonclient.grpc.model_config_pb2.ModelConfig

Add TensorRT optimization-profile selection to the common config.

class aitune.triton.TorchAOTIModelConfig()

Bases: BaseModelConfig

Triton configuration specialized for AOTInductor PT2 packages.

platform
Literal['torch_aoti'] = 'torch_aoti'
structured_call
bool
aitune.triton.TorchAOTIModelConfig._artifact_options(
) -> dict[str, typing.Any]
classmethod

Read the PT2 package’s call structure.

aitune.triton.TorchAOTIModelConfig._supports_artifact_batching(
) -> bool
classmethod

Structured PT2 calls cannot use Triton’s implicit batch dimension.

aitune.triton.TorchAOTIModelConfig._validate_structured_batching() -> aitune.triton.config.torch_aoti.TorchAOTIModelConfig

Reject batching that cannot preserve a structured PT2 call.

class aitune.triton.TritonDataType

Bases: enum.Enum

Tensor element types supported by AITune artifacts and Triton.

BFLOAT16
= 'TYPE_BF16'
BOOL
= 'TYPE_BOOL'
FLOAT16
= 'TYPE_FP16'
FLOAT32
= 'TYPE_FP32'
FLOAT64
= 'TYPE_FP64'
INT16
= 'TYPE_INT16'
INT32
= 'TYPE_INT32'
INT64
= 'TYPE_INT64'
INT8
= 'TYPE_INT8'
STRING
= 'TYPE_STRING'
UINT16
= 'TYPE_UINT16'
UINT32
= 'TYPE_UINT32'
UINT64
= 'TYPE_UINT64'
UINT8
= 'TYPE_UINT8'
class aitune.triton.TritonTensorConfig()

Bases: BaseModel

One input or output in a Triton model configuration.

allow_ragged_batch
bool = False
data_type
TritonDataType
dims
tuple[int, ...]
format
Literal['FORMAT_NONE', 'FORMAT_NHWC', 'FORMAT_NCHW'] = 'FORMAT_NONE'
is_non_linear_format_io
bool = False
is_shape_tensor
bool = False
label_filename
str | None = None
model_config
= ConfigDict(frozen=True, extra='forbid')
name
str = Field(min_length=1)
optional
bool = False
reshape
tuple[int, ...] | None = None
aitune.triton.TritonTensorConfig._validate_dims(
dims: tuple[int, ...]
) -> tuple[int, ...]
classmethod

Allow concrete positive dimensions and Triton’s dynamic marker.

aitune.triton.TritonTensorConfig._validate_reshape(
dims: tuple[int, ...] | None
) -> tuple[int, ...] | None
classmethod

Allow scalar reshapes and one inferred dimension.

aitune.triton.TritonTensorConfig.to_config_dict(
output: bool
) -> dict[str, typing.Any]

Serialize only settings appropriate to an input or output tensor.

aitune.triton.publish(
model: aitune.records.DeploymentArtifact | str | os.PathLike[str],
path: str | os.PathLike[str],
model_name: str | None = None,
model_version: int = 1,
model_analyzer: aitune.triton.model_analyzer.ModelAnalyzerConfig | None = None,
config: aitune.triton.config.TensorRTModelConfig | aitune.triton.config.ONNXRuntimeModelConfig | aitune.triton.config.TorchAOTIModelConfig | None = None,
additional_files: collections.abc.Sequence[str | os.PathLike[str]] = (),
resources: collections.abc.Mapping[str, str | os.PathLike[str]] | None = None
) -> pathlib.Path

Publish a tuned artifact or an existing model file to a Triton repository.

The operation never replaces an existing model. Files are written directly into the new model directory, so a failure can leave an incomplete directory. For artifacts, a Model Analyzer config is generated under model_analyzer/config.yaml with input shapes derived from the artifact. Without an explicit config, the Triton batch limit and scheduler are derived from the artifact’s tensor bounds and runtime call structure. Existing model files require an explicit backend-specific config and are copied without compilation or tuning. Callers must keep generation separate from updates to a live Triton repository.

Supported model format/runtime pairs are onnx/onnxruntime, tensorrt_plan/tensorrt, and pt2/aotinductor. ONNX provider selection comes from runtime.options["execution_provider"]. TensorRT uses model.metadata["optimization_profile_count"] and the optional runtime setting use_cuda_graphs. PT2 uses model.metadata["structured_call"].

Parameters:

model
DeploymentArtifact | str | os.PathLike[str]

DeploymentArtifact | str | os.PathLike[str] — Deployment artifact or path to an existing model file.

path
str | os.PathLike[str]

Triton model repository root.

model_name
str | NoneDefaults to None

New model directory name for an artifact; defaults to config.name when config is supplied.

model_version
intDefaults to 1

Positive Triton model version.

model_analyzer
ModelAnalyzerConfig | NoneDefaults to None

ModelAnalyzerConfig | None — Optional Model Analyzer options. Omission uses the default options for artifacts.

config
TensorRTModelConfig | ONNXRuntimeModelConfig | TorchAOTIModelConfig | NoneDefaults to None

TensorRTModelConfig | ONNXRuntimeModelConfig | TorchAOTIModelConfig | None — Complete backend-specific configuration. For an artifact, it is derived when omitted. A supplied config must match the artifact runtime and model name; the caller owns its other values. An existing model file requires it.

additional_files
Sequence[str | os.PathLike[str]]Defaults to ()

ONNX external-data paths relative to the source file’s directory.

resources
Mapping[str, str | os.PathLike[str]] | NoneDefaults to None

Model-relative auxiliary destination paths mapped to local files.

Returns: Path

Path to the generated model directory.

Raises:

  • AITuneUserInputError: If publication arguments are invalid.
  • AITunePublicationError: If the artifact cannot be represented or publication fails.
aitune.triton.model_repository.PublicationError = AITunePublicationError