---
title: "ClikaRT::nn"
sidebar_label: "nn"
description: "Namespace ClikaRT::nn"
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--namespace">namespace</span>

## Namespaces

| Name | Description |
| --- | --- |
| [`ClikaRT::nn::fused`](./fused/index.md) |  |

## Classes

| Name | Description |
| --- | --- |
| [`AdaptiveAvgPool1d`](./AdaptiveAvgPool1d.md) | Average pooling to a fixed 1-D output size, the window derived per output position; the input is channels-last. The module form of [`ClikaRT::ops::adaptive_avg_pool1d`](../ops/adaptive_avg_pool1d.md#adaptive_avg_pool1d), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`AdaptiveAvgPool1dOptions`](./AdaptiveAvgPool1dOptions.md) | Settings of [`AdaptiveAvgPool1d`](./AdaptiveAvgPool1d.md): chain the setters, or assign the fields. |
| [`AdaptiveAvgPool2d`](./AdaptiveAvgPool2d.md) | Average pooling to a fixed 2-D output size, the window derived per output position; the input is channels-last. The module form of [`ClikaRT::ops::adaptive_avg_pool2d`](../ops/adaptive_avg_pool2d.md#adaptive_avg_pool2d), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`AdaptiveAvgPool2dOptions`](./AdaptiveAvgPool2dOptions.md) | Settings of [`AdaptiveAvgPool2d`](./AdaptiveAvgPool2d.md): chain the setters, or assign the fields. |
| [`AdaptiveAvgPool3d`](./AdaptiveAvgPool3d.md) | Average pooling to a fixed 3-D output size, the window derived per output position; the input is channels-last. The module form of [`ClikaRT::ops::adaptive_avg_pool3d`](../ops/adaptive_avg_pool3d.md#adaptive_avg_pool3d), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`AdaptiveAvgPool3dOptions`](./AdaptiveAvgPool3dOptions.md) | Settings of [`AdaptiveAvgPool3d`](./AdaptiveAvgPool3d.md): chain the setters, or assign the fields. |
| [`AdaptiveMaxPool1d`](./AdaptiveMaxPool1d.md) | Max pooling to a fixed 1-D output size, the window derived per output position; the input is channels-last. The module form of [`ClikaRT::ops::adaptive_max_pool1d`](../ops/adaptive_max_pool1d.md#adaptive_max_pool1d), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`AdaptiveMaxPool1dOptions`](./AdaptiveMaxPool1dOptions.md) | Settings of [`AdaptiveMaxPool1d`](./AdaptiveMaxPool1d.md): chain the setters, or assign the fields. |
| [`AdaptiveMaxPool2d`](./AdaptiveMaxPool2d.md) | Max pooling to a fixed 2-D output size, the window derived per output position; the input is channels-last. The module form of [`ClikaRT::ops::adaptive_max_pool2d`](../ops/adaptive_max_pool2d.md#adaptive_max_pool2d), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`AdaptiveMaxPool2dOptions`](./AdaptiveMaxPool2dOptions.md) | Settings of [`AdaptiveMaxPool2d`](./AdaptiveMaxPool2d.md): chain the setters, or assign the fields. |
| [`AdaptiveMaxPool3d`](./AdaptiveMaxPool3d.md) | Max pooling to a fixed 3-D output size, the window derived per output position; the input is channels-last. The module form of [`ClikaRT::ops::adaptive_max_pool3d`](../ops/adaptive_max_pool3d.md#adaptive_max_pool3d), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`AdaptiveMaxPool3dOptions`](./AdaptiveMaxPool3dOptions.md) | Settings of [`AdaptiveMaxPool3d`](./AdaptiveMaxPool3d.md): chain the setters, or assign the fields. |
| [`Add`](./Add.md) | Adds `other`, scaled by alpha, to `input` elementwise with broadcasting: input + alpha \* other, then the optional fused activation. The module form of [`ClikaRT::ops::add`](../ops/add.md#add), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`AddOptions`](./AddOptions.md) | Settings of [`Add`](./Add.md): chain the setters, or assign the fields. |
| [`Attention`](./Attention.md) | [Attention](./Attention.md) module: fixed settings, optional bound tensors, one fused call per [`forward`](./Attention.md#forward). The module form of [`ops::attention`](../ops/attention.md#attention). |
| [`AttentionOptions`](./AttentionOptions.md) | Settings of [`Attention`](./Attention.md): chain the setters, or assign the fields. The defaults are plain non-causal attention over head-split inputs. |
| [`AvgPool1d`](./AvgPool1d.md) | Average pooling over a 1-D window; the input is channels-last `[N, D1, C]`. The module form of [`ClikaRT::ops::avg_pool1d`](../ops/avg_pool1d.md#avg_pool1d), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`AvgPool1dOptions`](./AvgPool1dOptions.md) | Settings of [`AvgPool1d`](./AvgPool1d.md): chain the setters, or assign the fields. |
| [`AvgPool2d`](./AvgPool2d.md) | Average pooling over a 2-D window; the input is channels-last `[N, D1..D2, C]`. The module form of [`ClikaRT::ops::avg_pool2d`](../ops/avg_pool2d.md#avg_pool2d), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`AvgPool2dOptions`](./AvgPool2dOptions.md) | Settings of [`AvgPool2d`](./AvgPool2d.md): chain the setters, or assign the fields. |
| [`AvgPool3d`](./AvgPool3d.md) | Average pooling over a 3-D window; the input is channels-last `[N, D1..D3, C]`. The module form of [`ClikaRT::ops::avg_pool3d`](../ops/avg_pool3d.md#avg_pool3d), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`AvgPool3dOptions`](./AvgPool3dOptions.md) | Settings of [`AvgPool3d`](./AvgPool3d.md): chain the setters, or assign the fields. |
| [`BatchNorm`](./BatchNorm.md) | Batch normalization, inference form. |
| [`BatchNormOptions`](./BatchNormOptions.md) | Construction settings of [`BatchNorm`](./BatchNorm.md) beyond the channel count (a plain aggregate; assign the fields you need). |
| [`BCELoss`](./BCELoss.md) | Binary cross entropy between probabilities `input` and `target`. The module form of [`ClikaRT::ops::binary_cross_entropy`](../ops/binary_cross_entropy.md#binary_cross_entropy), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`BCELossOptions`](./BCELossOptions.md) | Settings of [`BCELoss`](./BCELoss.md): chain the setters, or assign the fields. |
| [`BCEWithLogitsLoss`](./BCEWithLogitsLoss.md) | Binary cross entropy over logits: the sigmoid fused with the loss in one stable pass. The module form of [`ClikaRT::ops::binary_cross_entropy_with_logits`](../ops/binary_cross_entropy_with_logits.md#binary_cross_entropy_with_logits), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`BCEWithLogitsLossOptions`](./BCEWithLogitsLossOptions.md) | Settings of [`BCEWithLogitsLoss`](./BCEWithLogitsLoss.md): chain the setters, or assign the fields. |
| [`CELU`](./CELU.md) | Continuously differentiable exponential linear unit: max(0, input) + min(0, alpha \* (exp(input / alpha) - 1)). The module form of [`ClikaRT::ops::celu`](../ops/celu.md#celu), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`CELUOptions`](./CELUOptions.md) | Settings of [`CELU`](./CELU.md): chain the setters, or assign the fields. |
| [`CircularPad`](./CircularPad.md) | Pads by wrapping around the axis. The module form of [`ClikaRT::ops::circular_pad`](../ops/circular_pad.md#circular_pad), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`CircularPadOptions`](./CircularPadOptions.md) | Settings of [`CircularPad`](./CircularPad.md): chain the setters, or assign the fields. |
| [`Clamp`](./Clamp.md) | Clamps every element of `input` into \[min\_val, max\_val\]; an unset bound leaves that side open. The module form of [`ClikaRT::ops::clamp`](../ops/clamp.md#clamp), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`ClampOptions`](./ClampOptions.md) | Settings of [`Clamp`](./Clamp.md): chain the setters, or assign the fields. |
| [`ConstantPad`](./ConstantPad.md) | Pads with a constant value. The module form of [`ClikaRT::ops::constant_pad`](../ops/constant_pad.md#constant_pad), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`ConstantPadOptions`](./ConstantPadOptions.md) | Settings of [`ConstantPad`](./ConstantPad.md): chain the setters, or assign the fields. |
| [`Conv`](./Conv.md) | N-dimensional convolution module (1-D/2-D/3-D by the weight's rank). |
| [`ConvTranspose`](./ConvTranspose.md) | N-dimensional transposed-convolution module (learnable upsampling). |
| [`CosineSimilarity`](./CosineSimilarity.md) | Cosine similarity of `x1` and `x2` along `dim`, with broadcasting. The module form of [`ClikaRT::ops::cosine_similarity`](../ops/cosine_similarity.md#cosine_similarity), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`CosineSimilarityOptions`](./CosineSimilarityOptions.md) | Settings of [`CosineSimilarity`](./CosineSimilarity.md): chain the setters, or assign the fields. |
| [`CrossEntropyLoss`](./CrossEntropyLoss.md) | Cross entropy over class logits with the class axis last: the log-softmax followed by the negative log-likelihood. The module form of [`ClikaRT::ops::cross_entropy`](../ops/cross_entropy.md#cross_entropy), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`CrossEntropyLossOptions`](./CrossEntropyLossOptions.md) | Settings of [`CrossEntropyLoss`](./CrossEntropyLoss.md): chain the setters, or assign the fields. |
| [`Div`](./Div.md) | Divides `input` by `other` elementwise with broadcasting, with an optional quotient rounding and fused activation. The module form of [`ClikaRT::ops::div`](../ops/div.md#div), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`DivOptions`](./DivOptions.md) | Settings of [`Div`](./Div.md): chain the setters, or assign the fields. |
| [`Dropout`](./Dropout.md) | The inference form of dropout: the input passes through unchanged. The runtime serves trained models, where dropout is disabled, so no element is dropped and nothing is rescaled; `p` is kept so the module reads and exports like the layer it stands for. |
| [`DropoutOptions`](./DropoutOptions.md) | Settings of [`Dropout`](./Dropout.md): chain the setter, or assign the field. |
| [`ELU`](./ELU.md) | Exponential linear unit: scale \* input for input \> 0, scale \* alpha \* (exp(input\_scale \* input) - 1) otherwise. The module form of [`ClikaRT::ops::elu`](../ops/elu.md#elu), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`ELUOptions`](./ELUOptions.md) | Settings of [`ELU`](./ELU.md): chain the setters, or assign the fields. |
| [`Embedding`](./Embedding.md) | Embedding-table module: gathers rows of its table by token index, the module form of [`ops::embedding`](../ops/embedding.md#embedding). |
| [`Flatten`](./Flatten.md) | Merges the inclusive dimension range `[start_dim, end_dim]` into one dimension; a view when the layout permits. The module form of [`ClikaRT::ops::flatten`](../ops/flatten.md#flatten), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`FlattenOptions`](./FlattenOptions.md) | Settings of [`Flatten`](./Flatten.md): chain the setters, or assign the fields. |
| [`Fold`](./Fold.md) | Sums sliding windows `[N, L, prod(kernel_size), C]` back into a channels- last image `[N, output_size.., C]`; overlapping windows add. The module form of [`ClikaRT::ops::fold`](../ops/fold.md#fold), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`FoldOptions`](./FoldOptions.md) | Settings of [`Fold`](./Fold.md): chain the setters, or assign the fields. |
| [`GeGLU`](./GeGLU.md) | [GeGLU](./GeGLU.md) over a concatenated \[\*, 2d\] gate-then-up input, emitting \[\*, d\]: gelu(gate) \* up. The module form of [`ClikaRT::ops::geglu`](../ops/geglu.md#geglu), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`GeGLUOptions`](./GeGLUOptions.md) | Settings of [`GeGLU`](./GeGLU.md): chain the setters, or assign the fields. |
| [`GELU`](./GELU.md) | Gaussian error linear unit: input \* Phi(input), the exact erf form by default or the tanh approximation. The module form of [`ClikaRT::ops::gelu`](../ops/gelu.md#gelu), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`GELUOptions`](./GELUOptions.md) | Settings of [`GELU`](./GELU.md): chain the setters, or assign the fields. |
| [`GLU`](./GLU.md) | Gated linear unit: splits the input in half along dim and multiplies the first half by the sigmoid of the second; the size of dim must be even and the output halves it. The module form of [`ClikaRT::ops::glu`](../ops/glu.md#glu), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`GLUOptions`](./GLUOptions.md) | Settings of [`GLU`](./GLU.md): chain the setters, or assign the fields. |
| [`GroupNorm`](./GroupNorm.md) | Group normalization. |
| [`GroupNormOptions`](./GroupNormOptions.md) | Construction settings of [`GroupNorm`](./GroupNorm.md) beyond the group and channel counts (a plain aggregate; assign the fields you need). |
| [`Hardshrink`](./Hardshrink.md) | Hard shrinkage: zeroes every element within \[-lambd, lambd\] and keeps the rest. The module form of [`ClikaRT::ops::hardshrink`](../ops/hardshrink.md#hardshrink), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`HardshrinkOptions`](./HardshrinkOptions.md) | Settings of [`Hardshrink`](./Hardshrink.md): chain the setters, or assign the fields. |
| [`Hardsigmoid`](./Hardsigmoid.md) | Piecewise-linear sigmoid approximation: clamp(input / 6 + 1 / 2, 0, 1). The module form of [`ClikaRT::ops::hardsigmoid`](../ops/hardsigmoid.md#hardsigmoid), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`HardsigmoidOptions`](./HardsigmoidOptions.md) | Settings of [`Hardsigmoid`](./Hardsigmoid.md): chain the setters, or assign the fields. |
| [`Hardswish`](./Hardswish.md) | Piecewise-linear swish approximation: input \* clamp(input / 6 + 1 / 2, 0, 1). The module form of [`ClikaRT::ops::hardswish`](../ops/hardswish.md#hardswish), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`HardswishOptions`](./HardswishOptions.md) | Settings of [`Hardswish`](./Hardswish.md): chain the setters, or assign the fields. |
| [`Hardtanh`](./Hardtanh.md) | Clamps every element to \[min\_val, max\_val\]. The module form of [`ClikaRT::ops::hardtanh`](../ops/hardtanh.md#hardtanh), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`HardtanhOptions`](./HardtanhOptions.md) | Settings of [`Hardtanh`](./Hardtanh.md): chain the setters, or assign the fields. |
| [`HookOutcome`](./HookOutcome.md) | What one call of a custom operator's `output_shapes` or `compute` reported back to the runtime: [`Status::Ok`](../../index.md#Status) with empty text on success, otherwise the status and text of the exception the hook raised. Plain data on purpose: an exception raised in application code is caught by the application's own C++ runtime (the entry points of `detail::ModuleHookTable`) and only this record crosses into the library. Not something a module author fills in by hand: the entry points in `detail::ModuleHookTable` produce it. |
| [`HuberLoss`](./HuberLoss.md) | Half the squared error below `delta`, a linear penalty above it, between `input` and `target`. The module form of [`ClikaRT::ops::huber_loss`](../ops/huber_loss.md#huber_loss), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`HuberLossOptions`](./HuberLossOptions.md) | Settings of [`HuberLoss`](./HuberLoss.md): chain the setters, or assign the fields. |
| [`Identity`](./Identity.md) | Returns its input unchanged: it keeps a slot in a container where a module is expected (a skipped normalization, a disabled projection) without changing the data flow. |
| [`IdentityOptions`](./IdentityOptions.md) | [`Identity`](./Identity.md) has no settings; the struct keeps every module in this header constructible the same way. |
| [`InitSpec`](./InitSpec.md) | How [`Module::init_weights`](./Module.md#init_weights) fills the storage-free slots of a tree (the parameters and buffers a config-built module declared from a [`FakeTensor`](../FakeTensor.md) spec), the way a model's weight initializer does before a checkpoint is bound, or when none is. |
| [`InstanceNorm`](./InstanceNorm.md) | Instance normalization. |
| [`InstanceNormOptions`](./InstanceNormOptions.md) | Construction settings of [`InstanceNorm`](./InstanceNorm.md) beyond the channel count (a plain aggregate; assign the fields you need). |
| [`KLDivLoss`](./KLDivLoss.md) | Kullback-Leibler divergence of `target` from `input`, where `input` holds log-probabilities. The module form of [`ClikaRT::ops::kl_div`](../ops/kl_div.md#kl_div), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`KLDivLossOptions`](./KLDivLossOptions.md) | Settings of [`KLDivLoss`](./KLDivLoss.md): chain the setters, or assign the fields. |
| [`KVCache`](./KVCache.md) | The serving-side KV cache: per-layer storage rows (attention K/V, conv windows, recurrent slabs) over a slot-indexed batch. |
| [`KVCacheConfig`](./KVCacheConfig.md) | Construction parameters shared by every cache strategy. [`num_kv_heads`](./KVCacheConfig.md#num_kv_heads) is the KV head count (grouped-query attention: KV heads ≤ query heads); the cache stores K/V as `[seq_len, `[`num_kv_heads`](./KVCacheConfig.md#num_kv_heads)`, `[`head_dim`](./KVCacheConfig.md#head_dim)`]` per (slot, layer). |
| [`KVCacheFootprint`](./KVCacheFootprint.md) | What [`KVCache::make`](./KVCache.md#make) allocates for a composition, by storage class, and the two figures a serving stack budgets beside them. Every device figure is the bytes the construction allocates for that class, read off the same per-row plan the cache builds its storage from (one law, never a second estimate); [`device_bytes_at_make()`](./KVCacheFootprint.md#device_bytes_at_make) is their sum. A serving stack sizes its pool against [`device_bytes_at_steady_state()`](./KVCacheFootprint.md#device_bytes_at_steady_state) plus [`snapshot_host_budget_bytes`](./KVCacheFootprint.md#snapshot_host_budget_bytes) on the host. |
| [`KVLayerSpec`](./KVLayerSpec.md) | One decoder layer's storage row, the per-layer entry of the spec vector [`KVCache::make`](./KVCache.md#make) consumes. Two orthogonal axes: [`Kind`](./KVLayerSpec.md#Kind) says WHAT the row stores, [`Layout`](./KVLayerSpec.md#Layout) says HOW a token-indexed row is laid out. |
| [`KVQuantSpec`](./KVQuantSpec.md) | Per-side KV quantization scheme (quantize-on-append). Three families:ELEMENT-CODED (block == KVBlockScheme::None, the default): the side stores CODE bytes at dtype (Int8 / UInt8 / Float8\_E4M3 / Float8\_E5M2) under the per-tensor scale (+ optional integer zero\_point; fp8 codes are scale-only; one there is rejected at construction). BLOCK-QUANTIZED (block set): the side stores packed blocks with inline scales (see KVBlockScheme); dtype / scale / zero\_point must stay at their defaults. PER-TOKEN (per\_token true): the online scheme; every appended row encodes with its own absmax-derived scale, stored in a scale plane the cache allocates beside its buffer. Element-coded over the symmetric byte codes (Int8 / Float8\_E4M3 / Float8\_E5M2); scale / zero\_point must stay at their defaults (the plane owns the scales), and block must stay None. Either way the scheme rides every tensor the cache hands out: the attention op encodes appended rows through it and decodes attended rows back. |
| [`L1Loss`](./L1Loss.md) | Mean absolute error between `input` and `target`. The module form of [`ClikaRT::ops::l1_loss`](../ops/l1_loss.md#l1_loss), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`L1LossOptions`](./L1LossOptions.md) | Settings of [`L1Loss`](./L1Loss.md): chain the setters, or assign the fields. |
| [`LayerNorm`](./LayerNorm.md) | Layer normalization module. |
| [`LeakyReLU`](./LeakyReLU.md) | [ReLU](./ReLU.md) with a small slope on the negative side: input for input \> 0, negative\_slope \* input otherwise. The module form of [`ClikaRT::ops::leaky_relu`](../ops/leaky_relu.md#leaky_relu), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`LeakyReLUOptions`](./LeakyReLUOptions.md) | Settings of [`LeakyReLU`](./LeakyReLU.md): chain the setters, or assign the fields. |
| [`Linear`](./Linear.md) | Affine transformation of the trailing dimension: $y = x W^\top + b$. |
| [`LinearOptions`](./LinearOptions.md) | Construction options: everything beyond the two feature counts. Every field is optional / defaulted; the defaults produce a plain packing [Linear](./Linear.md). |
| [`LoadOptions`](./LoadOptions.md) | Options for the `load_state_dict` overloads (a plain aggregate; assign the fields you need). The same options serve BOTH load paths (an in-memory [`NamedTensors`](../NamedTensors.md) dict and a lazy checkpoint container), so a model accounts its weight names identically whichever way it loads. [`strict`](./LoadOptions.md#strict) gates the completeness report; the allow-lists carve per-name exceptions out of it without turning the whole check off:allow\_missing: declared slot names the checkpoint may legitimately omit, e.g. a tied head's lm\_head.weight, absent from checkpoints that share it with the embedding and bound by weight-sharing instead. allow\_unexpected: checkpoint names no slot declares that are fine to leave unread, e.g. a checkpoint shipping a redundant copy of a tied head's weight. weight\_residency: a load-scope residency override. When set, every module in the tree that admits a residency choice adopts this value before the checkpoint binds, as if it had been constructed with it, so one load call pins the whole model's posture without touching the model's own construction defaults. A module whose class pins its residency keeps the pin, and so does a module whose weight is tied to another module's table; the load logs one summary line with how many modules adopted the override and how many kept their own residency. Packed on a weight whose layout cannot pack still refuses readably at bind. Absent (the default) changes nothing. pack\_on\_load: pack every bound weight during THIS load, so a serving process pays the one-time pack at load time instead of on its first forward. It is the same pack the first forward would run (once, thread-safe), driven through the tree's own pack hooks from the root, so a composite that fuses or folds at pack time does that work here too. The bind and the pack interleave per module: a module's own weights and its direct children's bind right before its pack hook runs, a weight a pack hook reads by name or enumerates binds at that read, and whatever no pack hook reached binds after the walk, so a load holds one module's raw weights beside its pack, never the whole model's. After it each packed weight has exactly one resident copy and still reads back through named\_parameters() / state\_dict(). Default off: the first forward packs. |
| [`LogSigmoid`](./LogSigmoid.md) | Logarithm of the sigmoid, computed stably: -softplus(-input). The module form of [`ClikaRT::ops::log_sigmoid`](../ops/log_sigmoid.md#log_sigmoid), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`LogSigmoidOptions`](./LogSigmoidOptions.md) | [`LogSigmoid`](./LogSigmoid.md) has no settings; the struct keeps every module in this header constructible the same way. |
| [`LogSoftmax`](./LogSoftmax.md) | Logarithm of the softmax along dim, computed stably in one pass. The module form of [`ClikaRT::ops::log_softmax`](../ops/log_softmax.md#log_softmax), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`LogSoftmaxOptions`](./LogSoftmaxOptions.md) | Settings of [`LogSoftmax`](./LogSoftmax.md): chain the setters, or assign the fields. |
| [`Maximum`](./Maximum.md) | Elementwise maximum of `input` and `other` with broadcasting; a NaN in either operand yields NaN. The module form of [`ClikaRT::ops::maximum`](../ops/maximum.md#maximum), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`MaximumOptions`](./MaximumOptions.md) | [`Maximum`](./Maximum.md) has no settings; the struct keeps every module in this header constructible the same way. |
| [`MaxPool1d`](./MaxPool1d.md) | Max pooling over a 1-D window; the input is channels-last `[N, D1, C]`. The module form of [`ClikaRT::ops::max_pool1d`](../ops/max_pool1d.md#max_pool1d), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`MaxPool1dOptions`](./MaxPool1dOptions.md) | Settings of [`MaxPool1d`](./MaxPool1d.md): chain the setters, or assign the fields. |
| [`MaxPool2d`](./MaxPool2d.md) | Max pooling over a 2-D window; the input is channels-last `[N, D1..D2, C]`. The module form of [`ClikaRT::ops::max_pool2d`](../ops/max_pool2d.md#max_pool2d), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`MaxPool2dOptions`](./MaxPool2dOptions.md) | Settings of [`MaxPool2d`](./MaxPool2d.md): chain the setters, or assign the fields. |
| [`MaxPool3d`](./MaxPool3d.md) | Max pooling over a 3-D window; the input is channels-last `[N, D1..D3, C]`. The module form of [`ClikaRT::ops::max_pool3d`](../ops/max_pool3d.md#max_pool3d), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`MaxPool3dOptions`](./MaxPool3dOptions.md) | Settings of [`MaxPool3d`](./MaxPool3d.md): chain the setters, or assign the fields. |
| [`Minimum`](./Minimum.md) | Elementwise minimum of `input` and `other` with broadcasting; a NaN in either operand yields NaN. The module form of [`ClikaRT::ops::minimum`](../ops/minimum.md#minimum), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`MinimumOptions`](./MinimumOptions.md) | [`Minimum`](./Minimum.md) has no settings; the struct keeps every module in this header constructible the same way. |
| [`Mish`](./Mish.md) | [Mish](./Mish.md) activation: input \* tanh(softplus(input)). The module form of [`ClikaRT::ops::mish`](../ops/mish.md#mish), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`MishOptions`](./MishOptions.md) | Settings of [`Mish`](./Mish.md): chain the setters, or assign the fields. |
| [`Module`](./Module.md) | Base class of every [ClikaRT](../../index.md) module: an ownership tree of parameters, buffers, and child modules. |
| [`ModuleDict`](./ModuleDict.md) | A named set of modules registered under their keys, in insertion order, so a checkpoint names their weights `heads.cls.weight`. A dict has no `forward` of its own: the owner looks a module up and calls it. |
| [`ModuleHooks`](./ModuleHooks.md) | The entry points a module captures when it is constructed, one per virtual the runtime invokes from its own frames (see [`Module::Module()`](./Module.md#Module-4) and `detail::ModuleHookTable`). A [`Result`](../Result.md)-returning hook reports a caught exception as the failed [`Result`](../Result.md); the others report it as a [`HookOutcome`](./HookOutcome.md). Filled by `Module()`; a module author never constructs one. |
| [`ModuleList`](./ModuleList.md) | An indexed list of modules registered under their positions (`"0"`, `"1"`, ...), so a checkpoint names their weights `layers.3.weight`. A list has no `forward` of its own: the owner iterates it. |
| [`MoE`](./MoE.md) | Dense mixture-of-experts module: a router picks top-k experts per token, each expert runs its gated FFN, and the outputs combine under the router weights. |
| [`MoeOptions`](./MoeOptions.md) | [MoE](./MoE.md) configuration beyond the required top-k. Every field is optional; the defaults are the runtime's (SoftmaxTopK routing, renormalized top-k weights, [SwiGLU](./SwiGLU.md) with the Interleaved gate‖up layout, erf gelu). |
| [`MSELoss`](./MSELoss.md) | Mean squared error between `input` and `target`. The module form of [`ClikaRT::ops::mse_loss`](../ops/mse_loss.md#mse_loss), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`MSELossOptions`](./MSELossOptions.md) | Settings of [`MSELoss`](./MSELoss.md): chain the setters, or assign the fields. |
| [`Mul`](./Mul.md) | Multiplies `input` by `other` elementwise with broadcasting, then the optional fused activation. The module form of [`ClikaRT::ops::mul`](../ops/mul.md#mul), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`MulOptions`](./MulOptions.md) | Settings of [`Mul`](./Mul.md): chain the setters, or assign the fields. |
| [`NLLLoss`](./NLLLoss.md) | Negative log-likelihood over log-probabilities with the class axis last. The module form of [`ClikaRT::ops::nll_loss`](../ops/nll_loss.md#nll_loss), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`NLLLossOptions`](./NLLLossOptions.md) | Settings of [`NLLLoss`](./NLLLoss.md): chain the setters, or assign the fields. |
| [`OutputQuant`](./OutputQuant.md) | Static output quantization for a [Linear](./Linear.md)'s product: requantize the output with [`scale`](./OutputQuant.md#scale) / [`zero_point`](./OutputQuant.md#zero_point) along [`axis`](./OutputQuant.md#axis), at [`out_dtype`](./OutputQuant.md#out_dtype). |
| [`PagedParams`](./PagedParams.md) | Shared block-pool geometry for the cache's paged rows. [`block_size`](./PagedParams.md#block_size) must be a power of two in \[16, 512\] (a kernel addressing contract); [`num_blocks`](./PagedParams.md#num_blocks) is the pool capacity; [`max_blocks_per_seq`](./PagedParams.md#max_blocks_per_seq) caps one sequence's block-table row. |
| [`PairwiseDistance`](./PairwiseDistance.md) | The p-norm of `x1 - x2 + eps` over the last axis, with broadcasting of the leading dimensions. The module form of [`ClikaRT::ops::pairwise_distance`](../ops/pairwise_distance.md#pairwise_distance), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`PairwiseDistanceOptions`](./PairwiseDistanceOptions.md) | Settings of [`PairwiseDistance`](./PairwiseDistance.md): chain the setters, or assign the fields. |
| [`PixelShuffle`](./PixelShuffle.md) | Moves channels into the spatial axes: `[N, H, W, C * r * r]` to `[N, H * r, W * r, C]` for the factor `r`. The module form of [`ClikaRT::ops::pixel_shuffle`](../ops/pixel_shuffle.md#pixel_shuffle), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`PixelShuffleOptions`](./PixelShuffleOptions.md) | Settings of [`PixelShuffle`](./PixelShuffle.md): chain the setters, or assign the fields. |
| [`PixelUnshuffle`](./PixelUnshuffle.md) | Moves spatial samples into the channels: `[N, H * r, W * r, C]` to `[N, H, W, C * r * r]` for the factor `r`. The module form of [`ClikaRT::ops::pixel_unshuffle`](../ops/pixel_unshuffle.md#pixel_unshuffle), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`PixelUnshuffleOptions`](./PixelUnshuffleOptions.md) | Settings of [`PixelUnshuffle`](./PixelUnshuffle.md): chain the setters, or assign the fields. |
| [`Pow`](./Pow.md) | Raises `input` to `exponent` elementwise with broadcasting. The module form of [`ClikaRT::ops::pow`](../ops/pow.md#pow), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`PowOptions`](./PowOptions.md) | [`Pow`](./Pow.md) has no settings; the struct keeps every module in this header constructible the same way. |
| [`PReLU`](./PReLU.md) | Parametric [ReLU](./ReLU.md). |
| [`PReLUOptions`](./PReLUOptions.md) | Construction settings of [`PReLU`](./PReLU.md) beyond the parameter count (a plain aggregate; assign the fields you need). |
| [`QConv`](./QConv.md) | Statically-quantized convolution module: quantized weight AND activation-quantized compute where the backend serves the scheme, [`Conv`](./Conv.md)'s static-quant sibling (construct with a [`QTensor`](../QTensor.md) weight). |
| [`QConvWoQ`](./QConvWoQ.md) | Weight-only-quantized convolution module: the weight rests quantized (a [`QTensor`](../QTensor.md)) and decodes inside the kernels; compute runs at the activation dtype, [`Conv`](./Conv.md)'s weight-only sibling. |
| [`QEmbedding`](./QEmbedding.md) | Quantized embedding-table module: gathers rows of a packed table by token index and decodes them to float. |
| [`QEmbeddingOptions`](./QEmbeddingOptions.md) | Settings of [`QEmbedding`](./QEmbedding.md): chain the setters, or assign the fields. |
| [`QLinear`](./QLinear.md) | Statically-quantized linear module: quantized weight AND activation-quantized compute where the backend serves the scheme, [`Linear`](./Linear.md)'s static-quant sibling (same forward surface). |
| [`QLinearWoQ`](./QLinearWoQ.md) | Weight-only-quantized linear module: the weight rests quantized (a [`QTensor`](../QTensor.md)) and decodes inside the matmul kernels; compute runs at the activation dtype, [`Linear`](./Linear.md)'s weight-only sibling (same forward surface). |
| [`QMoEWoQ`](./QMoEWoQ.md) | Weight-only-quantized mixture-of-experts module: the stacked `[E, ...]` expert weights rest quantized and decode inside the per-expert kernels, [`MoE`](./MoE.md)'s weight-only sibling (same routing surface and options). |
| [`ReflectionPad`](./ReflectionPad.md) | Pads by mirroring about the edge, without repeating the edge sample. The module form of [`ClikaRT::ops::reflect_pad`](../ops/reflect_pad.md#reflect_pad), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`ReflectionPadOptions`](./ReflectionPadOptions.md) | Settings of [`ReflectionPad`](./ReflectionPad.md): chain the setters, or assign the fields. |
| [`ReGLU`](./ReGLU.md) | [ReGLU](./ReGLU.md) over a concatenated \[\*, 2d\] gate-then-up input, emitting \[\*, d\]: relu(gate) \* up. The module form of [`ClikaRT::ops::reglu`](../ops/reglu.md#reglu), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`ReGLUOptions`](./ReGLUOptions.md) | [`ReGLU`](./ReGLU.md) has no settings; the struct keeps every module in this header constructible the same way. |
| [`ReLU`](./ReLU.md) | Rectified linear unit: max(0, input). The module form of [`ClikaRT::ops::relu`](../ops/relu.md#relu), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`ReLU6`](./ReLU6.md) | [ReLU](./ReLU.md) capped at 6: clamp(input, 0, 6). The module form of [`ClikaRT::ops::relu6`](../ops/relu6.md#relu6), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`ReLU6Options`](./ReLU6Options.md) | Settings of [`ReLU6`](./ReLU6.md): chain the setters, or assign the fields. |
| [`ReLUOptions`](./ReLUOptions.md) | Settings of [`ReLU`](./ReLU.md): chain the setters, or assign the fields. |
| [`ReplicationPad`](./ReplicationPad.md) | Pads by repeating the edge sample. The module form of [`ClikaRT::ops::replicate_pad`](../ops/replicate_pad.md#replicate_pad), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`ReplicationPadOptions`](./ReplicationPadOptions.md) | Settings of [`ReplicationPad`](./ReplicationPad.md): chain the setters, or assign the fields. |
| [`RMSNorm`](./RMSNorm.md) | Root-mean-square normalization module. |
| [`RotaryEmbedding`](./RotaryEmbedding.md) | Rotary position embedding module: the angle tables built once at [`make`](./RotaryEmbedding.md#make), the rotation applied per call. The module form of [`ops::rotary_embedding`](../ops/rotary_embedding.md#rotary_embedding). |
| [`RotaryEmbeddingOptions`](./RotaryEmbeddingOptions.md) | Settings of [`RotaryEmbedding`](./RotaryEmbedding.md): chain the setters, or assign the fields. The defaults are the plain rotary embedding of most decoder checkpoints: base 10000, no context scaling, half-split pairs. |
| [`SELU`](./SELU.md) | Scaled exponential linear unit: [ELU](./ELU.md) with the fixed self-normalizing constants (alpha about 1.6733, scale about 1.0507). The module form of [`ClikaRT::ops::selu`](../ops/selu.md#selu), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`SELUOptions`](./SELUOptions.md) | Settings of [`SELU`](./SELU.md): chain the setters, or assign the fields. |
| [`Sequential`](./Sequential.md) | Runs its steps in order, each fed the previous step's output. |
| [`Sigmoid`](./Sigmoid.md) | Logistic sigmoid: 1 / (1 + exp(-input)). The module form of [`ClikaRT::ops::sigmoid`](../ops/sigmoid.md#sigmoid), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`SigmoidOptions`](./SigmoidOptions.md) | [`Sigmoid`](./Sigmoid.md) has no settings; the struct keeps every module in this header constructible the same way. |
| [`SiLU`](./SiLU.md) | [Sigmoid](./Sigmoid.md) linear unit (swish): input \* sigmoid(input). The module form of [`ClikaRT::ops::silu`](../ops/silu.md#silu), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`SiLUOptions`](./SiLUOptions.md) | Settings of [`SiLU`](./SiLU.md): chain the setters, or assign the fields. |
| [`SmoothL1Loss`](./SmoothL1Loss.md) | Squared error below `beta`, absolute error above it, between `input` and `target`. The module form of [`ClikaRT::ops::smooth_l1_loss`](../ops/smooth_l1_loss.md#smooth_l1_loss), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`SmoothL1LossOptions`](./SmoothL1LossOptions.md) | Settings of [`SmoothL1Loss`](./SmoothL1Loss.md): chain the setters, or assign the fields. |
| [`Softmax`](./Softmax.md) | [Softmax](./Softmax.md) along dim, computed stably. The module form of [`ClikaRT::ops::softmax`](../ops/softmax.md#softmax), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`SoftmaxOptions`](./SoftmaxOptions.md) | Settings of [`Softmax`](./Softmax.md): chain the setters, or assign the fields. |
| [`Softmin`](./Softmin.md) | [Softmax](./Softmax.md) of the negated input along dim: small values weigh most. The module form of [`ClikaRT::ops::softmin`](../ops/softmin.md#softmin), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`SoftminOptions`](./SoftminOptions.md) | Settings of [`Softmin`](./Softmin.md): chain the setters, or assign the fields. |
| [`Softplus`](./Softplus.md) | Smooth [ReLU](./ReLU.md): log(1 + exp(beta \* input)) / beta, switching to the exact linear input where beta \* input exceeds threshold. The module form of [`ClikaRT::ops::softplus`](../ops/softplus.md#softplus), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`SoftplusOptions`](./SoftplusOptions.md) | Settings of [`Softplus`](./Softplus.md): chain the setters, or assign the fields. |
| [`Softshrink`](./Softshrink.md) | Soft thresholding: moves every element toward zero by lambd, to zero within \[-lambd, lambd\]. The module form of [`ClikaRT::ops::softshrink`](../ops/softshrink.md#softshrink), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`SoftshrinkOptions`](./SoftshrinkOptions.md) | Settings of [`Softshrink`](./Softshrink.md): chain the setters, or assign the fields. |
| [`Softsign`](./Softsign.md) | [Softsign](./Softsign.md) activation: input / (1 + \|input\|). The module form of [`ClikaRT::ops::softsign`](../ops/softsign.md#softsign), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`SoftsignOptions`](./SoftsignOptions.md) | [`Softsign`](./Softsign.md) has no settings; the struct keeps every module in this header constructible the same way. |
| [`Sub`](./Sub.md) | Subtracts `other`, scaled by alpha, from `input` elementwise with broadcasting: input - alpha \* other, then the optional fused activation. The module form of [`ClikaRT::ops::sub`](../ops/sub.md#sub), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`SubOptions`](./SubOptions.md) | Settings of [`Sub`](./Sub.md): chain the setters, or assign the fields. |
| [`SwiGLU`](./SwiGLU.md) | [SwiGLU](./SwiGLU.md) over a concatenated \[\*, 2d\] gate-then-up input, emitting \[\*, d\]: (clamp(up, -limit, limit) + beta) \* G \* sigmoid(alpha \* G) with G = min(gate, limit); the defaults reduce to silu(gate) \* up. The module form of [`ClikaRT::ops::swiglu`](../ops/swiglu.md#swiglu), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`SwiGLUOptions`](./SwiGLUOptions.md) | Settings of [`SwiGLU`](./SwiGLU.md): chain the setters, or assign the fields. |
| [`Tanh`](./Tanh.md) | Elementwise hyperbolic tangent. The module form of [`ClikaRT::ops::tanh`](../ops/tanh.md#tanh), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`TanhOptions`](./TanhOptions.md) | [`Tanh`](./Tanh.md) has no settings; the struct keeps every module in this header constructible the same way. |
| [`Threshold`](./Threshold.md) | Keeps every element above threshold and replaces the rest with value. The module form of [`ClikaRT::ops::threshold`](../ops/threshold.md#threshold), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`ThresholdOptions`](./ThresholdOptions.md) | Settings of [`Threshold`](./Threshold.md): chain the setters, or assign the fields. |
| [`Unflatten`](./Unflatten.md) | Splits the dimension `dim` into `sizes`, whose product must equal its extent; a view when the layout permits. The module form of [`ClikaRT::ops::unflatten`](../ops/unflatten.md#unflatten), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`UnflattenOptions`](./UnflattenOptions.md) | Settings of [`Unflatten`](./Unflatten.md): chain the setters, or assign the fields. |
| [`Unfold`](./Unfold.md) | Extracts sliding windows from a channels-last input `[N, D1..Dn, C]` into `[N, L, prod(kernel_size), C]`, one row per window placement. The module form of [`ClikaRT::ops::unfold`](../ops/unfold.md#unfold), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`UnfoldOptions`](./UnfoldOptions.md) | Settings of [`Unfold`](./Unfold.md): chain the setters, or assign the fields. |
| [`Upsample`](./Upsample.md) | Resamples the spatial dimensions to `size` or by `scale_factor` (exactly one given); the input is channels-last and its rank picks the spatial variant. The two settings share one type, so the module is constructed from its options: [`Upsample`](./Upsample.md)`(UpsampleOptions().scale_factor({2, 2}))`. The module form of [`ClikaRT::ops::interpolate`](../ops/interpolate.md#interpolate), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`UpsampleOptions`](./UpsampleOptions.md) | Settings of [`Upsample`](./Upsample.md): chain the setters, or assign the fields. |
| [`Where`](./Where.md) | Elementwise select with broadcasting: `input` where `condition` holds, `other` elsewhere. The module form of [`ClikaRT::ops::where`](../ops/where.md#where), which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`WhereOptions`](./WhereOptions.md) | [`Where`](./Where.md) has no settings; the struct keeps every module in this header constructible the same way. |
| [`ZeroPad`](./ZeroPad.md) | Pads with zeros. The module form of [`ClikaRT::ops::constant_pad`](../ops/constant_pad.md#constant_pad) with `value` fixed to `0.0`, which documents the full contract (shapes, dtypes, errors); construct once, then call it like a function. |
| [`ZeroPadOptions`](./ZeroPadOptions.md) | Settings of [`ZeroPad`](./ZeroPad.md): chain the setters, or assign the fields. |

## Enumerations

### enum KVBlockScheme {#KVBlockScheme}

<div class="api-signature">

`enum class` **`KVBlockScheme`** `:` `uint8_t`

</div>

Block-quantized KV storage selector: the block-wise online schemes whose scales ride INLINE in the cache's own block bytes (no external scale to supply; the append encodes each block as it writes). `Q8_0` stores 8-bit codes + one f16 scale per 32 elements (8.5 bits/element at rest); `NVFP4` stores 4-bit float codes + one UE4M3 sub-scale per 16 elements over 64-element blocks (4.5 bits/element at rest). `head_dim` must be a whole number of the scheme's blocks. The wider block-scheme taxonomy is reachable by name through [`KVCacheConfig::kv_cache_scheme`](./KVCacheConfig.md#kv_cache_scheme); this enum names only the common selections.

| Enumerator | Description |
| --- | --- |
| `None` | element-coded (the [`dtype`](../dtype/index.md)/`scale` fields below apply) |
| `Q8_0` | 32-element blocks, int8 codes, inline f16 scales |
| `NVFP4` | 64-element blocks, fp4 codes, inline per-16 UE4M3 sub-scales |

<div class="api-declared">

Declared in `ClikaRT/nn/kv_cache.h`, line 110

</div>

### enum KVCacheMode {#KVCacheMode}

<div class="api-signature">

`enum class` **`KVCacheMode`** `:` `uint8_t`

</div>

The cache's serving mode: what every [`KVLayerSpec::Layout::Auto`](./KVLayerSpec.md#Layout) row resolves to. A composition with no token-indexed rows serves identically under both (the mode describes the cache's token-indexed rows; a state-only stack has nothing to page).

| Enumerator | Description |
| --- | --- |
| `Continuous` | per-slot buffers (preallocated or grow-on-demand) |
| `Paged` | token-indexed rows share the cache's block pool |

<div class="api-declared">

Declared in `ClikaRT/nn/kv_cache.h`, line 152

</div>

### enum LinearKind {#LinearKind}

<div class="api-signature">

`enum class` **`LinearKind`** `:` `std::uint8_t`

</div>

The SERVING POSTURE of a Linear-family module: what the bound weight is and how `forward` serves it. Reported by [`Linear::kind()`](./Linear.md#kind); the runtime is built without RTTI, so this type tag is the one sanctioned runtime introspection. It names the posture, NOT the class identity: a plain [`Linear`](./Linear.md) reports `Dense` until a quantized checkpoint payload binds onto its declared slot, then `WeightQuantized`; the subclasses report their pinned posture constantly.

| Enumerator | Description |
| --- | --- |
| `Dense` | dense weight, dense matmul |
| `WeightQuantized` | quantized-at-rest weight, float activations |
| `StaticQuant` | quantized weight AND quantized activations ([QLinear](./QLinear.md)) |

<div class="api-declared">

Declared in `ClikaRT/nn/linear.h`, line 118

</div>

### enum WeightResidency {#WeightResidency}

<div class="api-signature">

`enum class` **`WeightResidency`** `:` `std::uint8_t`

</div>

How a bound weight lives at rest.

| Enumerator | Description |
| --- | --- |
| `Packed` | Pack once into the backend kernel layout; the pack is the resident copy. |
| `Borrowed` | Never pack a private copy; forward serves off the shared storage. A derived runtime form the call needs (e.g. a quantized weight's compute form) is retained once when it fits the device's free-memory budget, and rebuilt per call when it does not. |
| `Auto` | Pack only when the copy fits the device's free-memory budget. |
| `PerCall` | Never retain a derived runtime form on this module, the memory-pressure fallback made deterministic: forward serves off the shared storage and rebuilds any derived form per call, regardless of the free-memory budget. [Minimum](./Minimum.md) per-module retention at a per-call rebuild cost; the runtime may still serve repeated calls from its own bounded, process-wide working set, which this choice does not pin. |

<div class="api-declared">

Declared in `ClikaRT/nn/weight_residency.h`, line 15

</div>

## Variables

### kAutoPackMaxFreeFraction {#kAutoPackMaxFreeFraction}

<div class="api-signature">

`double` **`kAutoPackMaxFreeFraction`** `= 0.10`

</div>

`Auto` packs a weight when its pack stays at or under this share of the device's currently-free memory: small enough that downstream pool sizing (which claims its own fraction of what remains after load) barely notices, large enough to admit every real vocab-sized weight on a workstation card. A device that reports no free-memory figure resolves to Borrowed, never a blind pack. A dense weight tied to another module's table (`share_weight`) resolves to Borrowed whatever the budget says: its pack would keep a second resident copy of that table. The resolution is logged either way.

<div class="api-declared">

Declared in `ClikaRT/nn/linear.h`, line 109

</div>

## `ClikaRT/nn/attention.h` {#attention-h}

```cpp
#include <ClikaRT/nn/attention.h>
```

Multi-head attention as an `nn::Module` leaf over the runtime's fused attention. The settings (head split, causality, scale, soft-cap, sliding window) are fixed at `make`; the optional bound tensors, an attention mask, a learned per-head softmax sink and rotary tables, live in the module as registered slots and ride every `forward(query, key, value)` as inputs of the fused attention. The module holds no projection weights: the query / key / value projections and the output projection are `Linear` modules the caller composes around it. This class serves the dense form (every key and value passed per call). The cached form is the operator: `ops::group_query_attention_varlen` with a `KVCache` layer's `keys` / `values` bound as the past and the present rows appends the new keys and values in place and attends over the whole row, for the prefill and for every decode step alike ([`ClikaRT/nn/kv_cache.h`](./index.md#kv_cache-h)).

Held via `std::shared_ptr` (an `nn::Module` leaf); copy/move are pinned by the base.

## `ClikaRT/nn/batch_norm.h` {#batch_norm-h}

```cpp
#include <ClikaRT/nn/batch_norm.h>
```

`BatchNorm`: per-channel normalization with STORED statistics, the inference form of batch normalization over channels-last input (`[N, D1..Dn, C]`, the channel axis last), exposed as an `nn::Module` leaf. Unlike the stateless `ops::batch_norm` free function, a `BatchNorm` binds its `weight` / `bias` and its `running_mean` / `running_var` ONCE and reuses them every forward.

The lifecycle (uniform across the weight-bearing `nn` modules): `make(num_features, ...)` declares storage-free slots under their checkpoint names; `set_weights(...)` / `set_running_stats(...)` (positional) or `load_state_dict(...)` (a checkpoint, by dotted name) bind them; the FIRST `forward` builds (once, thread-safe); `LoadOptions::pack_on_load` pays the build at load time. The module holds each weight exactly once and never re-packs it, so `named_parameters()` / `named_buffers()` / `state_dict()` are complete before and after any forward.

Slots and their checkpoint names: parameters `weight` (scale) and `bias` (shift) when `affine`; buffers `running_mean`, `running_var` and `num_batches_tracked`. The counter is an Int64 scalar the normalization never reads: it is declared with the value 0 so a checkpoint written by torch binds strictly; a checkpoint without it loads with `LoadOptions::allow_missing = {"num_batches_tracked"}`.

Held via `std::shared_ptr` (an `nn::Module` leaf); copy/move are pinned by the base.

## `ClikaRT/nn/containers.h` {#containers-h}

```cpp
#include <ClikaRT/nn/containers.h>
```

Module containers and two stateless utility modules: `Sequential`, `ModuleList`, `ModuleDict`, `Identity`, `Dropout`. Header-only: a container holds no weights of its own, the children it registers enumerate under their dotted names (`0.weight`, `encoder.1.bias`), and every `forward` runs in the calling code, one child after the other.

The classes follow the shape of every stateless module: an options struct where there are settings, `forward_impl` returning a `Result`, and `forward` / `operator()` unwrapping it the way every public method does.

## `ClikaRT/nn/generated/activation.h` {#activation-h}

```cpp
#include <ClikaRT/nn/generated/activation.h>
```

Machine-generated; do not hand-edit. Regenerated with each release of the public surface.

Activation functions as modules: each class applies one nonlinearity to its input, elementwise or along one axis, with the settings fixed at construction.

Every class derives from `nn::Module`, keeps its settings in a `<Class>Options` struct (chainable setters; a single positional setting also constructs it implicitly) and runs one [`ClikaRT::ops`](../ops/index.md) function. `forward_impl` returns a `Result`; `forward` and `operator()` unwrap it the way every public method does. The modules hold no weights, so construct one where the model is built and call it every step.

A class with the `inplace` setting runs the function's in-place form while it is on: the result is written into the input, and the input is returned.

## `ClikaRT/nn/generated/distance.h` {#distance-h}

```cpp
#include <ClikaRT/nn/generated/distance.h>
```

Machine-generated; do not hand-edit. Regenerated with each release of the public surface.

Distances and similarities between two tensors as modules.

Every class derives from `nn::Module`, keeps its settings in a `<Class>Options` struct (chainable setters; a single positional setting also constructs it implicitly) and runs one [`ClikaRT::ops`](../ops/index.md) function. `forward_impl` returns a `Result`; `forward` and `operator()` unwrap it the way every public method does. The modules hold no weights, so construct one where the model is built and call it every step.

## `ClikaRT/nn/generated/elementwise.h` {#elementwise-h}

```cpp
#include <ClikaRT/nn/generated/elementwise.h>
```

Machine-generated; do not hand-edit. Regenerated with each release of the public surface.

Elementwise arithmetic as modules: each class combines its operands the way the matching [`ClikaRT::ops`](../ops/index.md) function does (broadcasting and type promotion included), with the settings fixed at construction.

Every class derives from `nn::Module`, keeps its settings in a `<Class>Options` struct (chainable setters; a single positional setting also constructs it implicitly) and runs one [`ClikaRT::ops`](../ops/index.md) function. `forward_impl` returns a `Result`; `forward` and `operator()` unwrap it the way every public method does. The modules hold no weights, so construct one where the model is built and call it every step.

## `ClikaRT/nn/generated/flatten.h` {#flatten-h}

```cpp
#include <ClikaRT/nn/generated/flatten.h>
```

Machine-generated; do not hand-edit. Regenerated with each release of the public surface.

Dimension merging and splitting as modules; the results are views when the layout permits.

Every class derives from `nn::Module`, keeps its settings in a `<Class>Options` struct (chainable setters; a single positional setting also constructs it implicitly) and runs one [`ClikaRT::ops`](../ops/index.md) function. `forward_impl` returns a `Result`; `forward` and `operator()` unwrap it the way every public method does. The modules hold no weights, so construct one where the model is built and call it every step.

## `ClikaRT/nn/generated/fold.h` {#fold-h}

```cpp
#include <ClikaRT/nn/generated/fold.h>
```

Machine-generated; do not hand-edit. Regenerated with each release of the public surface.

Sliding-window extraction (`Unfold`) and its inverse (`Fold`) as modules over channels-last input.

Every class derives from `nn::Module`, keeps its settings in a `<Class>Options` struct (chainable setters; a single positional setting also constructs it implicitly) and runs one [`ClikaRT::ops`](../ops/index.md) function. `forward_impl` returns a `Result`; `forward` and `operator()` unwrap it the way every public method does. The modules hold no weights, so construct one where the model is built and call it every step.

## `ClikaRT/nn/generated/loss.h` {#loss-h}

```cpp
#include <ClikaRT/nn/generated/loss.h>
```

Machine-generated; do not hand-edit. Regenerated with each release of the public surface.

Losses as modules: `forward(input, target)` with the reduction and the per-class weights fixed at construction.

Every class derives from `nn::Module`, keeps its settings in a `<Class>Options` struct (chainable setters; a single positional setting also constructs it implicitly) and runs one [`ClikaRT::ops`](../ops/index.md) function. `forward_impl` returns a `Result`; `forward` and `operator()` unwrap it the way every public method does. The modules hold no weights, so construct one where the model is built and call it every step.

## `ClikaRT/nn/generated/padding.h` {#padding-h}

```cpp
#include <ClikaRT/nn/generated/padding.h>
```

Machine-generated; do not hand-edit. Regenerated with each release of the public surface.

Padding as modules: the pad widths are `(low, high)` pairs in axis order, the first pair padding the leading axis; fewer pairs than the input rank pad the leading axes only, and a negative width crops.

Every class derives from `nn::Module`, keeps its settings in a `<Class>Options` struct (chainable setters; a single positional setting also constructs it implicitly) and runs one [`ClikaRT::ops`](../ops/index.md) function. `forward_impl` returns a `Result`; `forward` and `operator()` unwrap it the way every public method does. The modules hold no weights, so construct one where the model is built and call it every step.

## `ClikaRT/nn/generated/pixelshuffle.h` {#pixelshuffle-h}

```cpp
#include <ClikaRT/nn/generated/pixelshuffle.h>
```

Machine-generated; do not hand-edit. Regenerated with each release of the public surface.

Pixel shuffle as modules over channels-last input: channels move to and from the spatial axes by a fixed factor.

Every class derives from `nn::Module`, keeps its settings in a `<Class>Options` struct (chainable setters; a single positional setting also constructs it implicitly) and runs one [`ClikaRT::ops`](../ops/index.md) function. `forward_impl` returns a `Result`; `forward` and `operator()` unwrap it the way every public method does. The modules hold no weights, so construct one where the model is built and call it every step.

## `ClikaRT/nn/generated/pooling.h` {#pooling-h}

```cpp
#include <ClikaRT/nn/generated/pooling.h>
```

Machine-generated; do not hand-edit. Regenerated with each release of the public surface.

Pooling as modules over channels-last input (`[N, D1..Dn, C]`, the channel axis last): one class per window rank, the window geometry fixed at construction. A geometry list with one value broadcasts to every spatial dimension.

Every class derives from `nn::Module`, keeps its settings in a `<Class>Options` struct (chainable setters; a single positional setting also constructs it implicitly) and runs one [`ClikaRT::ops`](../ops/index.md) function. `forward_impl` returns a `Result`; `forward` and `operator()` unwrap it the way every public method does. The modules hold no weights, so construct one where the model is built and call it every step.

## `ClikaRT/nn/generated/upsampling.h` {#upsampling-h}

```cpp
#include <ClikaRT/nn/generated/upsampling.h>
```

Machine-generated; do not hand-edit. Regenerated with each release of the public surface.

Resampling as a module over channels-last input: the target size or the scale factors and the interpolation mode are fixed at construction.

Every class derives from `nn::Module`, keeps its settings in a `<Class>Options` struct (chainable setters; a single positional setting also constructs it implicitly) and runs one [`ClikaRT::ops`](../ops/index.md) function. `forward_impl` returns a `Result`; `forward` and `operator()` unwrap it the way every public method does. The modules hold no weights, so construct one where the model is built and call it every step.

## `ClikaRT/nn/group_norm.h` {#group_norm-h}

```cpp
#include <ClikaRT/nn/group_norm.h>
```

`GroupNorm`: normalization over groups of channels of channels-last input (`[N, D1..Dn, C]`, the channel axis last), exposed as an `nn::Module` leaf. The statistics come from the input itself, per `(sample, group)` over the group's channels and the spatial dimensions.

The lifecycle (uniform across the weight-bearing `nn` modules): `make(num_groups, num_channels, ...)` declares storage-free slots under their checkpoint names; `set_weights(...)` (positional) or `load_state_dict(...)` (a checkpoint, by dotted name) binds them; the FIRST `forward` builds (once, thread-safe); `LoadOptions::pack_on_load` pays the build at load time. The module holds each weight exactly once and never re-packs it, so `named_parameters()` / `state_dict()` are complete before and after any forward.

Held via `std::shared_ptr` (an `nn::Module` leaf); copy/move are pinned by the base.

## `ClikaRT/nn/instance_norm.h` {#instance_norm-h}

```cpp
#include <ClikaRT/nn/instance_norm.h>
```

`InstanceNorm`: normalization per `(sample, channel)` over the spatial dimensions of channels-last input (`[N, D1..Dn, C]`, the channel axis last), exposed as an `nn::Module` leaf. By default the statistics come from the input itself; a module made with `track_running_stats` folds stored `running_mean` / `running_var` instead (the inference form).

The lifecycle (uniform across the weight-bearing `nn` modules): `make(num_features, ...)` declares storage-free slots under their checkpoint names; `set_weights(...)` / `set_running_stats(...)` (positional) or `load_state_dict(...)` (a checkpoint, by dotted name) bind them; the FIRST `forward` builds (once, thread-safe); `LoadOptions::pack_on_load` pays the build at load time. The module holds each weight exactly once and never re-packs it, so `named_parameters()` / `named_buffers()` / `state_dict()` are complete before and after any forward.

Slots and their checkpoint names: parameters `weight` (scale) and `bias` (shift) when `affine`; buffers `running_mean`, `running_var` and the Int64 counter `num_batches_tracked` when `track_running_stats` (the counter is declared with the value 0 and never read; a checkpoint without it loads with `LoadOptions::allow_missing`).

Held via `std::shared_ptr` (an `nn::Module` leaf); copy/move are pinned by the base.

## `ClikaRT/nn/kv_cache.h` {#kv_cache-h}

```cpp
#include <ClikaRT/nn/kv_cache.h>
```

A key/value cache for autoregressive decoding, the public face of the runtime's `IKVCache`. It holds per-layer K/V history across decode steps so attention reads the whole context while each step only computes the new tokens. Bind a layer's `keys(l)`/`values(l)` straight into `ops::group_query_attention_varlen` as BOTH `past_key`/`past_value` AND `out_present_key`/`out_present_value`; the op then appends this step's post-RoPE K/V into the cache buffer IN PLACE (no realloc, no copy), which is the mechanism that makes per-token decode fast.

One cache serves every decoder composition through a per-layer spec vector, on two orthogonal axes:

- **Kind**, WHAT a row stores: token-indexed K/V (`AttentionKV`, full or windowed via `window`), or fixed-size serving state (`ConvState`, `RecurrentState`, `HybridState`: slot-resident slabs the recurrence ops bind directly; no token indexing, so layout does not apply).
- **Layout**, HOW a token-indexed row is laid out: `Continuous` (a per-slot buffer, preallocated or grow-on-demand) or `Paged` (blocks from the cache's shared pool, handed out by `reserve` / `prepare_step`). `Auto` (the default) follows the cache's serving `mode`, so one spec vector serves both serving shapes unchanged.

Construction is ONE call: `KVCache::make(config, layer_specs)`; the config carries the cache-wide defaults, the serving `mode`, and (when any row lays out paged) the shared pool geometry in `config.paged`. Move-only.

###  {#autotoc_md3_1s1}

#### Prefix caching (paged rows): the contract {#autotoc_md3}

A cache with paged rows can reuse the K/V of already-seen prompt prefixes, so a repeated prefix (a system prompt, a chat transcript resubmitted next turn) skips its prefill compute entirely. The rules:

- **Opt-in, per session.** Caching happens ONLY through two calls: `admit(slot, prompt_ids)` at session start (binds the longest already-cached prefix, and enrolls the prompt's own full blocks in the cache as they fill) and `retire(slot, full_ids)` at clean finish (keeps the session's blocks, generated tokens included, addressable for future admits). Skip both and the paged cache does no hashing and no caching, zero overhead.
- **Opt-out, two levels.** Per session: finish via `evict_batch` (the cancel/error path). It caches nothing NEW: the session's blocks that no hash names (the partial tail, its generated tokens) return to the pool. Its sealed prefix blocks (full prompt blocks an `admit` enrolled) are PARKED, not dropped: they stay addressable to a later `admit` of the same prompt, which reports them as cached tokens. A parked block is free capacity (reclaimed under pool pressure like any cached block). To drop every cached block, `reset` the cache. Entirely: never call `admit`/`retire`.
- **Memory-neutral.** The pool's footprint is fixed at construction (`num_blocks` × `block_size` × paged rows × heads × head\_dim × dtype); caching never allocates beyond it and never pins: a cached block is FREE memory that happens to retain its bytes, reclaimed least-recently-used the moment a live sequence needs a block. A cache entry can therefore disappear under pool pressure; `admit` reports fewer (or zero) cached tokens.
- **What it saves is prefill compute, not storage.** `admit` returns `num_cached`; forward only `prompt_ids[num_cached:]`. Concurrent sessions sharing a prefix also share the physical blocks (copy-on-write on divergence), which REDUCES live block usage.
- **State rows ride along.** On a cache mixing paged rows with state rows, `retire` snapshots each state row's block-boundary checkpoint keyed by the prefix content hash, and `admit` adopts a cached prefix only when a snapshot matches the hit length exactly; otherwise it binds nothing and returns 0 (shared K/V over the wrong recurrent state is never served).
- **Controls.** `num_blocks` bounds how much history can stay cached opportunistically (size it above the live working set to leave cache headroom); `block_size` sets hit granularity (a hit needs a full identical block; smaller blocks match finer, at more block-table rows); `retire` vs `evict_batch` decides per session what enters the cache.
- **Multimodal sessions declare their media boundary.** Sharing is keyed on token ids, and the K/V under a media placeholder comes from NON-token inputs (pixels, audio) the ids cannot identify, so a session whose prompt carries media passes its FIRST media position as `addressable_len` on `admit` AND `retire`. Caching then covers only the pure-text prefix before it: blocks at or past the boundary are never shared or kept, and text-only sessions (the default) pay nothing.

## `ClikaRT/nn/linear.h` {#linear-h}

```cpp
#include <ClikaRT/nn/linear.h>
```

`Linear`: the public face of the runtime's packed matmul family, exposed as an `nn::Module` leaf and the BASE of its posture hierarchy (`QLinearWoQ` pins a quantized-at-rest weight; `QLinear` adds static output quantization). Unlike the stateless `ops::matmul` / `ops::linear` free functions (which re-pack the weight on every call), a `Linear` binds its weight ONCE and packs it into the backend's kernel layout; every `forward` reuses that packed weight. This is the pack-once path that makes per-token decode fast; build one `Linear` per projection at load, reuse it every step.

Construction is ONE factory with two symmetric overloads, and the factory IS the posture dispatch:

- `make(weight[, bias][, options])`: construct FROM tensors: geometry, dtype and device all read off the weight; declared and bound in one call. The returned `shared_ptr<Linear>`'s dynamic type follows what was given: `options.output_quant` set ⇒ a `QLinear` (this wins even over a quantized weight; quantized weight + output requant IS the static-quant posture); else `weight.is_quantized()` ⇒ a `QLinearWoQ`; else a plain `Linear`. Model code holds the base pointer and never branches.
- `make(in_features, out_features[, options])`: declare-then-bind for checkpoint flows: storage-free `weight` / `bias` slots are declared under their canonical names (bias presence rides `options.bias`; placement rides `options.device`); `set_weights` (tensors in hand) or `load_state_dict` (by dotted name) binds them, and the first `forward` packs (once, thread-safe). `options.output_quant` set returns a `QLinear` here too. Otherwise the object is a plain `Linear` whose SERVING POSTURE follows the payload that later binds: a dense payload serves through the dense matmul, a quantized one through the weight-only-quantized matmul; `kind()` reports which. `LoadOptions::pack_on_load` pays the pack at load time instead of on the first forward.

Dtype: adoption over declaration. A declared slot ADOPTS the bound payload's dtype (a weight keeps its checkpoint dtype, never a cast at rest). Until a payload binds, an unpinned slot HAS no dtype: it enumerates through `named_parameters()` as `DataType::Undefined`. `LinearOptions::dtype` PINS a dtype instead: the slots declare at it and every bind casts the payload to it. `to(dtype)`, called before or after any bind, casts the slots and pins that dtype for every subsequent re-bind. One seam to know: a checkpoint RE-load (`load_state_dict` onto a module whose slot already holds a payload) re-binds at the slot's CURRENT dtype; re-bind through `set_weights` when adoption of the new payload's dtype is wanted.

Weight orientation: the canonical dense layout is the HuggingFace `[out_features, in_features]`. `set_weights` also accepts the transposed `[in_features, out_features]`, validated against the declared feature counts (the ambiguous square DENSE case is read as `[out, in]`).

A QUANTIZED payload states its own orientation, and every posture and entrance (`Linear`, `QLinear`, `QLinearWoQ`; `make(Tensor)`, `set_weights`, `load_state_dict`, `share_weight`) reads it by ONE law, in this order:

1. a declared group axis (a grouped scheme): groups ride the input features;
2. a per-channel scale axis: one scale per OUTPUT feature, so `quant_axis` 0 names an `[out, in]` payload and 1 an `[in, out]` one (a scale whose length fits only the other axis is refused);
3. an n-major-canonical scheme (the plane-addressed schemes): `[out, in]`. A payload none of these describe follows the declared feature counts (a non-square shape fits exactly one order; a block stream bound in the transposed `[out, in]` order is read as such and routed by the residency law); past the counts, a block stream (a `load_gguf` / MX / NVFP4 payload, the one carrying a `logical_shape`) reads in the loader's `[in, out]` order, and a plain code tensor from the tensor alone reads the dense contract, `[out, in]`, a square one included, the same reading a square dense weight takes. Ahead of every rung, a payload whose FACTORY fixes its orientation carries that statement on its own params (`make_quantized_fp8` adopts codes as `[in, out]`, `make_quantized_fp8_blocked` as the checkpoint's `[out, in]`), so a square fp8 payload binds right from the tensor alone; a caller holding a square `[in, out]` payload of any other kind states it through a per-channel scale axis along its output features. One thing is refused with a sentence at `make` / `set_weights` (never at the first forward): evidence that contradicts the declared counts. Held via `std::shared_ptr` (an `nn::Module` leaf); copy/move are pinned by the base.

## `ClikaRT/nn/module.h` {#module-h}

```cpp
#include <ClikaRT/nn/module.h>
```

[`ClikaRT::nn::Module`](./Module.md): the PyTorch-`nn.Module`-style base every model and layer subclasses. It is BOTH the parameter/submodule container (so `named_parameters()` produces the same canonical dotted names, in registration order, as PyTorch, i.e. the keys in a HuggingFace `model.safetensors`) AND the user-space custom-op seam: a leaf module overrides `output_shapes()` + `compute()` with its own kernel logic and calls `dispatch()`, which runs that kernel through the runtime (eager and tracing alike).

Authoring:

- Composite: subclass, `register_module(...)` / `register_parameter(...)` in the ctor, and define your own `forward(...)` (any signature) composing `ops::` / child modules.
- Leaf custom op: subclass, override `output_shapes()` + `compute()`, and have `forward(...)` call `this->dispatch({inputs...})`. Modules are held via `std::shared_ptr` (`register_module` stores one); a leaf that calls `dispatch()` must itself be owned by a `shared_ptr`.

## `ClikaRT/nn/moe.h` {#moe-h}

```cpp
#include <ClikaRT/nn/moe.h>
```

A bound, weight-packing Mixture-of-Experts block over DENSE expert weights, the public face of the runtime's fused MoE (router top-k selection + per-expert gated FFN + the weighted combine, in ONE op). Like `Linear` vs `ops::matmul`, a `MoE` binds its stacked expert weights ONCE and packs them into the backend's kernel layout; every `forward` reuses the pack. Build one per MoE layer at load, reuse it every step. Weight-only-QUANTIZED experts are the sibling module `QMoEWoQ` (exactly the `Linear` vs `QLinearWoQ` split).

The lifecycle (uniform across every weight-bearing `nn` module):

1. `make(experts, hidden, intermediate, top_k, options, ...)`, the ONE constructor: declares the storage-free expert / bias slots.
2. `set_weights(...)` or `load_state_dict(...)` binds them.
3. `forward(x, router_logits)` packs on first call (once, thread-safe), then serves; `LoadOptions::pack_on_load` pays the pack at load time.

The caller computes the per-token router logits itself (families differ in how: a plain projection, a normalized/scaled one) and hands them to `forward` beside the activations; routing (`MoeRouting`), the gated activation, and the gate‖up layout (`ops::fused::SwigluFusion`) are configuration.

Expert weights are stacked 3-D tensors (the HF "experts as one parameter" layout): `gate_up_experts` `[E, F·I, H]` (F=2 fused gate‖up, F=1 with a separate `gate_experts`) and `down_experts` `[E, H, I]`.

## `ClikaRT/nn/prelu.h` {#prelu-h}

```cpp
#include <ClikaRT/nn/prelu.h>
```

`PReLU`: the parametric ReLU, a ReLU whose negative-side slope is a learned weight (one slope for all channels, or one per channel), exposed as an `nn::Module` leaf. Unlike the stateless `ops::prelu` free function, a `PReLU` holds its `weight` and reuses it every forward.

The lifecycle: `make(num_parameters, ...)` declares the `weight` parameter `[num_parameters]` FILLED with `options.init`, so the module is usable at once; `set_weights(...)` (positional) or `load_state_dict(...)` (a checkpoint, by dotted name) replaces it; the FIRST `forward` builds (once, thread-safe); `LoadOptions::pack_on_load` pays the build at load time. The module holds the weight exactly once and never re-packs it, so `named_parameters()` / `state_dict()` are complete before and after any forward.

Held via `std::shared_ptr` (an `nn::Module` leaf); copy/move are pinned by the base.

## `ClikaRT/nn/qembedding.h` {#qembedding-h}

```cpp
#include <ClikaRT/nn/qembedding.h>
```

A quantized embedding table as an `nn::Module` leaf: the packed weight stays quantized at rest and every row decodes at gather. The module form of `ops::q_embedding`, with the weight owned by the module.

The weight is the `nn.Embedding` layout, slot `weight`, `[num_embeddings, embedding_dim]`, bound as a `QTensor` (the packed payload carrying its scheme; the scales and zero points ride the payload). The lifecycle is the one every weight-bearing `nn` module follows: `make(...)` declares the slot (or binds it, for the from-weight overload); `set_weights(...)` / `load_state_dict(...)` bind; the FIRST `forward` builds the lookup once (thread-safe) and hands the registry slot over to the packed form, which is the single resident copy; the slot then enumerates as its reconstruction, so `named_parameters()` and `state_dict()` stay total. `LoadOptions::pack_on_load` pays the build at load time.

Held via `std::shared_ptr` (an `nn::Module` leaf); copy/move are pinned by the base.

## `ClikaRT/nn/rotary_embedding.h` {#rotary_embedding-h}

```cpp
#include <ClikaRT/nn/rotary_embedding.h>
```

Rotary position embedding (RoPE) as an `nn::Module` leaf. The module owns the angle tables: `make(dim, max_positions, options)` builds the `cos` / `sin` planes once, through `ops::generate_rotary_cache`, and registers them as the buffers `cos` and `sin` (each `[max_positions, dim / 2]` Float32), so `named_buffers()`, `state_dict()` and `to(device)` all see them. `forward(input, position_ids)` rotates one tensor by position and `forward_qk(query, key, position_ids)` rotates the pair with one angle gather. One module serves every layer that shares the geometry.

Held via `std::shared_ptr` (an `nn::Module` leaf); copy/move are pinned by the base.

## `ClikaRT/nn/weight_residency.h` {#weight_residency-h}

```cpp
#include <ClikaRT/nn/weight_residency.h>
```

[`ClikaRT::nn::WeightResidency`](./index.md#WeightResidency): how a bound weight lives at rest. The load call decides it, through `nn::LoadOptions::weight_residency`; this enum is that option's type. A module picks its own posture only where its weight format leaves one choice (a shared-storage tie, a quantized pack), and the option overrides every posture a module leaves open.
