Skip to main content

Module

Trait Module 

Source
pub trait Module<E: Element>: Send + Sync {
    // Required method
    fn express<'tape>(&self, input: Value<'tape, E>) -> Value<'tape, E>;

    // Provided method
    fn visit(&self, visitor: &mut dyn Visitor) { ... }
}
Expand description

A named, parameterized recording function: the unit of model composition.

A module holds its parameters as detached Symbols and records its formula through the public operation surface — it never owns payloads (the caller’s Parameters do) and never touches the engine. Expression happens at record time, once per topology; the cost never reaches a run, a plan, or a kernel, which is why composing through dyn Module (see Sequential) sits squarely inside the sanctioned dynamic-dispatch exceptions.

Programmatic access to a module’s parameters — tying, freezing, inspection — goes through its typed accessors (weights(), struct fields), never through names. Module::visit exists for the serialization boundary alone, where checkpoints need stable structured paths.

Required Methods§

Source

fn express<'tape>(&self, input: Value<'tape, E>) -> Value<'tape, E>

Records this module’s formula over input — on the tape the input already carries — and returns the output value.

Provided Methods§

Source

fn visit(&self, visitor: &mut dyn Visitor)

Walks this module’s parameters and children in a stable order, announcing each parameter under its local name and each child under a path segment. Stateless modules do nothing, which is the default.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<E: Element> Module<E> for Activation

Source§

impl<E: Element> Module<E> for Conv2d<E>

Source§

impl<E: Element> Module<E> for Dropout<E>

Source§

impl<E: Element> Module<E> for Embedding<E>

Source§

impl<E: Element> Module<E> for LayerNorm<E>

Source§

impl<E: Element> Module<E> for Linear<E>

Source§

impl<E: Element> Module<E> for Mlp<E>

Source§

impl<E: Element> Module<E> for RmsNorm<E>

Source§

impl<E: Element> Module<E> for Sequential<E>