Skip to navigation

aitune.torch.artifact

View as MarkdownOpen in Claude

Translate Torch graph metadata into deployment-neutral artifact records.

Module Contents

Functions

NameDescription
_batch_axisReturn the single directly representable logical batch axis, if known.
artifact_input_sampleCapture one recorded Torch call as portable deployment input values.
bounded_tensor_specsCreate ordered bounded tensor specs from a recorded Torch graph.

Data

TensorKind

_TORCH_DTYPE_TO_RECORD

API

Return the single directly representable logical batch axis, if known.

aitune.torch.artifact.artifact_input_sample(
recorded_names: collections.abc.Sequence[str] | None = None,
metadata_indices: collections.abc.Sequence[int] | None = None,
artifact_names: collections.abc.Sequence[str] | None = None
) -> tuple[aitune.records.TensorSample, ...]

Capture one recorded Torch call as portable deployment input values.

A recorded sample follows the module’s Python call signature, while an exported executable can expose a different input order or different names. This function uses GraphSpec locators to read the original tensors, reorders them to match the executable, and stores their shape and flattened values in TensorSample records. The result contains no Torch objects, so it can be kept in a deployment artifact and later converted to input formats such as Perf Analyzer JSON.

By default, the result uses the input order and original tensor names stored in GraphSpec. A backend whose executable selects or reorders named inputs can provide recorded_names. Positional formats such as PT2 instead provide metadata_indices and use artifact_names for their final public names. The two explicit selection methods are mutually exclusive.

Parameters:

graph_spec
GraphSpec

GraphSpec — Recorded graph metadata containing tensor names and locators.

sample
Sample

Sample — Original module call represented as (args, kwargs).

recorded_names
Sequence[str] | NoneDefaults to None

Recorded graph input names in executable order.

metadata_indices
Sequence[int] | NoneDefaults to None

Graph input positions in executable order.

artifact_names
Sequence[str] | NoneDefaults to None

Final executable names for the selected inputs. Recorded names are used when this is omitted.

Returns: tuple[ TensorSample , ...]

Portable input samples in executable order.

Raises:

  • ValueError: If selection is ambiguous, an input cannot be found, names and selected inputs have different lengths, or a selected value is not a tensor.
aitune.torch.artifact.bounded_tensor_specs(
recorded_names: collections.abc.Sequence[str] | None = None,
metadata_indices: collections.abc.Sequence[int] | None = None,
artifact_names: collections.abc.Sequence[str] | None = None

Create ordered bounded tensor specs from a recorded Torch graph.

Backends whose executable retains exporter names select tensors with recorded_names. Backends with a positional ABI can instead select metadata by index and provide their finalized artifact_names. Selection methods are mutually exclusive so an adapter cannot accidentally combine two orderings.

aitune.torch.artifact.TensorKind = Literal['input', 'output']
aitune.torch.artifact._TORCH_DTYPE_TO_RECORD = {torch.bool: DType.BOOL, torch.uint8: DType.UINT8, torch.int8: DType.INT8, torch...