IR API¶
lattice_contract is now MLIR-first. Its public surface contains the
annotation-backed lattice dialect schema plus a generated textual MLIR builder.
It does not import MLX, Torch, native kernels, or sparse runtime objects.
For the conceptual model, read Sparse model IR.
Annotated dialect schema¶
The dialect schema is executable metadata: decorators register types, attributes, operations, operands, results, and operation attributes once. The builder consumes this schema directly, so exporter code can call the generated operation surface instead of carrying a parallel op-name registry.
The current dialect surface is intentionally small but semantic: sparse ABI construction/decomposition, symbolic weight binding, the sparse convolution family (forward, submanifold, target, transpose, and generative transpose), local/global sparse pooling, point/voxel conversion, dense feature projection, dense feature activation, dense feature normalization, sparse feature replacement, and coordinate-aligned sparse binary algebra. Backend execution routes such as TensorOps, CSR views, point-to-voxel cache maps, or rulebook layouts are not encoded in the dialect.
- class lattice_contract.schema.TypeParameter(name, kind)[source]¶
Bases:
objectOne MLIR dialect type parameter.
- class lattice_contract.schema.TypeDef(name, mnemonic, parameters=(), summary='')[source]¶
Bases:
objectAnnotated MLIR type declaration.
- Parameters:
name (str)
mnemonic (str)
parameters (tuple[TypeParameter, ...])
summary (str)
- parameters: tuple[TypeParameter, ...]¶
- class lattice_contract.schema.AttrParameter(name, kind)[source]¶
Bases:
objectOne MLIR dialect attribute parameter.
- class lattice_contract.schema.AttrDef(name, mnemonic, parameters=(), values=(), summary='')[source]¶
Bases:
objectAnnotated MLIR attribute declaration.
- Parameters:
- parameters: tuple[AttrParameter, ...]¶
- class lattice_contract.schema.OperandDef(name, type, kind='ssa', optional=False)[source]¶
Bases:
objectOne operation operand declaration.
- class lattice_contract.schema.ResultDef(name, type)[source]¶
Bases:
objectOne operation result declaration.
- class lattice_contract.schema.OpAttributeDef(name, kind, required=True)[source]¶
Bases:
objectOne operation attribute declaration.
- Parameters:
- class lattice_contract.schema.OpDef(name, python_name, operands=(), results=(), attributes=(), assembly='functional', summary='')[source]¶
Bases:
objectAnnotated MLIR operation declaration.
- Parameters:
name (str)
python_name (str)
operands (tuple[OperandDef, ...])
attributes (tuple[OpAttributeDef, ...])
assembly (str)
summary (str)
- operands: tuple[OperandDef, ...]¶
- attributes: tuple[OpAttributeDef, ...]¶
- class lattice_contract.schema.DialectSchema(namespace, types=<factory>, attrs=<factory>, ops=<factory>, _ops_by_python_name=<factory>)[source]¶
Bases:
objectAnnotation-backed dialect schema.
The schema is intentionally executable: decorators register MLIR declarations once, and downstream builders/importers consume the registry instead of maintaining hand-written op-name maps.
- Parameters:
- attr(name, mnemonic, *, parameters=(), values=(), summary='')[source]¶
Register a dialect attribute declaration.
- op(name, *, python_name=None, operands=(), results=(), attributes=(), assembly='functional', summary='')[source]¶
Register a dialect operation declaration.
- lattice_contract.schema.type_param(name, kind)[source]¶
Declare one dialect type parameter.
- Return type:
- Parameters:
- lattice_contract.schema.attr_param(name, kind)[source]¶
Declare one dialect attribute parameter.
- Return type:
- Parameters:
- lattice_contract.schema.operand(name, type, *, kind='ssa', optional=False)[source]¶
Declare one operation operand.
- Return type:
- Parameters:
- lattice_contract.schema.op_attr(name, kind, *, required=True)[source]¶
Declare one operation attribute.
- Return type:
- Parameters:
- lattice_contract.schema.schema_digest(schema)[source]¶
Return a compact stable digest useful for drift tests.
- lattice_contract.schema.canonical_schema(schema)[source]¶
Return the canonical public schema used for artifact compatibility.
- Return type:
- Parameters:
schema (DialectSchema)
- lattice_contract.schema.schema_fingerprint(schema)[source]¶
Return a deterministic SHA-256 fingerprint for a dialect schema.
- Return type:
- Parameters:
schema (DialectSchema)
- class lattice_contract.dialect.SparseTensorType[source]¶
Bases:
objectAnnotated sparse tensor type declaration.
- class lattice_contract.dialect.WeightType[source]¶
Bases:
objectAnnotated symbolic weight type declaration.
- class lattice_contract.dialect.CoordAttr[source]¶
Bases:
objectAnnotated coordinate convention attribute.
- class lattice_contract.dialect.FeatureLayoutAttr[source]¶
Bases:
objectAnnotated feature layout attribute.
- class lattice_contract.dialect.WeightLayoutAttr[source]¶
Bases:
objectAnnotated weight layout attribute.
- class lattice_contract.dialect.PackingAttr[source]¶
Bases:
objectAnnotated weight packing attribute.
- class lattice_contract.dialect.ActivationAttr[source]¶
Bases:
objectAnnotated dense feature activation attribute.
- class lattice_contract.dialect.GeluApproxAttr[source]¶
Bases:
objectAnnotated GELU approximation attribute.
- class lattice_contract.dialect.JoinAttr[source]¶
Bases:
objectAnnotated sparse algebra join attribute.
- class lattice_contract.dialect.BinaryOpAttr[source]¶
Bases:
objectAnnotated sparse binary operation attribute.
- class lattice_contract.dialect.PoolModeAttr[source]¶
Bases:
objectAnnotated sparse pooling reduction mode attribute.
- class lattice_contract.dialect.VoxelReductionAttr[source]¶
Bases:
objectAnnotated point-to-voxel feature aggregation reduction.
- class lattice_contract.dialect.PointInterpolationAttr[source]¶
Bases:
objectAnnotated voxel-to-point interpolation mode.
- lattice_contract.dialect.sparse_decompose()[source]¶
Register lattice.sparse.decompose.
- Return type:
- lattice_contract.dialect.sparse_with_features()[source]¶
Register lattice.sparse.with_features.
- Return type:
- lattice_contract.dialect.normalized_subm_conv3d()[source]¶
Register lattice.normalized_subm_conv3d.
- Return type:
- lattice_contract.dialect.conv_transpose3d()[source]¶
Register lattice.conv_transpose3d.
- Return type:
- lattice_contract.dialect.target_conv_transpose3d()[source]¶
Register lattice.target_conv_transpose3d.
- Return type:
- lattice_contract.dialect.normalized_conv_transpose3d()[source]¶
Register lattice.normalized_conv_transpose3d.
- Return type:
- lattice_contract.dialect.target_normalized_conv_transpose3d()[source]¶
Register lattice.target_normalized_conv_transpose3d.
- Return type:
- lattice_contract.dialect.generative_conv_transpose3d()[source]¶
Register lattice.generative_conv_transpose3d.
- Return type:
- lattice_contract.dialect.normalized_generative_conv_transpose3d()[source]¶
Register lattice.normalized_generative_conv_transpose3d.
- Return type:
- lattice_contract.dialect.pool_transpose3d()[source]¶
Register lattice.pool_transpose3d.
- Return type:
- lattice_contract.dialect.trilinear_upsample3d()[source]¶
Register lattice.trilinear_upsample3d.
- Return type:
MLIR builder¶
The builder emits textual lattice MLIR from the annotated schema. It is intended
for exporters and tests; semantic verification remains the job of
lattice-opt and the MLIR dialect verifier.
Generated modules include the required artifact ABI metadata:
lattice.ir_version = 2 and
lattice.weight_file = "weights.safetensors". These attributes are part of
the stable exchange contract, not optional documentation. The corresponding
Python constants are exported as CURRENT_DIALECT_VERSION,
ARTIFACT_GRAPH_FILE, and ARTIFACT_WEIGHT_FILE.
- class lattice_contract.mlir.builder.TensorType(text)[source]¶
Bases:
objectRaw MLIR tensor type used at graph ABI boundaries.
- Parameters:
text (str)
- class lattice_contract.mlir.builder.SparseTensorType(dtype='f16', rank=3, coord='batch_x_y_z', feature='row_channel')[source]¶
Bases:
objectLattice sparse tensor type.
- class lattice_contract.mlir.builder.WeightType(family, dtype='f16')[source]¶
Bases:
objectLattice symbolic weight type.
- class lattice_contract.mlir.builder.Packing(kind='dense', group_size=0, scale_dtype='', mode='')[source]¶
Bases:
objectLattice weight packing attribute.
- class lattice_contract.mlir.builder.SSAValue(name, type)[source]¶
Bases:
objectNamed SSA value plus its MLIR type.
- Parameters:
name (str)
type (TensorType | SparseTensorType | WeightType)
- type: TensorType | SparseTensorType | WeightType¶
- lattice_contract.mlir.builder.quantized_packing(kind, *, group_size, scale_dtype='f16', mode='affine')[source]¶
Return affine int4/int8 weight packing.
- class lattice_contract.mlir.builder.EmitFn(*args, **kwargs)[source]¶
Bases:
ProtocolTextual MLIR emitter callable with a stable function name.
- class lattice_contract.mlir.builder.EmitRegistry(functions, default)[source]¶
Bases:
objectAnnotation-backed textual assembly emitter registry.
- lattice_contract.mlir.builder.mlir_emitter(*, op)[source]¶
Bind a textual assembly hook to a dialect declaration.
- class lattice_contract.mlir.builder.MLIRModuleBuilder(name='forward')[source]¶
Bases:
objectAnnotation-driven textual MLIR module builder.
Operation methods are generated dynamically from
lattice_contract.dialect.LATTICE_DIALECT. The builder is therefore a convenience layer over the annotated schema, not a second op registry.- Parameters:
name (str)
- argument(name, type, *, role='tensor')[source]¶
Append a function argument and return its SSA value.
- Return type:
- Parameters:
name (str)
type (str | TensorType | SparseTensorType)
role (Literal['tensor', 'sparse_coords', 'sparse_features', 'sparse_active'])