Skip to main content

WeightMaterializer

Trait WeightMaterializer 

Source
pub trait WeightMaterializer: Send + Sync {
    // Required methods
    fn descriptor(&self) -> &WeightMaterializerDescriptor;
    fn execution_schema(
        &self,
        family: &PreparedModelFamily,
        device: &DeviceDescriptor,
    ) -> Result<WeightSchema, VNextError>;
    fn materialize_component<'source>(
        &self,
        source: &'source dyn WeightComponentSource,
        source_components: &[&WeightComponentSpec],
        execution_component: &WeightComponentSpec,
    ) -> Result<WeightComponentPayload<'source>, VNextError>;

    // Provided methods
    fn component_sources(
        &self,
        family: &PreparedModelFamily,
        execution_schema: &WeightSchema,
    ) -> Result<BTreeMap<WeightId, Vec<WeightId>>, VNextError> { ... }
    fn materialize_components<'source>(
        &self,
        source: &'source dyn WeightComponentSource,
        source_components: &[&WeightComponentSpec],
        execution_components: &[&WeightComponentSpec],
    ) -> Result<Vec<WeightComponentPayload<'source>>, VNextError> { ... }
}
Expand description

Trusted authority for one physical weight transformation.

Implementations are invoked once while compiling an immutable plan. They must derive the complete execution schema from the prepared family and device descriptor without allocating device memory or reading request state. During static initialization the same retained implementation turns source components into the exact execution components recorded in that plan; no provider or weight source may bypass this authority.

Required Methods§

Source

fn descriptor(&self) -> &WeightMaterializerDescriptor

Source

fn execution_schema( &self, family: &PreparedModelFamily, device: &DeviceDescriptor, ) -> Result<WeightSchema, VNextError>

Source

fn materialize_component<'source>( &self, source: &'source dyn WeightComponentSource, source_components: &[&WeightComponentSpec], execution_component: &WeightComponentSpec, ) -> Result<WeightComponentPayload<'source>, VNextError>

Materialize one execution component on the cold initialization path.

source_components is resolved from the immutable plan’s ordered source map. Implementations may borrow source bytes for identity layouts or return owned bytes for repacked/quantized layouts.

Provided Methods§

Source

fn component_sources( &self, family: &PreparedModelFamily, execution_schema: &WeightSchema, ) -> Result<BTreeMap<WeightId, Vec<WeightId>>, VNextError>

Ordered source-component identities for every execution component.

The default only permits a same-id mapping. Materializers that create derived component identities or combine multiple source components must declare that provenance explicitly.

Source

fn materialize_components<'source>( &self, source: &'source dyn WeightComponentSource, source_components: &[&WeightComponentSpec], execution_components: &[&WeightComponentSpec], ) -> Result<Vec<WeightComponentPayload<'source>>, VNextError>

Materialize execution components that share one exact ordered source set.

The default preserves existing one-component implementations. Expensive transforms may override this method to decode, quantize, or repack their common source once and return one payload per requested component in the same order.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§