Artifact API¶
mlx_lattice.artifact loads and saves legacy lattice model artifacts. The
deployment entry point is mlx_lattice.artifact.load_lattice_model(), which
reads a manifest and safetensors weight file, validates the graph, and
returns an in-memory mlx_lattice.artifact.LatticeModel.
The public package root intentionally exposes only loading, saving, and the runtime model. JSON graph builders and registries are legacy submodule tools; future producer work should target the MLIR lattice dialect rather than growing the JSON graph authoring surface.
The artifact implementation has three layers:
mlx_lattice.artifact.iohandles the on-disk artifact directory;mlx_lattice.artifact.modelexecutes a validated in-memory manifest;mlx_lattice.artifact.registrymaps manifest operations and module annotations to approved publicmlx_lattice.opscalls.
Module artifact helpers under mlx_lattice.artifact.builder still build
legacy manifests and weight dictionaries from approved sparse NN modules. They
are kept for tests, local fixtures, and compatibility with the current JSON
runner, but they are not the long-term cross-framework IR API.
The artifact runner honors manifest dtype_policy for floating dense arrays and
sparse feature matrices while preserving coordinates, integer arrays, byte
streams, and packed quantized payloads.
Artifact manifests also carry runtime compatibility metadata. The loader
accepts artifacts targeted at mlx-lattice whose version specifier matches
the installed native mlx-lattice package, and rejects incompatible runtime metadata names or version
windows before dispatching any graph node.
- class mlx_lattice.artifact.LatticeArtifact(manifest, weights)[source]¶
Bases:
objectLoaded lattice model artifact.
- Parameters:
manifest (IRManifest)
- manifest: IRManifest¶
- class mlx_lattice.artifact.LatticeModel(manifest, weights)[source]¶
Bases:
objectExecutable in-memory graph loaded from a lattice artifact.
The model does not execute generated Python. It validates IR nodes and dispatches each node through the public
mlx_lattice.opssurface.- Parameters:
manifest (IRManifest)
weights (Mapping[str, mx.array])
- mlx_lattice.artifact.load_lattice_artifact(path)[source]¶
Load a lattice artifact directory.
The artifact directory must contain
manifest.jsonandweights.safetensors. UseLatticeArtifact.model()orload_lattice_model()when an executable graph runner is needed.- Return type:
- Parameters:
- mlx_lattice.artifact.load_lattice_model(path)[source]¶
Load a lattice artifact directory into an executable model.
The model-oriented name is the recommended deployment entry point.
- Return type:
- Parameters:
- mlx_lattice.artifact.save_lattice_artifact(path, manifest, weights)[source]¶
Write a lattice artifact directory.
This helper is intentionally strict and low level. It is useful for tests, fixtures, and future producers that already own a valid manifest.
- mlx_lattice.artifact.save_lattice_graph(path, builder, **kwargs)[source]¶
Build and save an explicitly built lattice graph.
- Return type:
- Parameters:
builder (LatticeGraphBuilder)
- mlx_lattice.artifact.save_lattice_model(path, manifest, weights)[source]¶
Alias for
save_lattice_artifact().
- mlx_lattice.artifact.save_lattice_module(path, module, **kwargs)[source]¶
Build and save a serializable sparse NN module.
Artifact I/O¶
- class mlx_lattice.artifact.io.LatticeArtifact(manifest, weights)[source]¶
Bases:
objectLoaded lattice model artifact.
- Parameters:
manifest (IRManifest)
- manifest: IRManifest¶
- mlx_lattice.artifact.io.load_lattice_artifact(path)[source]¶
Load a lattice artifact directory.
The artifact directory must contain
manifest.jsonandweights.safetensors. UseLatticeArtifact.model()orload_lattice_model()when an executable graph runner is needed.- Return type:
- Parameters:
- mlx_lattice.artifact.io.load_lattice_model(path)[source]¶
Load a lattice artifact directory into an executable model.
The model-oriented name is the recommended deployment entry point.
- Return type:
- Parameters:
- mlx_lattice.artifact.io.save_lattice_artifact(path, manifest, weights)[source]¶
Write a lattice artifact directory.
This helper is intentionally strict and low level. It is useful for tests, fixtures, and future producers that already own a valid manifest.
- mlx_lattice.artifact.io.save_lattice_model(path, manifest, weights)[source]¶
Alias for
save_lattice_artifact().
Artifact model¶
- class mlx_lattice.artifact.model.LatticeModel(manifest, weights)[source]¶
Bases:
objectExecutable in-memory graph loaded from a lattice artifact.
The model does not execute generated Python. It validates IR nodes and dispatches each node through the public
mlx_lattice.opssurface.- Parameters:
manifest (IRManifest)
weights (Mapping[str, mx.array])
Legacy internals¶
- mlx_lattice.artifact.registry.lattice_op(op, *, function, inputs, outputs=None, parameters=None, optional_parameters=None, attributes=None, value_attributes=None, defaults=None, sequence_inputs=None, output='output', output_types=None, input_types=None, value_attribute_types=None, handler=None)[source]¶
Register a public operation with one compact annotation.
- Return type:
Callable[[TypeVar(HandlerT, bound=Callable[[ExecutionContext,IRNode],dict[str,SparseTensor|array|KernelRelation|NeighborRelation|CoordinateSet|SparseAlignment|SparseQuantization|PointVoxelMap|CoordinateOrdering|SparseOccupancy|OccupancyExpansion|bytes|object]])],TypeVar(HandlerT, bound=Callable[[ExecutionContext,IRNode],dict[str,SparseTensor|array|KernelRelation|NeighborRelation|CoordinateSet|SparseAlignment|SparseQuantization|PointVoxelMap|CoordinateOrdering|SparseOccupancy|OccupancyExpansion|bytes|object]])]- Parameters:
op (str | IROpContract)
function (Callable[[...], GraphValue])
parameters (Mapping[str, str | ParameterBinding] | None)
optional_parameters (Mapping[str, str | ParameterBinding] | None)
output (str)
output_types (Mapping[str, Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes']] | None)
input_types (Mapping[str, Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes']] | None)
value_attribute_types (Mapping[str, Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes']] | None)
handler (GraphHandler | None)
- mlx_lattice.artifact.registry.module_binding(module_type, *, op, parameters=(), attributes=<function <lambda>>)[source]¶
Register a serializable NN module producer.
- mlx_lattice.artifact.registry.iter_operation_specs()[source]¶
Return all operation contracts supported by the MLX artifact graph.
- mlx_lattice.artifact.registry.operation_spec(name)[source]¶
Return the artifact operation spec for
name.
- mlx_lattice.artifact.registry.operation_binding(name)[source]¶
Return the artifact operation binding for
name.- Return type:
- Parameters:
name (str)
- mlx_lattice.artifact.registry.module_artifact_binding(module)[source]¶
Return the artifact binding for
module.- Return type:
- Parameters:
module (Module)
- mlx_lattice.artifact.registry.validate_node_against_artifact(node)[source]¶
Validate an IR node against the MLX artifact binding.
- type mlx_lattice.artifact.bindings.GraphValue = SparseTensor | array | KernelRelation | NeighborRelation | CoordinateSet | SparseAlignment | SparseQuantization | PointVoxelMap | CoordinateOrdering | SparseOccupancy | OccupancyExpansion | bytes | object¶
- type mlx_lattice.artifact.bindings.GraphHandler = Callable[[ExecutionContext, IRNode], dict[str, GraphValue]]¶
- class mlx_lattice.artifact.bindings.ParameterBinding(argument, kind=IRParameterKind.ARRAY)[source]¶
Bases:
objectHow an IR parameter name is converted into a runtime argument.
- Parameters:
argument (str)
kind (IRParameterKind)
- kind: IRParameterKind¶
- class mlx_lattice.artifact.bindings.ModuleParameterBinding(name, source)[source]¶
Bases:
objectHow an NN module field is stored as an IR parameter.
- class mlx_lattice.artifact.bindings.ValueTypeBinding(value_type, runtime_type, fields=<factory>)[source]¶
Bases:
objectRuntime type and public fields for one IR value type.
- Parameters:
value_type (Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes'])
fields (Mapping[str, Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes']])
- class mlx_lattice.artifact.bindings.OperationBinding(spec, function, input_arguments, parameter_arguments=<factory>, attribute_arguments=<factory>, value_attribute_arguments=<factory>, defaults=<factory>, sequence_inputs=frozenset({}), output='output', handler=None)[source]¶
Bases:
objectRuntime binding for one public lattice operation.
- Parameters:
spec (IROpSpec)
function (Callable[[...], GraphValue])
parameter_arguments (Mapping[str, ParameterBinding])
output (str)
handler (GraphHandler | None)
- function: Callable[[...], GraphValue]¶
- parameter_arguments: Mapping[str, ParameterBinding]¶
- handler: GraphHandler | None¶
- run(context, node)[source]¶
- Return type:
dict[str,SparseTensor|array|KernelRelation|NeighborRelation|CoordinateSet|SparseAlignment|SparseQuantization|PointVoxelMap|CoordinateOrdering|SparseOccupancy|OccupancyExpansion|bytes|object]- Parameters:
context (ExecutionContext)
node (IRNode)
- run_default(context, node)[source]¶
- Return type:
dict[str,SparseTensor|array|KernelRelation|NeighborRelation|CoordinateSet|SparseAlignment|SparseQuantization|PointVoxelMap|CoordinateOrdering|SparseOccupancy|OccupancyExpansion|bytes|object]- Parameters:
context (ExecutionContext)
node (IRNode)
- class mlx_lattice.artifact.bindings.ModuleBinding(module_type, op, parameters=(), attributes=<function ModuleBinding.<lambda>>)[source]¶
Bases:
objectArtifact binding for a serializable sparse NN module.
- Parameters:
- parameters: tuple[ModuleParameterBinding, ...]¶
- class mlx_lattice.artifact.bindings.ExecutionContext(values, weights, batch_size=None)[source]¶
Bases:
objectMutable graph execution state.
- values: dict[str, GraphValue]¶
- value(name)[source]¶
- Return type:
SparseTensor|array|KernelRelation|NeighborRelation|CoordinateSet|SparseAlignment|SparseQuantization|PointVoxelMap|CoordinateOrdering|SparseOccupancy|OccupancyExpansion|bytes|object- Parameters:
name (str)
- input_value(value_ref, *, sequence=False)[source]¶
- Return type:
SparseTensor|array|KernelRelation|NeighborRelation|CoordinateSet|SparseAlignment|SparseQuantization|PointVoxelMap|CoordinateOrdering|SparseOccupancy|OccupancyExpansion|bytes|object|tuple[SparseTensor|array|KernelRelation|NeighborRelation|CoordinateSet|SparseAlignment|SparseQuantization|PointVoxelMap|CoordinateOrdering|SparseOccupancy|OccupancyExpansion|bytes|object,...]- Parameters:
value_ref (IRInputRef)
sequence (bool)
- parameter(name, kind=IRParameterKind.ARRAY)[source]¶
- Return type:
- Parameters:
name (str)
kind (IRParameterKind | str)
- mlx_lattice.artifact.bindings.infer_batch_size(values)[source]¶
Infer batch size from sparse graph inputs when metadata exists.
- Return type:
- Parameters:
values (Mapping[str, GraphValue])
- mlx_lattice.artifact.bindings.apply_dtype_policy(value, policy, *, inference=True)[source]¶
Apply an artifact dtype policy to graph-carried tensor values.
- Return type:
SparseTensor|array|KernelRelation|NeighborRelation|CoordinateSet|SparseAlignment|SparseQuantization|PointVoxelMap|CoordinateOrdering|SparseOccupancy|OccupancyExpansion|bytes|object- Parameters:
value (GraphValue)
policy (Literal['preserve', 'fp32', 'fp16', 'fp16_inference'])
inference (bool)
- mlx_lattice.artifact.bindings.validate_value_type(name, expected, value)[source]¶
Validate a runtime value against an IR value type.
- Return type:
- Parameters:
name (str)
expected (Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes'])
value (GraphValue)
- mlx_lattice.artifact.bindings.layout_id(value)[source]¶
Encode a quantized weight layout for artifact metadata.
- mlx_lattice.artifact.bindings.value_type_binding(value_type)[source]¶
Return the artifact binding for an IR value type.
- Return type:
- Parameters:
value_type (Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes'])
- mlx_lattice.artifact.bindings.value_type_fields(value_type)[source]¶
Return public structural fields exposed for an IR value type.
- Return type:
Mapping[str,Literal['any','sparse_tensor','dense_tensor','relation','coordinate_set','alignment','quantization','point_voxel_map','coordinate_ordering','sparse_occupancy','occupancy_expansion','bytes']]- Parameters:
value_type (Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes'])
- mlx_lattice.artifact.bindings.iter_value_type_bindings()[source]¶
Return artifact bindings for all known IR value types.
- Return type:
- class mlx_lattice.artifact.builder.LatticeArtifactData(manifest, weights)[source]¶
Bases:
objectManifest and weight tensors for an in-memory lattice artifact.
- Parameters:
manifest (IRManifest)
- manifest: IRManifest¶
- class mlx_lattice.artifact.builder.GraphOutput(value, value_type=None, name=None)[source]¶
Bases:
objectPublic graph output mapping for an explicit artifact graph.
- Parameters:
- class mlx_lattice.artifact.builder.LatticeGraphBuildable(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for modules that append their own artifact graph nodes.
- build_lattice_graph(builder, input_name)[source]¶
Append nodes to
builderand return the output value name.- Return type:
- Parameters:
builder (LatticeGraphBuilder)
input_name (str)
- class mlx_lattice.artifact.builder.LatticeGraphBuilder(input_name='input', *, inputs=None)[source]¶
Bases:
objectBuilder for explicit lattice model manifests.
The builder is intentionally small: it owns graph nodes and weight tensors, validates op/module bindings through the shared artifact registry, and returns named values that can be wired into later nodes. It is the escape hatch for custom modules and DAGs without requiring Python tracing.
- value_types: dict[str, Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes']]¶
- add_op(name, op, *, inputs, output=None, outputs=None, parameters=None, attributes=None)[source]¶
Append an operation node and return its primary output value.
- call(op, /, name=None, *, output=None, outputs=None, parameters=None, **arguments)[source]¶
Append an operation by using its registered public argument names.
Graph-value arguments are passed as value names. JSON-compatible constants become manifest attributes. Tensor parameters are passed either as artifact key strings or as arrays/packed
QuantizedWeightobjects, which are stored automatically inweights.safetensors. Theparametersmapping remains available when the caller already owns stable artifact keys. This is the concise explicit-graph API;add_op()remains the lower-level escape hatch when a manifest needs exact port dictionaries.
- add_module(name, module, input_value, *, output=None)[source]¶
Append a registered sparse NN module node.
- output(value, *, name=None, value_type=None)[source]¶
Describe a public graph output, inferring its type by default.
- Return type:
- Parameters:
- add_quantized_parameter(name, value)[source]¶
Store a packed quantized parameter and return its artifact prefix.
- Return type:
- Parameters:
name (str)
value (QuantizedWeight)
- module_parameters(node_id, module, parameters)[source]¶
Artifact registered module parameters into artifact weights.
- manifest(*, outputs=None, output_name='output', output_value=None, input_type=None, output_type=None, producer=None)[source]¶
Build an immutable manifest from the accumulated graph.
- Return type:
- Parameters:
outputs (Mapping[str, Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes'] | ~mlx_lattice.artifact.builder.GraphOutput | None] | ~collections.abc.Sequence[str] | None)
output_name (str)
output_value (str | None)
input_type (Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes'] | None)
output_type (Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes'] | None)
- mlx_lattice.artifact.builder.build_lattice_graph_artifact(builder, *, outputs, producer=None)[source]¶
Build an artifact from an explicit lattice graph.
- Return type:
- Parameters:
builder (LatticeGraphBuilder)
outputs (Mapping[str, Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes'] | ~mlx_lattice.artifact.builder.GraphOutput | None] | ~collections.abc.Sequence[str])
- mlx_lattice.artifact.builder.build_lattice_module_artifact(module, *, input_name='input', output_name='output', input_type='sparse_tensor', output_type=None, producer=None)[source]¶
Build a sparse NN module artifact graph.
Built-in lattice modules and sequential containers build structurally. Custom modules can implement
build_lattice_graph(builder, input_name)to emit arbitrary DAGs with the same builder used internally.- Return type:
- Parameters:
module (Module)
input_name (str)
output_name (str)
input_type (Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes'])
output_type (Literal['any', 'sparse_tensor', 'dense_tensor', 'relation', 'coordinate_set', 'alignment', 'quantization', 'point_voxel_map', 'coordinate_ordering', 'sparse_occupancy', 'occupancy_expansion', 'bytes'] | None)