pub struct ModuleContext<'a> { /* private fields */ }Expand description
Where in a module hierarchy a tensor was found.
The one thing a PackTensor cannot carry. Its contents are Burn module vocabulary
("Struct:Linear", "Vec", "Enum:ConvType"), produced by the Module derive macro,
while burn-pack is a format crate with no notion of modules at all. Rather than push that
vocabulary into the on-disk type, the traversal hands it to adapters alongside the tensor.
Borrowed rather than owned: both producers (Collector and
Applier) keep this stack live as they walk the module, and pass it
straight through.
Note this carries only the container stack, not the path. A tensor’s parameter name comes
from the tensor itself, because ChainAdapter threads each adapter’s output into the
next: an adapter that renames must be visible to the one after it, which a fixed context
could not express.
Implementations§
Source§impl<'a> ModuleContext<'a>
impl<'a> ModuleContext<'a>
Sourcepub fn new(container_stack: &'a [String]) -> Self
pub fn new(container_stack: &'a [String]) -> Self
Wrap the container stack captured at a point in a module traversal.
The stack runs outermost-first, one entry per level entered, e.g.
["Struct:Model", "Vec", "Struct:Linear"]. An empty stack means the tensor was not
reached through any user-defined module.
Sourcepub fn module_type(&self) -> Option<&'a str>
pub fn module_type(&self) -> Option<&'a str>
The innermost user-defined module type, skipping collection wrappers.
This is what adapters key on, because a parameter’s meaning comes from the module that
declares it and not from the Vec or array that happens to hold that module.
§Examples
Linear.weight->Some("Struct:Linear")Vec<Linear>[0].weight->Some("Struct:Linear")- a stack with no
Struct:/Enum:entry at all ->None