Functional Core #
Small functional helpers built from the primitive Runtime.Autograd.Torch.Ops API.
These definitions are shared by eager and typed graph execution, so they stay close to the primitive operation names: elementwise helpers, broadcasting, embedding lookup, reductions, and seeded RNG.
Elementwise helpers #
Elementwise square: $x\mapsto x^2$.
PyTorch analogue: torch.square.
Instances For
Elementwise transcendentals for scientific forward models #
Scientific forward models often use affine terms together with exp, log, sin, or cos.
These helpers expose the corresponding primitives through nn.functional, so the
forward equation can be written once as a pure function and differentiated
by the autograd engine. Each exported primitive has a registered backward
rule, so reverse-mode jacrev and grad work through the expression.
PyTorch analogues: torch.exp, torch.log, torch.sin, torch.cos, and c·x / c·x + k via
torch.mul/torch.add against scalars.
For real-valued reasoning, log requires positive inputs. The eager CPU tape and IR evaluator
reject nonpositive inputs; raw typed graph closures can panic, and CUDA uses the native operation.
Use safeLog when a model needs an epsilon-protected log-like operation.
Add a constant scalar $c$ to every element: $x\mapsto x+c$. Builds the
constant via Ops.const at scalar shape and broadcasts it to s (same pattern
as the dropout keep-probability broadcast).
Instances For
Scalar affine map $x\mapsto xc+k$.
This is a common building block in physical forward models, including the
SMAP-NISAR AVS surface and vegetation terms. It composes scale and shift.
Instances For
Detach #
Broadcasting helpers #
Avoid recording a broadcast node when the input already has the target shape.
Instances For
Broadcasting add: compute x + y after broadcasting both inputs to the target shape t.
PyTorch analogue: torch.add (broadcasting semantics).
Instances For
Broadcasting multiply: compute x * y after broadcasting both inputs to the target shape t.
PyTorch analogue: torch.mul (broadcasting semantics).
Instances For
Indexing helpers #
Embedding lookup for an arbitrary tensor of bounded token ids.
The indexing primitive operates on a flat vector of indices. This wrapper flattens any input shape,
selects the corresponding rows, and restores the original axes with the embedding dimension
appended. The element type Fin vocabularySize makes an out-of-range token unrepresentable.
Instances For
Reductions #
Mean over all elements, scaling the sum by the reciprocal of the element count.
An empty tensor uses denominator one and returns its zero sum, unlike PyTorch's NaN convention. The reciprocal is computed before multiplication; this need not round like direct division.
Instances For
Seeded RNG helpers #
Seeded dropout implemented as $x\odot\mathtt{mask}/\mathtt{keepProb}$, where
$\mathtt{mask}\in\{0,1\}$ is sampled from a
deterministic PRNG keyed by seed.
Instances For
Seeded dropout where the probability is supplied as a scalar tensor ref.
Model builders can store p as tensor data and pass it through the same interface as the input.
For finite inputs and 0 ≤ p ≤ 1, a retained entry is scaled by 1 / (1 - p) and a
dropped entry is zero.
The seeded mask is held fixed during differentiation.
The denominator is 1 - p * mask: it equals 1 - p at retained entries and 1 at dropped
entries. At p = 1, every entry is dropped, avoiding a reciprocal at zero. With finite
intermediates, the forward value and gradients are zero. Multiplying by a zero mask does not
suppress a NaN or infinity. Evaluation mode returns the input directly.