Skip to content

models #

vtl.nn.models

Sequential[T] composes layers and a loss around an autograd context. Its builder methods cover inputs, dense/convolutional layers, pooling, activations, normalization, embeddings, recurrent and attention layers, and loss selection. The architecture is an ordered list: each builder adds a layer whose output feeds the next layer. The context is supplied when constructing the model.

gru(input_size, hidden_size) adds a single-layer CPU GRU. It uses a zero initial hidden state and expects [sequence, batch, features] input. Its output keeps the sequence and batch dimensions and replaces the feature dimension with hidden_size.

import vtl.autograd
import vtl.nn.models

ctx := autograd.ctx[f32]()
mut model := models.sequential_from_ctx[f32](ctx)
model.input([4])
model.linear(8)
model.relu()
model.linear(2)
model.mse_loss()

Use forward for inference and the model's loss/backpropagation methods for training; consult sequential.v for exact method signatures.

save(path) writes model weights. save_checkpoint(path, epoch, loss) also stores epoch/loss metadata; load_weights(path) loads into an already-built compatible model and Sequential.load_checkpoint[T](path) reads checkpoint metadata. Registered custom-module parameters and buffers are stored by name and restored into the prebuilt module graph; callback code itself is not serialized. For resumable Adam training, build the optimizer with the model's parameters and use save_training_checkpoint(path, epoch, loss, optimizer); restore into a compatible model and a built Adam optimizer with load_training_checkpoint(path, mut optimizer). This stores Adam's scalar configuration and first/second moments alongside model weights and metadata. For SGD with momentum, use save_sgd_training_checkpoint and load_sgd_training_checkpoint; these store the scalar configuration, momentum buffers, and first-step initialization state. For AdamW, use save_adamw_training_checkpoint and load_adamw_training_checkpoint to store its scalar configuration and first/second moments. For RMSProp, use save_rmsprop_training_checkpoint and load_rmsprop_training_checkpoint; these store its scalar configuration and squared-gradient buffers. For AdaGrad, use save_adagrad_training_checkpoint and load_adagrad_training_checkpoint; these store its scalar configuration and accumulated squared gradients. For NAdam and RAdam, use the corresponding save_nadam_training_checkpoint / load_nadam_training_checkpoint and save_radam_training_checkpoint / load_radam_training_checkpoint methods; these persist the step schedule, scalar configuration, and both moments. The custom optimizer types, device remapping, and cross-version migration are not supported by this API yet. The JSON format has version 1.0, ordered layer definitions, per-layer weight maps, optimizer metadata, and checkpoint metadata; tensor weights are base64 encoded. Loading rejects a version mismatch.

For portable .npy weight bundles, use models.export_portable_weights(model, directory) and models.load_portable_weights(mut model, manifest_path); the JSON manifest is read and validated by models.read_portable_manifest(path), and each .npy entry path must stay inside the bundle directory. Only trainable parameters from layer.variables() are exported; non-trainable buffers such as BatchNorm running mean/variance are not included. This is a weight-only format, separate from the JSON+base64 checkpoint and inference-checkpoint APIs below.

For versioned, inference-only CPU weights, use save_inference_checkpoint(path) and load_inference_checkpoint(path) on a prebuilt Sequential. This separate data-only JSON format currently supports f32/f64 input, linear, and relu layers and validates architecture, dtype, shapes, and finite values before loading. It does not store optimizer state or support training resume; see the inference checkpoint guide.

import vtl.nn.models
import vtl.nn.optimizers

mut model := models.sequential[f64]()
model.input([2])
model.linear(1)
mut optimizer := optimizers.adam_optimizer[f64](learning_rate: 0.001)
optimizer.build_params(model.info.layers)
model.save_training_checkpoint('training.json', 12, 0.25, optimizer)!

mut resumed := models.sequential[f64]()
resumed.input([2])
resumed.linear(1)
mut resumed_optimizer := optimizers.adam_optimizer[f64](learning_rate: 0.001)
resumed_optimizer.build_params(resumed.info.layers)
epoch, loss := resumed.load_training_checkpoint('training.json', mut resumed_optimizer)!

Start with the neural-network tutorial.

fn export_portable_weights #

fn export_portable_weights[T](nn &Sequential[T], directory string) !PortableManifest

export_portable_weights writes every Sequential parameter as a .npy file plus a JSON manifest. Paths inside the manifest are relative to directory. Only trainable parameters reported by layer.variables() are exported; non-trainable buffers such as BatchNorm running statistics are not included.

fn load_portable_weights #

fn load_portable_weights[T](mut nn Sequential[T], manifest_path string) !

load_portable_weights restores parameters into an already-constructed Sequential model. Architecture, dtype, file count, entry path confinement, and each shape are validated before values are copied.

fn migrate_checkpoint #

fn migrate_checkpoint(data []u8, target_version int) !MigrationResult

migrate_checkpoint upgrades a legacy inference checkpoint to the current schema. Version 0 payloads omit format/version and use data for parameter values; they are upgraded to version 1 by renaming that field and adding the version metadata. Unknown or newer versions fail closed.

fn parse_map_location #

fn parse_map_location(text string) !MapLocation

parse_map_location accepts only cpu and rejects accelerator locations.

fn read_portable_manifest #

fn read_portable_manifest(path string) !PortableManifest

read_portable_manifest validates a portable weights manifest before any file is read.

fn sequential #

fn sequential[T]() &Sequential[T]

sequential creates a new sequential network with a new context.

fn sequential_from_ctx #

fn sequential_from_ctx[T](ctx &autograd.Context[T]) &Sequential[T]

sequential_from_ctx creates a new sequential network with the given context.

fn sequential_from_ctx_with_layers #

fn sequential_from_ctx_with_layers[T](ctx &autograd.Context[T], given_layers []types.Layer[T]) &Sequential[T]

sequential_from_ctx_with_layers creates a new sequential network with the given context and the given layers.

fn sequential_info #

fn sequential_info[T](ctx &autograd.Context[T], layers_ []types.Layer[T]) &SequentialInfo[T]

sequential_info creates a new neural network container with an empty list of layers.

fn sequential_with_layers #

fn sequential_with_layers[T](given_layers []types.Layer[T]) &Sequential[T]

sequential_with_layers creates a new sequential network with a new context and the given layers.

fn validate_model_compatibility #

fn validate_model_compatibility[T](saved_path string, model_layers []types.Layer[T]) !bool

validate_model_compatibility checks if a saved model is compatible with the given layers. Returns an error with details if incompatible.

fn MapLocation.from #

fn MapLocation.from[W](input W) !MapLocation

from returns the MapLocation value of an integer or of a field name, or an error if there is none.

fn Sequential.load_checkpoint #

fn Sequential.load_checkpoint[T](path string) !(int, f64)

load_checkpoint restores a Sequential model's weights and training metadata from a JSON file. Returns the epoch and loss from the checkpoint.

Note: The model must already be constructed with the same architecture. This method loads weights into an existing model.

fn (SequentialInfo[T]) input #

fn (mut ls SequentialInfo[T]) input(shape []int)

input adds a new input layer to the network with the given shape.

fn (SequentialInfo[T]) linear #

fn (mut ls SequentialInfo[T]) linear(output_size int)

linear adds a new linear layer to the network with the given output size

fn (SequentialInfo[T]) maxpool2d #

fn (mut ls SequentialInfo[T]) maxpool2d(kernel []int, padding []int, stride []int)

maxpool2d adds a new maxpool2d layer to the network with the given kernel size and stride.

fn (SequentialInfo[T]) mse_loss #

fn (mut ls SequentialInfo[T]) mse_loss()

mse_loss sets the loss function to the mean squared error loss.

fn (SequentialInfo[T]) sigmoid_cross_entropy_loss #

fn (mut ls SequentialInfo[T]) sigmoid_cross_entropy_loss()

sigmoid_cross_entropy_loss sets the loss function to the sigmoid cross entropy loss.

fn (SequentialInfo[T]) softmax_cross_entropy_loss #

fn (mut ls SequentialInfo[T]) softmax_cross_entropy_loss()

softmax_cross_entropy_loss sets the loss function to the softmax cross entropy loss.

fn (SequentialInfo[T]) flatten #

fn (mut ls SequentialInfo[T]) flatten()

flatten adds a new flatten layer to the network.

fn (SequentialInfo[T]) relu #

fn (mut ls SequentialInfo[T]) relu()

relu adds a new relu layer to the network.

fn (SequentialInfo[T]) leaky_relu #

fn (mut ls SequentialInfo[T]) leaky_relu()

leaky_relu adds a new leaky_relu layer to the network.

fn (SequentialInfo[T]) elu #

fn (mut ls SequentialInfo[T]) elu()

elu adds a new elu layer to the network.

fn (SequentialInfo[T]) sigmoid #

fn (mut ls SequentialInfo[T]) sigmoid()

sigmoid adds a new sigmoid layer to the network.

fn (SequentialInfo[T]) tanh #

fn (mut ls SequentialInfo[T]) tanh()

tanh adds a new tanh layer to the network.

fn (SequentialInfo[T]) softmax #

fn (mut ls SequentialInfo[T]) softmax()

softmax adds a new softmax layer to the network.

fn (SequentialInfo[T]) gelu #

fn (mut ls SequentialInfo[T]) gelu()

gelu adds a new GELU layer to the network.

fn (SequentialInfo[T]) swish #

fn (mut ls SequentialInfo[T]) swish()

swish adds a new Swish layer to the network.

fn (SequentialInfo[T]) mish #

fn (mut ls SequentialInfo[T]) mish()

mish adds a new Mish layer to the network.

fn (SequentialInfo[T]) softplus #

fn (mut ls SequentialInfo[T]) softplus()

softplus adds a Softplus layer to the network.

fn (SequentialInfo[T]) selu #

fn (mut ls SequentialInfo[T]) selu()

selu adds a SELU layer to the network.

fn (SequentialInfo[T]) hardswish #

fn (mut ls SequentialInfo[T]) hardswish()

hardswish adds a HardSwish layer to the network.

fn (SequentialInfo[T]) conv2d #

fn (mut ls SequentialInfo[T]) conv2d(in_channels int, out_channels int, kernel_size []int, config layers.Conv2DConfig)

conv2d adds a new Conv2D layer to the network.

fn (SequentialInfo[T]) conv_transpose2d #

fn (mut ls SequentialInfo[T]) conv_transpose2d(out_channels int, kernel_size []int, config layers.ConvTranspose2DConfig)

conv_transpose2d adds a transposed convolution using the previous layer's [channels, height, width] shape.

fn (SequentialInfo[T]) batchnorm1d #

fn (mut ls SequentialInfo[T]) batchnorm1d(num_features int, config layers.BatchNorm1DConfig)

batchnorm1d adds a new BatchNorm1D layer to the network.

fn (SequentialInfo[T]) batchnorm2d #

fn (mut ls SequentialInfo[T]) batchnorm2d(num_features int, config layers.BatchNorm2DConfig)

batchnorm2d adds a new BatchNorm2D layer to the network.

fn (SequentialInfo[T]) batchnorm3d #

fn (mut ls SequentialInfo[T]) batchnorm3d(num_features int, config layers.BatchNorm3DConfig)

batchnorm3d adds a new BatchNorm3D layer to the network.

fn (SequentialInfo[T]) dropout #

fn (mut ls SequentialInfo[T]) dropout(prob f64)

dropout adds a dropout layer using the preceding layer's output shape.

fn (SequentialInfo[T]) avgpool2d #

fn (mut ls SequentialInfo[T]) avgpool2d(kernel []int, padding []int, stride []int)

avgpool2d adds a new AveragePool2D layer to the network.

fn (SequentialInfo[T]) avgpool3d #

fn (mut ls SequentialInfo[T]) avgpool3d(kernel []int, padding []int, stride []int)

avgpool3d appends an AveragePool3DLayer configured from the preceding layer's output shape.

fn (SequentialInfo[T]) maxpool3d #

fn (mut ls SequentialInfo[T]) maxpool3d(kernel []int, padding []int, stride []int)

maxpool3d appends a MaxPool3DLayer configured from the preceding layer's output shape.

fn (SequentialInfo[T]) global_avgpool2d #

fn (mut ls SequentialInfo[T]) global_avgpool2d()

global_avgpool2d adds a new GlobalAveragePool2D layer to the network.

fn (SequentialInfo[T]) adaptive_avgpool2d #

fn (mut ls SequentialInfo[T]) adaptive_avgpool2d(output_size []int)

adaptive_avgpool2d adds a fixed-output adaptive average-pooling layer.

fn (SequentialInfo[T]) adaptive_maxpool2d #

fn (mut ls SequentialInfo[T]) adaptive_maxpool2d(output_size []int)

adaptive_maxpool2d appends an AdaptiveMaxPool2DLayer configured from the preceding layer's output shape.

fn (SequentialInfo[T]) adaptive_avgpool1d #

fn (mut ls SequentialInfo[T]) adaptive_avgpool1d(output_size int)

adaptive_avgpool1d appends an AdaptiveAvgPool1DLayer configured from the preceding layer's output shape.

fn (SequentialInfo[T]) adaptive_maxpool1d #

fn (mut ls SequentialInfo[T]) adaptive_maxpool1d(output_size int)

adaptive_maxpool1d appends an AdaptiveMaxPool1DLayer configured from the preceding layer's output shape.

fn (SequentialInfo[T]) adaptive_avgpool3d #

fn (mut ls SequentialInfo[T]) adaptive_avgpool3d(output_size []int)

adaptive_avgpool3d appends an AdaptiveAvgPool3DLayer configured from the preceding layer's output shape.

fn (SequentialInfo[T]) adaptive_maxpool3d #

fn (mut ls SequentialInfo[T]) adaptive_maxpool3d(output_size []int)

adaptive_maxpool3d appends an AdaptiveMaxPool3DLayer configured from the preceding layer's output shape.

fn (SequentialInfo[T]) avgpool1d #

fn (mut ls SequentialInfo[T]) avgpool1d(kernel int, padding int, stride int)

avgpool1d appends an AveragePool1DLayer configured from the preceding layer's output shape.

fn (SequentialInfo[T]) maxpool1d #

fn (mut ls SequentialInfo[T]) maxpool1d(kernel int, padding int, stride int)

maxpool1d appends a MaxPool1DLayer configured from the preceding layer's output shape.

fn (SequentialInfo[T]) pad2d #

fn (mut ls SequentialInfo[T]) pad2d(padding []int, mode vtl.PadMode, constant T)

pad2d appends a Pad2DLayer configured from the preceding layer's output shape.

fn (SequentialInfo[T]) pad1d #

fn (mut ls SequentialInfo[T]) pad1d(padding []int, mode vtl.PadMode, constant T)

pad1d appends a Pad1DLayer configured from the preceding layer's output shape.

fn (SequentialInfo[T]) pad3d #

fn (mut ls SequentialInfo[T]) pad3d(padding []int, mode vtl.PadMode, constant T)

pad3d appends a Pad3DLayer configured from the preceding layer's output shape.

fn (SequentialInfo[T]) layer_norm #

fn (mut ls SequentialInfo[T]) layer_norm(normalized_shape []int, config layers.LayerNormConfig)

layer_norm adds a new LayerNorm layer to the network.

fn (SequentialInfo[T]) group_norm #

fn (mut ls SequentialInfo[T]) group_norm(num_groups int, config layers.GroupNormConfig)

group_norm adds a channel-first GroupNorm layer to the network.

fn (SequentialInfo[T]) rms_norm #

fn (mut ls SequentialInfo[T]) rms_norm(normalized_shape []int, config layers.RMSNormConfig)

rms_norm adds a trailing-dimension RMSNorm layer to the network.

fn (SequentialInfo[T]) embedding #

fn (mut ls SequentialInfo[T]) embedding(vocab_size int, embedding_dim int)

embedding adds a new Embedding layer to the network.

fn (SequentialInfo[T]) lstm #

fn (mut ls SequentialInfo[T]) lstm(input_size int, hidden_size int, num_layers int)

lstm adds a new LSTM layer to the network.

fn (SequentialInfo[T]) gru #

fn (mut ls SequentialInfo[T]) gru(input_size int, hidden_size int)

gru adds a single-layer, unidirectional GRU with a zero initial state.

fn (SequentialInfo[T]) conv1d #

fn (mut ls SequentialInfo[T]) conv1d(out_channels int, kernel_size int, config layers.Conv1DConfig)

conv1d adds a Conv1D layer using the previous layer's [channels, length] shape.

fn (SequentialInfo[T]) conv_transpose1d #

fn (mut ls SequentialInfo[T]) conv_transpose1d(out_channels int, kernel_size int, config layers.ConvTranspose1DConfig)

conv_transpose1d adds a transposed convolution using the previous layer's [channels, length] shape.

fn (SequentialInfo[T]) multihead_attention #

fn (mut ls SequentialInfo[T]) multihead_attention(embed_dim int, num_heads int)

multihead_attention adds a new MultiHeadAttention layer to the network.

fn (SequentialInfo[T]) positional_encoding #

fn (mut ls SequentialInfo[T]) positional_encoding(embed_dim int, max_len int)

positional_encoding adds a new PositionalEncoding layer to the network.

fn (SequentialInfo[T]) cross_entropy_loss #

fn (mut ls SequentialInfo[T]) cross_entropy_loss()

cross_entropy_loss sets the loss function to cross entropy loss.

fn (SequentialInfo[T]) bce_loss #

fn (mut ls SequentialInfo[T]) bce_loss()

bce_loss sets the loss function to binary cross entropy loss.

fn (SequentialInfo[T]) huber_loss #

fn (mut ls SequentialInfo[T]) huber_loss()

huber_loss sets the loss function to Huber loss.

fn (SequentialInfo[T]) l1_loss #

fn (mut ls SequentialInfo[T]) l1_loss()

l1_loss sets mean absolute error as the loss function.

fn (SequentialInfo[T]) hinge_loss #

fn (mut ls SequentialInfo[T]) hinge_loss()

hinge_loss sets binary hinge loss as the loss function.

fn (SequentialInfo[T]) focal_loss #

fn (mut ls SequentialInfo[T]) focal_loss()

focal_loss sets binary focal loss with its default configuration.

fn (SequentialInfo[T]) nll_loss #

fn (mut ls SequentialInfo[T]) nll_loss()

nll_loss sets the loss function to negative log likelihood loss.

fn (SequentialInfo[T]) kl_div_loss #

fn (mut ls SequentialInfo[T]) kl_div_loss()

kl_div_loss sets the loss function to KL divergence loss.

fn (Sequential[T]) save_inference_checkpoint #

fn (nn &Sequential[T]) save_inference_checkpoint(path string) !

save_inference_checkpoint stores CPU inference weights and the supported Sequential architecture in a versioned, data-only JSON format. It does not store optimizer state or training-resume metadata.

fn (Sequential[T]) load_inference_checkpoint #

fn (mut nn Sequential[T]) load_inference_checkpoint(path string) !

load_inference_checkpoint validates a versioned CPU inference checkpoint against this already-constructed Sequential model before copying any weights.

fn (Sequential[T]) load_inference_checkpoint_with_location #

fn (mut nn Sequential[T]) load_inference_checkpoint_with_location(path string, location string) !

load_inference_checkpoint_with_location validates the requested map target before reading the checkpoint file. Accelerator locations fail explicitly.

fn (Sequential[T]) load_inference_checkpoint_bytes #

fn (mut nn Sequential[T]) load_inference_checkpoint_bytes(data []u8, location MapLocation) !

load_inference_checkpoint_bytes applies checkpoint migration to an in-memory payload, so callers can load legacy checkpoints without writing a temporary file. The map target is checked at the real load boundary.

fn (Sequential[T]) input #

fn (mut nn Sequential[T]) input(shape []int)

input adds a new input layer to the network with the given shape.

fn (Sequential[T]) linear #

fn (mut nn Sequential[T]) linear(output_size int)

linear adds a new linear layer to the network with the given output size

fn (Sequential[T]) maxpool2d #

fn (mut nn Sequential[T]) maxpool2d(kernel []int, padding []int, stride []int)

maxpool2d adds a new maxpool2d layer to the network with the given kernel size and stride.

fn (Sequential[T]) mse_loss #

fn (mut nn Sequential[T]) mse_loss()

mse_loss sets the loss function to the mean squared error loss.

fn (Sequential[T]) sigmoid_cross_entropy_loss #

fn (mut nn Sequential[T]) sigmoid_cross_entropy_loss()

sigmoid_cross_entropy_loss sets the loss function to the sigmoid cross entropy loss.

fn (Sequential[T]) softmax_cross_entropy_loss #

fn (mut nn Sequential[T]) softmax_cross_entropy_loss()

softmax_cross_entropy_loss sets the loss function to the softmax cross entropy loss.

fn (Sequential[T]) flatten #

fn (mut nn Sequential[T]) flatten()

flatten adds a new flatten layer to the network.

fn (Sequential[T]) relu #

fn (mut nn Sequential[T]) relu()

relu adds a new relu layer to the network.

fn (Sequential[T]) leaky_relu #

fn (mut nn Sequential[T]) leaky_relu()

leaky_relu adds a new leaky_relu layer to the network.

fn (Sequential[T]) elu #

fn (mut nn Sequential[T]) elu()

elu adds a new elu layer to the network.

fn (Sequential[T]) sigmoid #

fn (mut nn Sequential[T]) sigmoid()

sigmoid adds a new sigmoid layer to the network.

fn (Sequential[T]) tanh #

fn (mut nn Sequential[T]) tanh()

tanh adds a new tanh layer to the network.

fn (Sequential[T]) softmax #

fn (mut nn Sequential[T]) softmax()

softmax adds a new softmax layer to the network.

fn (Sequential[T]) gelu #

fn (mut nn Sequential[T]) gelu()

gelu adds a new GELU layer to the network.

fn (Sequential[T]) swish #

fn (mut nn Sequential[T]) swish()

swish adds a new Swish layer to the network.

fn (Sequential[T]) mish #

fn (mut nn Sequential[T]) mish()

mish adds a new Mish layer to the network.

fn (Sequential[T]) softplus #

fn (mut nn Sequential[T]) softplus()

softplus adds a Softplus activation layer to the network.

fn (Sequential[T]) selu #

fn (mut nn Sequential[T]) selu()

selu adds a SELU activation layer to the network.

fn (Sequential[T]) hardswish #

fn (mut nn Sequential[T]) hardswish()

hardswish adds a HardSwish activation layer to the network.

fn (Sequential[T]) conv2d #

fn (mut nn Sequential[T]) conv2d(in_channels int, out_channels int, kernel_size []int, config layers.Conv2DConfig)

conv2d adds a new Conv2D layer to the network.

fn (Sequential[T]) conv_transpose2d #

fn (mut nn Sequential[T]) conv_transpose2d(out_channels int, kernel_size []int, config layers.ConvTranspose2DConfig)

conv_transpose2d adds a 2D transposed convolution over channel-first input.

fn (Sequential[T]) batchnorm1d #

fn (mut nn Sequential[T]) batchnorm1d(num_features int, config layers.BatchNorm1DConfig)

batchnorm1d adds a new BatchNorm1D layer to the network.

fn (Sequential[T]) batchnorm2d #

fn (mut nn Sequential[T]) batchnorm2d(num_features int, config layers.BatchNorm2DConfig)

batchnorm2d adds a new BatchNorm2D layer to the network.

fn (Sequential[T]) batchnorm3d #

fn (mut nn Sequential[T]) batchnorm3d(num_features int, config layers.BatchNorm3DConfig)

batchnorm3d adds a new BatchNorm3D layer to the network.

fn (Sequential[T]) dropout #

fn (mut nn Sequential[T]) dropout(prob f64)

dropout adds a dropout layer with the given probability.

fn (Sequential[T]) avgpool2d #

fn (mut nn Sequential[T]) avgpool2d(kernel []int, padding []int, stride []int)

avgpool2d adds a new AveragePool2D layer to the network.

fn (Sequential[T]) avgpool3d #

fn (mut nn Sequential[T]) avgpool3d(kernel []int, padding []int, stride []int)

avgpool3d adds a 3D average-pooling layer to the network.

fn (Sequential[T]) maxpool3d #

fn (mut nn Sequential[T]) maxpool3d(kernel []int, padding []int, stride []int)

maxpool3d adds a 3D max-pooling layer to the network.

fn (Sequential[T]) global_avgpool2d #

fn (mut nn Sequential[T]) global_avgpool2d()

global_avgpool2d adds a new GlobalAveragePool2D layer to the network.

fn (Sequential[T]) adaptive_avgpool2d #

fn (mut nn Sequential[T]) adaptive_avgpool2d(output_size []int)

adaptive_avgpool2d adds a fixed-output adaptive average-pooling layer.

fn (Sequential[T]) adaptive_maxpool2d #

fn (mut nn Sequential[T]) adaptive_maxpool2d(output_size []int)

adaptive_maxpool2d adds a fixed-output 2D adaptive max-pooling layer to the network.

fn (Sequential[T]) adaptive_avgpool1d #

fn (mut nn Sequential[T]) adaptive_avgpool1d(output_size int)

adaptive_avgpool1d adds a fixed-output 1D adaptive average-pooling layer to the network.

fn (Sequential[T]) adaptive_maxpool1d #

fn (mut nn Sequential[T]) adaptive_maxpool1d(output_size int)

adaptive_maxpool1d adds a fixed-output 1D adaptive max-pooling layer to the network.

fn (Sequential[T]) adaptive_avgpool3d #

fn (mut nn Sequential[T]) adaptive_avgpool3d(output_size []int)

adaptive_avgpool3d adds a fixed-output 3D adaptive average-pooling layer to the network.

fn (Sequential[T]) adaptive_maxpool3d #

fn (mut nn Sequential[T]) adaptive_maxpool3d(output_size []int)

adaptive_maxpool3d adds a fixed-output 3D adaptive max-pooling layer to the network.

fn (Sequential[T]) avgpool1d #

fn (mut nn Sequential[T]) avgpool1d(kernel int, padding int, stride int)

avgpool1d adds a 1D average-pooling layer to the network.

fn (Sequential[T]) maxpool1d #

fn (mut nn Sequential[T]) maxpool1d(kernel int, padding int, stride int)

maxpool1d adds a 1D max-pooling layer to the network.

fn (Sequential[T]) pad2d #

fn (mut nn Sequential[T]) pad2d(padding []int, mode vtl.PadMode, constant T)

pad2d adds a 2D padding layer to the network.

fn (Sequential[T]) pad1d #

fn (mut nn Sequential[T]) pad1d(padding []int, mode vtl.PadMode, constant T)

pad1d adds a 1D padding layer to the network.

fn (Sequential[T]) pad3d #

fn (mut nn Sequential[T]) pad3d(padding []int, mode vtl.PadMode, constant T)

pad3d adds a 3D padding layer to the network.

fn (Sequential[T]) layer_norm #

fn (mut nn Sequential[T]) layer_norm(normalized_shape []int, config layers.LayerNormConfig)

layer_norm adds a new LayerNorm layer to the network.

fn (Sequential[T]) group_norm #

fn (mut nn Sequential[T]) group_norm(num_groups int, config layers.GroupNormConfig)

group_norm adds a channel-first GroupNorm layer to the network.

fn (Sequential[T]) rms_norm #

fn (mut nn Sequential[T]) rms_norm(normalized_shape []int, config layers.RMSNormConfig)

rms_norm adds a trailing-dimension RMSNorm layer to the network.

fn (Sequential[T]) embedding #

fn (mut nn Sequential[T]) embedding(vocab_size int, embedding_dim int)

embedding adds a new Embedding layer to the network.

fn (Sequential[T]) lstm #

fn (mut nn Sequential[T]) lstm(input_size int, hidden_size int, num_layers int)

lstm adds a new LSTM layer to the network.

fn (Sequential[T]) gru #

fn (mut nn Sequential[T]) gru(input_size int, hidden_size int)

gru adds a new single-layer GRU to the network.

fn (Sequential[T]) conv1d #

fn (mut nn Sequential[T]) conv1d(out_channels int, kernel_size int, config layers.Conv1DConfig)

conv1d adds a one-dimensional convolution over channel-first sequence input.

fn (Sequential[T]) conv_transpose1d #

fn (mut nn Sequential[T]) conv_transpose1d(out_channels int, kernel_size int, config layers.ConvTranspose1DConfig)

conv_transpose1d adds a transposed convolution over channel-first sequence input.

fn (Sequential[T]) multihead_attention #

fn (mut nn Sequential[T]) multihead_attention(embed_dim int, num_heads int)

multihead_attention adds a new MultiHeadAttention layer to the network.

fn (Sequential[T]) positional_encoding #

fn (mut nn Sequential[T]) positional_encoding(embed_dim int, max_len int)

positional_encoding adds a new PositionalEncoding layer to the network.

fn (Sequential[T]) cross_entropy_loss #

fn (mut nn Sequential[T]) cross_entropy_loss()

cross_entropy_loss sets the loss function to cross entropy loss.

fn (Sequential[T]) bce_loss #

fn (mut nn Sequential[T]) bce_loss()

bce_loss sets the loss function to binary cross entropy loss.

fn (Sequential[T]) huber_loss #

fn (mut nn Sequential[T]) huber_loss()

huber_loss sets the loss function to Huber loss.

fn (Sequential[T]) l1_loss #

fn (mut nn Sequential[T]) l1_loss()

l1_loss sets mean absolute error as the loss function.

fn (Sequential[T]) hinge_loss #

fn (mut nn Sequential[T]) hinge_loss()

hinge_loss sets binary hinge loss as the loss function.

fn (Sequential[T]) focal_loss #

fn (mut nn Sequential[T]) focal_loss()

focal_loss sets binary focal loss with its default configuration.

fn (Sequential[T]) nll_loss #

fn (mut nn Sequential[T]) nll_loss()

nll_loss sets the loss function to negative log likelihood loss.

fn (Sequential[T]) kl_div_loss #

fn (mut nn Sequential[T]) kl_div_loss()

kl_div_loss sets the loss function to KL divergence loss.

fn (Sequential[T]) forward #

fn (mut nn Sequential[T]) forward(train &autograd.Variable[T]) !&autograd.Variable[T]

forward exposes this operation as part of the public API.

fn (Sequential[T]) train #

fn (mut nn Sequential[T]) train()

train enables training behavior for mode-aware layers such as dropout and batch normalization.

fn (Sequential[T]) eval #

fn (mut nn Sequential[T]) eval()

eval enables evaluation behavior for mode-aware layers such as dropout and batch normalization.

fn (Sequential[T]) loss #

fn (mut nn Sequential[T]) loss(output &autograd.Variable[T], target &vtl.Tensor[T]) !&autograd.Variable[T]

loss exposes this operation as part of the public API.

fn (Sequential[T]) save #

fn (nn &Sequential[T]) save(path string) !

save saves a Sequential model's weights to a JSON file. Does NOT save optimizer state - use save_checkpoint for full state.

fn (Sequential[T]) save_checkpoint #

fn (nn &Sequential[T]) save_checkpoint(path string, epoch int, loss f64) !

save_checkpoint saves a Sequential model's weights and training metadata to a JSON file.

fn (Sequential[T]) save_training_checkpoint #

fn (nn &Sequential[T]) save_training_checkpoint(path string, epoch int, loss f64,
	optimizer &optimizers.AdamOptimizer[T]) !

save_training_checkpoint stores model weights and Adam state for training resume.

fn (Sequential[T]) save_sgd_training_checkpoint #

fn (nn &Sequential[T]) save_sgd_training_checkpoint(path string, epoch int, loss f64,
	optimizer &optimizers.SgdOptimizer[T]) !

save_sgd_training_checkpoint stores model weights and SGD momentum state for an exact training resume.

fn (Sequential[T]) save_rmsprop_training_checkpoint #

fn (nn &Sequential[T]) save_rmsprop_training_checkpoint(path string, epoch int, loss f64,
	optimizer &optimizers.RMSPropOptimizer[T]) !

save_rmsprop_training_checkpoint stores model weights and RMSProp state for an exact training resume.

fn (Sequential[T]) save_adagrad_training_checkpoint #

fn (nn &Sequential[T]) save_adagrad_training_checkpoint(path string, epoch int, loss f64,
	optimizer &optimizers.AdaGradOptimizer[T]) !

save_adagrad_training_checkpoint stores model weights and AdaGrad state for an exact training resume.

fn (Sequential[T]) save_nadam_training_checkpoint #

fn (nn &Sequential[T]) save_nadam_training_checkpoint(path string, epoch int, loss f64,
	optimizer &optimizers.NAdamOptimizer[T]) !

save_nadam_training_checkpoint stores model weights and complete NAdam state.

fn (Sequential[T]) save_radam_training_checkpoint #

fn (nn &Sequential[T]) save_radam_training_checkpoint(path string, epoch int, loss f64,
	optimizer &optimizers.RAdamOptimizer[T]) !

save_radam_training_checkpoint stores model weights and complete RAdam state.

fn (Sequential[T]) save_adamw_training_checkpoint #

fn (nn &Sequential[T]) save_adamw_training_checkpoint(path string, epoch int, loss f64,
	optimizer &optimizers.AdamWOptimizer[T]) !

save_adamw_training_checkpoint stores model weights and AdamW state for a resumable training checkpoint.

fn (Sequential[T]) load_training_checkpoint #

fn (mut nn Sequential[T]) load_training_checkpoint(path string,
	mut optimizer &optimizers.AdamOptimizer[T]) !(int, f64)

load_training_checkpoint restores model weights, training metadata, and Adam state. Build the optimizer with the destination model's parameters before calling this method.

fn (Sequential[T]) load_sgd_training_checkpoint #

fn (mut nn Sequential[T]) load_sgd_training_checkpoint(path string,
	mut optimizer &optimizers.SgdOptimizer[T]) !(int, f64)

load_sgd_training_checkpoint restores model weights, metadata, and SGD momentum state into an optimizer already built from the destination model.

fn (Sequential[T]) load_rmsprop_training_checkpoint #

fn (mut nn Sequential[T]) load_rmsprop_training_checkpoint(path string,
	mut optimizer &optimizers.RMSPropOptimizer[T]) !(int, f64)

load_rmsprop_training_checkpoint restores model weights, metadata, and RMSProp state into an optimizer already built from the destination model.

fn (Sequential[T]) load_adagrad_training_checkpoint #

fn (mut nn Sequential[T]) load_adagrad_training_checkpoint(path string,
	mut optimizer &optimizers.AdaGradOptimizer[T]) !(int, f64)

load_adagrad_training_checkpoint restores model weights, metadata, and AdaGrad state into an optimizer already built from the destination model.

fn (Sequential[T]) load_nadam_training_checkpoint #

fn (mut nn Sequential[T]) load_nadam_training_checkpoint(path string,
	mut optimizer &optimizers.NAdamOptimizer[T]) !(int, f64)

load_nadam_training_checkpoint restores model weights, metadata, and NAdam state.

fn (Sequential[T]) load_radam_training_checkpoint #

fn (mut nn Sequential[T]) load_radam_training_checkpoint(path string,
	mut optimizer &optimizers.RAdamOptimizer[T]) !(int, f64)

load_radam_training_checkpoint restores model weights, metadata, and RAdam state.

fn (Sequential[T]) load_adamw_training_checkpoint #

fn (mut nn Sequential[T]) load_adamw_training_checkpoint(path string,
	mut optimizer &optimizers.AdamWOptimizer[T]) !(int, f64)

load_adamw_training_checkpoint restores model weights, metadata, and AdamW state into an optimizer built from the destination model.

fn (Sequential[T]) load_weights #

fn (nn &Sequential[T]) load_weights(path string) !

load_weights restores weights into an existing model. The model's layers must already be constructed in the same order as when saved.

fn (Sequential[f32]) forward_vulkan_inference #

fn (mut nn Sequential[f32]) forward_vulkan_inference(input &autograd.Variable[f32]) !&autograd.Variable[f32]

forward_vulkan_inference falls back to the ordinary CPU-capable path without a Vulkan-enabled build.

enum MapLocation #

enum MapLocation {
	cpu
}

MapLocation is the supported checkpoint target. Device remapping is not available yet, so non-CPU locations must fail explicitly.

struct MigrationResult #

struct MigrationResult {
pub:
	from_version int
	to_version   int
	data         []u8
	applied      []string
}

MigrationResult describes an upgraded checkpoint payload.

struct ModelMetadata #

struct ModelMetadata {
pub:
	epoch    int
	loss     f64
	saved_at string
	version  string = model_version
}

ModelMetadata stores training metadata for checkpoints.

struct PortableManifest #

struct PortableManifest {
pub:
	format      string = portable_weights_format
	model       string = 'Sequential'
	dtype       string
	layer_types []string
pub mut:
	version string = portable_weights_version
	weights []PortableWeight
}

PortableManifest is the data-only manifest for a directory of .npy parameter files. It is intentionally independent of the VTL checkpoint format so Python/NumPy tooling can reconstruct the same weights.

struct PortableWeight #

struct PortableWeight {
pub:
	name  string
	file  string
	dtype string
pub mut:
	shape []int
}

PortableWeight describes one exported parameter file.

struct Sequential #

struct Sequential[T] {
pub mut:
	info     &SequentialInfo[T] = unsafe { nil }
	training bool               = true
}

Sequential defines a public data structure for this module.

struct SequentialInfo #

struct SequentialInfo[T] {
	ctx &autograd.Context[T] = unsafe { nil }
pub mut:
	layers        []types.Layer[T]
	layer_types   []string
	layer_configs []map[string]int
	loss          types.Loss[T]
}

SequentialInfo defines a public data structure for this module.

struct SerializationError #

struct SerializationError {
	msg string
}

SerializationError represents errors during model save/load operations.

fn (SerializationError) msg #

fn (e &SerializationError) msg() string

msg exposes this operation as part of the public API.