Class F
java.lang.Object
ai.beestream.jitnn.F
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHowembeddingBag(Tensor, int[], Tensor, F.BagMode)andsegmentReduce(Tensor, int[], F.BagMode)combine the rows of a bag.static enumHowpad(Tensor, int[], int[], F.PadMode, float)fills: a constant, the reflection without the edge, or the edge replicated.static enumHowpool(Tensor, F.PoolMode, int[], int[], int[], int[], boolean, boolean, float)combines a window.static enumHow a loss reduces its per-element values. -
Method Summary
Modifier and TypeMethodDescriptionstatic floatFraction of rows whose argmax equals the label; runs now and returns a host value.static TensoradaptiveAvgPool(Tensor x, int... out) Adaptive average pooling of x [N, C, ...] (1 to 3 spatial axes) to the given output sizes (PyTorch's bins).static TensoradaptiveMaxPool(Tensor x, int... out) Adaptive max pooling of x [N, C, ...] (1 to 3 spatial axes) to the given output sizes.static TensorattentionSoftmax(Tensor scores, float scale, boolean causal) softmax(scores * scale) over the last axis of attention scores [..., T, S], in one kernel;causal: query t sees keys 0 .. t, as PyTorch'sis_causal.static TensorAverage pooling of x [N, C, L], PyTorch's avg_pool1d; padding counts in the divisor, as PyTorch's default.static TensorAverage pooling of x [N, C, H, W] over square windows, PyTorch's avg_pool2d; padding counts in the divisor, as PyTorch's default.static TensorAverage pooling of x [N, C, D, H, W] over cubic windows, PyTorch's avg_pool3d; padding counts in the divisor.static TensorbatchNorm(Tensor x, Tensor runningMean, Tensor runningVar, Tensor weight, Tensor bias, boolean training, float momentum, float eps) Batch normalisation of an NCHW (or NC) tensor.static TensorbatchNormRelu(Tensor x, Tensor runningMean, Tensor runningVar, Tensor weight, Tensor bias, boolean training, float momentum, float eps) relu(batchNorm(...)), fused.static TensorbinaryCrossEntropy(Tensor p, Tensor target) Binary cross-entropy of probabilitiespin [0, 1] againsttarget, PyTorch semantics: the logs are clamped at -100, so p = 0 or 1 gives finite values and gradients.static TensorbinaryCrossEntropy(Tensor p, Tensor target, F.Reduction reduction) binaryCrossEntropy(Tensor, Tensor)reduced asreductionsays.static TensorbinaryCrossEntropyWithLogits(Tensor logits, Tensor target) Binary cross-entropy on logits, sigmoid folded in without overflow (PyTorch's BCEWithLogits).static TensorbinaryCrossEntropyWithLogits(Tensor logits, Tensor target, F.Reduction reduction) binaryCrossEntropyWithLogits(Tensor, Tensor)reduced asreductionsays.static TensorcenterCrop(Tensor x, int height, int width) The central height x width window of images [..., H, W] (torchvision's center_crop, top-left rounding down).static TensorcontrastiveLoss(Tensor a, Tensor b, Tensor similar, float margin, F.Reduction reduction) Contrastive loss (Hadsell et al., 2006) withsimilar1 for similar pairs and 0 for dissimilar ones: similar d^2 + (1 - similar) max(margin - d, 0)^2.static TensorConvolution over 1 to 3 spatial axes with a size per axis:padsholds the padding before every axis, then after every axis (ONNX's order), so it may be asymmetric.static Tensor1-D convolution of x [N, C, L] with weight [Cout, C, K]; bias may be null.static TensorGrouped 1-D convolution: weight [Cout, C / groups, K]; groups = C is depthwise.static Tensor2-D convolution (NCHW), square kernel; bias may be null.static Tensorconv2dRelu(Tensor x, Tensor weight, Tensor bias, int stride, int padding, int dilation, int groups) relu(conv2d(...)) with the bias and ReLU fused into the convolution's output.static Tensor3-D convolution of x [N, C, D, H, W] with weight [Cout, C, KD, KH, KW]; bias may be null.static TensorGrouped 3-D convolution: weight [Cout, C / groups, KD, KH, KW].static TensorconvTranspose2d(Tensor x, Tensor weight, Tensor bias, int stride, int padding, int outputPadding, int dilation, int groups) Transposed 2-D convolution (NCHW), PyTorch's conv_transpose2d: weight [Cin, Cout/groups, K, K], square kernel; bias may be null.static TensorcosineEmbeddingLoss(Tensor a, Tensor b, Tensor target, float margin, F.Reduction reduction) Cosine embedding loss: 1 - cos(a, b) for target 1, max(0, cos(a, b) - margin) for -1.static TensorcosineProximityLoss(Tensor input, Tensor target, F.Reduction reduction) Cosine proximity loss (DL4J, Keras): minus the cosine similarity along the last axis, reduced.static TensorcosineSimilarity(Tensor a, Tensor b, int axis, float eps) Cosine similarity alongaxis: a . b / (max(|a|, eps) max(|b|, eps)), PyTorch's cosine_similarity.static TensorcrossEntropy(Tensor logits, Tensor labels) Mean cross-entropy betweenlogits[N, C] and INT32 class labels [N] (fused kernels).static TensorctcLoss(Tensor logProbs, Tensor targets, int[] inputLengths, int[] targetLengths, int blank, F.Reduction reduction) CTC loss, PyTorch's ctc_loss: log-probabilities [T, B, C] (log_softmax over C), INT32 targets [B, L] padded, input and target lengths; blank indexblank.static TensordepthToSpace(Tensor x, int block, String mode) Moves blocks of channels into space: x [N, C, H, W] to [N, C / b^2, H b, W b].static Tensordequantize(Tensor q) A Q8_0 tensor back to FP32.static TensorInverted dropout with a fresh mask per step:seedis an INT32 [2] host tensor.static TensorRows ofweight[V, D] picked by the INT32index: shape index.shape + [D].static TensorAsembedding(Tensor, Tensor); rowpaddingIdxreceives no gradient.static TensorembeddingBag(Tensor indices, int[] offsets, Tensor weight, F.BagMode mode) EmbeddingBag (PyTorch's, 1-D input with offsets): the rows ofweightpicked by the INT32indices, combined per bag bymode.static TensorfakeQuantize(Tensor x, float scale, float lowest, int bits) Quantises x tobits(8 or 16) bits and back: clamp(round_half_even(x / scale), lowest, lowest + 2^bits - 1) * scale,lowestbeing the lowest code minus the zero point (ONNX QuantizeLinear followed by DequantizeLinear).static Tensorx reversed along each ofaxes(torch.flip).static TensorFolds columns back into an image, summing overlaps (torch fold, ONNX Col2Im); seeSpatial.fold.static TensorSlices of data picked by INT32 index rows indices [..., k] (ONNX GatherND, batch_dims 0); differentiable in data.static TensorgaussianKl(Tensor mu, Tensor logvar) KL divergence of N(mu, exp(logvar)) from N(0, 1), summed over every element: -0.5 * sum(1 + logvar - mu^2 - exp(logvar)), the VAE regulariser.static TensorMean over the spatial dimensions: [N, C, H, W] to [N, C].static TensorGloVe's weighted least squares (Pennington et al., 2014) over a batch of co-occurrences: mean of weight (wi . wj + bi + bj - logX)^2, with wi, wj [B, D] and the rest [B].static TensorGroupNorm (Wu and He) of x [N, C, ...] ingroupsgroups of channels: each (sample, group) normalised over its channels and positions, then a per-channel affine (weight and bias may be null, as PyTorch with affine=False).static Tensor[]One GRU layer over x [T, B, I] (time first), PyTorch's equations and gate order (r, z, n): wih [3H, I], whh [3H, H], biases [3H], h0 [B, H].static Tensor[]Asgru(Tensor, Tensor, Tensor, Tensor, Tensor, Tensor)for padded batches oflengths.static TensorhingeLoss(Tensor input, Tensor target, F.Reduction reduction) Hinge loss with targets in {-1, 1}: max(0, 1 - target * input), Keras's hinge (mean).static TensorhuberLoss(Tensor input, Tensor target, float delta, F.Reduction reduction) Huber loss with thresholddelta: 0.5 d^2 where |d| < delta, else delta (|d| - delta / 2), d = input - target (PyTorch's huber_loss).static TensorinstanceNorm(Tensor x, Tensor weight, Tensor bias, float eps) InstanceNorm: GroupNorm with one channel per group (affine when weight and bias are given).static Tensorinterpolate(Tensor x, int height, int width, boolean bilinear, boolean alignCorners) Resizes x [N, C, H, W] to [N, C, height, width], nearest or bilinear (PyTorch's interpolate with size).static Tensorl1Loss(Tensor input, Tensor target, F.Reduction reduction) Mean absolute error (L1), PyTorch's l1_loss.static TensorLayerNorm over the last axis: (x - mean) / sqrt(var + eps) * weight + bias (bias may be null).static Tensory = x W^T + b, with W stored [out, in] and b of shape [out] (b may be null); one fused GEMM. x may have any leading dimensions: [..., in] gives [..., out].static Tensory = x W^T + b with Q8_0 weights W [out, in]; the gradient reaches x, not W.static TensorlinearRelu(Tensor x, Tensor weight, Tensor bias) relu(x W^T + b), with the bias and ReLU fused into the GEMM epilogue.static TensorlocalResponseNorm(Tensor x, int size, float alpha, float beta, float k) Local response normalisation across channels, PyTorch's local_response_norm (k 1, alpha 1e-4, beta 0.75 by default).static TensorlogSigmoid(Tensor x) log sigmoid(x) = -softplus(-x), without overflow.static TensorlpNormalize(Tensor x, int p, int axis, float eps) x / max(||x||_p, eps) alongaxis, p = 1 or 2 (torch.nn.functional.normalize; ONNX LpNormalization with eps 0).static Tensor[]One LSTM layer over x [T, B, I] (time first), PyTorch's equations and gate order (i, f, g, o): wih [4H, I], whh [4H, H], biases [4H], h0 and c0 [B, H].static Tensor[]Aslstm(Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor)for padded batches: INT32lengths[B] (null: all T); outputs past a sequence's length are 0 and h_n, c_n are each sequence's last valid state.static TensormapeLoss(Tensor input, Tensor target, F.Reduction reduction) Mean absolute percentage error: 100 |target - input| / max(|target|, eps) (Keras's MAPE, eps 1e-7).static TensormarginRankingLoss(Tensor x1, Tensor x2, Tensor target, float margin, F.Reduction reduction) Margin ranking loss: max(0, -target (x1 - x2) + margin), target 1 or -1.static TensorMax pooling of x [N, C, L] over windows ofkernelwith the given stride and padding (padding never wins), PyTorch's max_pool1d.static TensorMax pooling of x [N, C, H, W] over square windows ofkernelwith the given stride and padding, PyTorch's max_pool2d.static TensorMax pooling of x [N, C, D, H, W] over cubic windows ofkernel(padding never wins), PyTorch's max_pool3d.static TensorMean squared error betweeninputandtarget(same shape).static TensormseLoss(Tensor input, Tensor target, F.Reduction reduction) Squared error betweeninputandtarget(same shape), reduced asreductionsays.static TensormsleLoss(Tensor input, Tensor target, F.Reduction reduction) Mean squared logarithmic error: (log1p(input) - log1p(target))^2 (Keras's MSLE).static TensormultiHeadAttention(Tensor x, Tensor wqkv, Tensor bqkv, Tensor wout, Tensor bout, int heads, Tensor mask, boolean causal) Multi-head self-attention on x [B, T, D], as PyTorch'snn.MultiheadAttentionwith batch_first: q, k, v = split(x Wqkv^T + bqkv),headsheads, then the output projection.static Tensormultinomial(Tensor weights, Tensor seed, int stream) One INT32 index per row of non-negative weights [..., V] (probabilities, or any unnormalised weights), drawn in proportion to the weight.static TensornegativeSamplingLoss(Tensor hidden, Tensor target, Tensor negatives) Negative-sampling loss of word2vec (Mikolov et al., 2013): hidden [B, D] (the centre word, or the averaged context), target [B, D] (the output vector of the true word) and negatives [B, K, D] (output vectors of sampled words); mean over B of -log sigmoid(h . t) - sum_k log sigmoid(-h . n_k).static TensorPer-sample negative log-likelihood of INT32labelsunder log-probabilitieslogp.static TensornllLoss(Tensor logp, Tensor labels, F.Reduction reduction) Negative log-likelihood of INT32 labels under log-probabilities [N, C], reduced.static Tensortorch.nonzero_static: INT32 coordinates [size, rank] of the firstsizenon-zero elements, the rest of the rowsfill.static TensornormalizeImage(Tensor x, float[] mean, float[] std) Normalises images x [N, C, H, W] per channel: (x - mean[c]) / std[c], as torchvision's Normalize.static TensorINT32 labels [...] to a one-hot [..., classes].static TensorPads the spatial axes of x [N, C, ...]:before[k]andafter[k]elements on spatial axis k, PyTorch's F.pad for constant, reflect and replicate modes.static TensorpairwiseDistance(Tensor a, Tensor b) Euclidean distance of each row pair (last axis), PyTorch's pairwise_distance with eps 1e-6.static TensorpoissonNllLoss(Tensor input, Tensor target, boolean logInput, float eps, F.Reduction reduction) Poisson negative log-likelihood, PyTorch's poisson_nll_loss without the Stirling term: exp(input) - target input withlogInput, else input - target log(input + eps).static Tensorpool(Tensor x, F.PoolMode mode, int[] kernel, int[] stride, int[] pads, int[] dilation, boolean ceil, boolean countIncludePad, float p) Pooling over 1 to 3 spatial axes of x [N, C, ...] with a size per axis, as ONNX's MaxPool, AveragePool and LpPool and PyTorch's pooling layers:padsholds the padding before every axis, then after every axis;ceilrounds the output size up (a window must still start inside the input or its leading padding); average pooling counts the padding whencountIncludePad(never the positions added byceil); LP pooling computes (sum |x|^p)^(1/p).static TensorPReLU: x where x > 0, else a x, with a learnable slopeweightof one element or one per channel (axis 1 of x, as PyTorch).static TensorquantizeQ8(Tensor x) FP32 x (last axis a multiple of 32) quantised to Q8_0, GGUF's 8-bit block format.static TensorreverseSequences(Tensor x, int[] lengths) x [T, B, ...] with each sequence reversed within its length (padding left in place), as a bidirectional layer reads it; lengths null reverses the whole time axis.static TensorRGB images [N, 3, H, W] to luminance [N, 1, H, W] with torchvision's weights (0.2989, 0.587, 0.114).static TensorRMSNorm over the last axis: x / sqrt(mean(x^2) + eps) * weight.static TensorRotary position embedding of x [..., T, D] at positions offset .. offset + T - 1, frequency base^(-2i / D) for pair i.static TensorRotary position embedding of x [..., T, H, D] (the heads of a token share its position); seerope(Tensor, float, int, boolean).static TensorropeHeads(Tensor x, float base, RopeScaling scaling, int offset, boolean interleaved) ropeHeads(Tensor, float, int, boolean)with the frequencies rescaled for longer contexts (Llama 3.1's rope_scaling; null for none).static TensorRReLU (Xu et al., 2015): in training, a slope drawn uniformly from [lower, upper) for every element, seeded by the INT32 [2]seedtensor (seeTensor.seed(long)); in evaluation the mean slope (lower + upper) / 2.static TensorscaledDotProductAttention(Tensor q, Tensor k, Tensor v, Tensor mask, boolean causal, float scale) Scaled dot-product attention, PyTorch semantics: softmax(q k^T * scale + mask) v, for q [..., T, E], k [..., S, E], v [..., S, Ev].static TensorscaledDotProductAttentionBTHD(Tensor q, Tensor k, Tensor v, Tensor mask, boolean causal, float scale) Scaled dot-product attention on q [B, T, H, E], k and v [B, S, H, E] (heads after tokens, as the projections produce them), returning [B, T, H, E]; otherwise asscaledDotProductAttention(Tensor, Tensor, Tensor, Tensor, boolean, float).static TensorA copy of data with the update slices written ("none"), added ("add") or multiplied ("mul") at the INT32 index rows indices [..., k] (ONNX ScatterND); differentiable for none and add.static TensorsegmentReduce(Tensor x, int[] offsets, F.BagMode mode) Sum, mean or max of the row segments of x [rows, D]: segment b covers rows offsets[b] .. offsets[b + 1] - 1, the last to the end; an empty segment gives zeros.static TensorsmoothL1Loss(Tensor input, Tensor target, float beta, F.Reduction reduction) Smooth L1 loss, PyTorch's smooth_l1_loss: Huber with delta = beta, divided by beta.static TensorspaceToDepth(Tensor x, int block) Moves blocks of space into channels: x [N, C, H, W] to [N, C b^2, H / b, W / b] (ONNX SpaceToDepth; inverse of DCR depthToSpace).static TensorSparsemax (Martins and Astudillo, 2016) along the last axis: the Euclidean projection onto the probability simplex, max(x - tau, 0) with tau set by the sorted support.static TensorsquaredHingeLoss(Tensor input, Tensor target, F.Reduction reduction) Squared hinge loss: max(0, 1 - target * input)^2.static TensorSwiGLU gating, silu(gate) * up, as in the Llama feed-forward block.static TensortripletMarginLoss(Tensor anchor, Tensor positive, Tensor negative, float margin, F.Reduction reduction) Triplet margin loss: max(d(anchor, positive) - d(anchor, negative) + margin, 0).static Tensor[]torch.unique (sorted): the distinct values of x, then (when asked for, else null) the INT32 index of each element's value among them, shaped like x, and the INT32 count of each value.static TensorupsampleBilinear(Tensor x, float scale, boolean alignCorners) Bilinear upsampling of x [N, C, H, W] byscale.static TensorupsampleNearest(Tensor x, float scale) Nearest-neighbour upsampling of x [N, C, H, W] byscale(PyTorch's mode='nearest').static TensorweightNorm(Tensor v, Tensor g) Weight normalisation (Salimans and Kingma): w = g v / ||v|| with the norm over every axis but 0, g of shape [out] (PyTorch's weight_norm with dim 0).static Tensorcond !
-
Method Details
-
linear
-
linearRelu
-
nll
-
crossEntropy
-
conv2d
-
conv2dRelu
-
batchNorm
public static Tensor batchNorm(Tensor x, Tensor runningMean, Tensor runningVar, Tensor weight, Tensor bias, boolean training, float momentum, float eps) Batch normalisation of an NCHW (or NC) tensor. In training it uses the batch statistics and updatesrunningMean/runningVar(persistent tensors) in place. -
batchNormRelu
-
convTranspose2d
-
upsampleNearest
-
upsampleBilinear
-
interpolate
-
conv1d
-
conv1d
-
conv3d
-
conv3d
-
conv
public static Tensor conv(Tensor x, Tensor weight, Tensor bias, int[] stride, int[] pads, int[] dilation, int groups) Convolution over 1 to 3 spatial axes with a size per axis:padsholds the padding before every axis, then after every axis (ONNX's order), so it may be asymmetric. Square symmetric 2-D cases takeconv2d(Tensor, Tensor, Tensor, int, int, int, int)'s kernels; the rest the unfold (im2col) path. -
pool
public static Tensor pool(Tensor x, F.PoolMode mode, int[] kernel, int[] stride, int[] pads, int[] dilation, boolean ceil, boolean countIncludePad, float p) Pooling over 1 to 3 spatial axes of x [N, C, ...] with a size per axis, as ONNX's MaxPool, AveragePool and LpPool and PyTorch's pooling layers:padsholds the padding before every axis, then after every axis;ceilrounds the output size up (a window must still start inside the input or its leading padding); average pooling counts the padding whencountIncludePad(never the positions added byceil); LP pooling computes (sum |x|^p)^(1/p). -
maxPool1d
-
avgPool1d
-
maxPool3d
-
avgPool3d
-
adaptiveAvgPool
-
adaptiveMaxPool
-
pad
-
maxPool2d
-
avgPool2d
-
globalAvgPool2d
-
dropout
-
layerNorm
-
groupNorm
GroupNorm (Wu and He) of x [N, C, ...] ingroupsgroups of channels: each (sample, group) normalised over its channels and positions, then a per-channel affine (weight and bias may be null, as PyTorch with affine=False). -
instanceNorm
-
localResponseNorm
-
weightNorm
-
rmsNorm
-
embedding
-
embedding
Asembedding(Tensor, Tensor); rowpaddingIdxreceives no gradient. -
attentionSoftmax
-
fakeQuantize
-
scaledDotProductAttention
public static Tensor scaledDotProductAttention(Tensor q, Tensor k, Tensor v, Tensor mask, boolean causal, float scale) Scaled dot-product attention, PyTorch semantics: softmax(q k^T * scale + mask) v, for q [..., T, E], k [..., S, E], v [..., S, Ev].maskis an additive mask broadcast to [..., T, S] (0 to keep, a large negative number to drop), or null;causallets query t see keys 0 .. t (PyTorch's is_causal). A negativescalemeans 1 / sqrt(E). -
multiHeadAttention
public static Tensor multiHeadAttention(Tensor x, Tensor wqkv, Tensor bqkv, Tensor wout, Tensor bout, int heads, Tensor mask, boolean causal) Multi-head self-attention on x [B, T, D], as PyTorch'snn.MultiheadAttentionwith batch_first: q, k, v = split(x Wqkv^T + bqkv),headsheads, then the output projection. Wqkv is [3D, D] (rows q, then k, then v), Wout [D, D]; biases may be null. -
scaledDotProductAttentionBTHD
public static Tensor scaledDotProductAttentionBTHD(Tensor q, Tensor k, Tensor v, Tensor mask, boolean causal, float scale) Scaled dot-product attention on q [B, T, H, E], k and v [B, S, H, E] (heads after tokens, as the projections produce them), returning [B, T, H, E]; otherwise asscaledDotProductAttention(Tensor, Tensor, Tensor, Tensor, boolean, float). The fused kernels read this layout directly. -
ropeHeads
Rotary position embedding of x [..., T, H, D] (the heads of a token share its position); seerope(Tensor, float, int, boolean). -
ropeHeads
public static Tensor ropeHeads(Tensor x, float base, RopeScaling scaling, int offset, boolean interleaved) ropeHeads(Tensor, float, int, boolean)with the frequencies rescaled for longer contexts (Llama 3.1's rope_scaling; null for none). -
rope
Rotary position embedding of x [..., T, D] at positions offset .. offset + T - 1, frequency base^(-2i / D) for pair i.interleavedpairs (2i, 2i + 1) as GPT-J and Meta's Llama code; otherwise (i, i + D/2), the rotate-half form of Hugging Face's Llama. -
multinomial
-
mseLoss
-
mseLoss
Squared error betweeninputandtarget(same shape), reduced asreductionsays. -
binaryCrossEntropy
-
binaryCrossEntropy
binaryCrossEntropy(Tensor, Tensor)reduced asreductionsays. -
binaryCrossEntropyWithLogits
-
binaryCrossEntropyWithLogits
public static Tensor binaryCrossEntropyWithLogits(Tensor logits, Tensor target, F.Reduction reduction) binaryCrossEntropyWithLogits(Tensor, Tensor)reduced asreductionsays. -
l1Loss
Mean absolute error (L1), PyTorch's l1_loss. -
huberLoss
Huber loss with thresholddelta: 0.5 d^2 where |d| < delta, else delta (|d| - delta / 2), d = input - target (PyTorch's huber_loss). -
smoothL1Loss
Smooth L1 loss, PyTorch's smooth_l1_loss: Huber with delta = beta, divided by beta. -
nllLoss
Negative log-likelihood of INT32 labels under log-probabilities [N, C], reduced. -
hingeLoss
Hinge loss with targets in {-1, 1}: max(0, 1 - target * input), Keras's hinge (mean). -
squaredHingeLoss
Squared hinge loss: max(0, 1 - target * input)^2. -
cosineSimilarity
-
cosineProximityLoss
Cosine proximity loss (DL4J, Keras): minus the cosine similarity along the last axis, reduced. -
poissonNllLoss
public static Tensor poissonNllLoss(Tensor input, Tensor target, boolean logInput, float eps, F.Reduction reduction) Poisson negative log-likelihood, PyTorch's poisson_nll_loss without the Stirling term: exp(input) - target input withlogInput, else input - target log(input + eps). -
ctcLoss
public static Tensor ctcLoss(Tensor logProbs, Tensor targets, int[] inputLengths, int[] targetLengths, int blank, F.Reduction reduction) CTC loss, PyTorch's ctc_loss: log-probabilities [T, B, C] (log_softmax over C), INT32 targets [B, L] padded, input and target lengths; blank indexblank. MEAN divides each sample's loss by its target length, then averages (PyTorch's default). -
nonzero
torch.nonzero_static: INT32 coordinates [size, rank] of the firstsizenon-zero elements, the rest of the rowsfill. UnlikeTensor.nonzero()it needs no host read, so it stays inside a compiled plan. -
unique
-
logSigmoid
-
negativeSamplingLoss
Negative-sampling loss of word2vec (Mikolov et al., 2013): hidden [B, D] (the centre word, or the averaged context), target [B, D] (the output vector of the true word) and negatives [B, K, D] (output vectors of sampled words); mean over B of -log sigmoid(h . t) - sum_k log sigmoid(-h . n_k). -
gloveLoss
-
pairwiseDistance
-
tripletMarginLoss
public static Tensor tripletMarginLoss(Tensor anchor, Tensor positive, Tensor negative, float margin, F.Reduction reduction) Triplet margin loss: max(d(anchor, positive) - d(anchor, negative) + margin, 0). -
contrastiveLoss
public static Tensor contrastiveLoss(Tensor a, Tensor b, Tensor similar, float margin, F.Reduction reduction) Contrastive loss (Hadsell et al., 2006) withsimilar1 for similar pairs and 0 for dissimilar ones: similar d^2 + (1 - similar) max(margin - d, 0)^2. -
cosineEmbeddingLoss
public static Tensor cosineEmbeddingLoss(Tensor a, Tensor b, Tensor target, float margin, F.Reduction reduction) Cosine embedding loss: 1 - cos(a, b) for target 1, max(0, cos(a, b) - margin) for -1. -
marginRankingLoss
public static Tensor marginRankingLoss(Tensor x1, Tensor x2, Tensor target, float margin, F.Reduction reduction) Margin ranking loss: max(0, -target (x1 - x2) + margin), target 1 or -1. -
sparsemax
-
msleLoss
Mean squared logarithmic error: (log1p(input) - log1p(target))^2 (Keras's MSLE). -
mapeLoss
Mean absolute percentage error: 100 |target - input| / max(|target|, eps) (Keras's MAPE, eps 1e-7). -
gaussianKl
-
lstm
public static Tensor[] lstm(Tensor x, Tensor wih, Tensor whh, Tensor bih, Tensor bhh, Tensor h0, Tensor c0) One LSTM layer over x [T, B, I] (time first), PyTorch's equations and gate order (i, f, g, o): wih [4H, I], whh [4H, H], biases [4H], h0 and c0 [B, H]. Returns {y [T, B, H], h_n, c_n} ([B, H] each); c_n carries no gradient. -
lstm
public static Tensor[] lstm(Tensor x, Tensor wih, Tensor whh, Tensor bih, Tensor bhh, Tensor h0, Tensor c0, int[] lengths) Aslstm(Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor)for padded batches: INT32lengths[B] (null: all T); outputs past a sequence's length are 0 and h_n, c_n are each sequence's last valid state. -
reverseSequences
-
gru
-
gru
-
prelu
-
rrelu
RReLU (Xu et al., 2015): in training, a slope drawn uniformly from [lower, upper) for every element, seeded by the INT32 [2]seedtensor (seeTensor.seed(long)); in evaluation the mean slope (lower + upper) / 2. -
where
-
oneHot
-
segmentReduce
-
embeddingBag
-
quantizeQ8
-
dequantize
-
linearQ8
-
flip
-
centerCrop
-
lpNormalize
-
depthToSpace
-
spaceToDepth
-
gatherND
-
scatterND
-
fold
-
normalizeImage
-
rgbToGrayscale
-
swiglu
-
accuracy
-