Interface TensorBackend
-
Method Summary
Modifier and TypeMethodDescriptionvoidadamWUpdate(Tensor w, Tensor g, Tensor mt, Tensor vt, double lr, double beta1, double beta2, double eps, double weightDecay, double bc1, double bc2) In-place AdamW update.addBroadcastCols(Tensor a, Tensor colVector) addBroadcastRows(Tensor a, Tensor rowVector) default voidaddInPlace(Tensor a, Tensor b) addRowVector(Tensor a, Tensor rowVector) default voidaddScalarInPlace(Tensor a, double s) causalMask(int size) crossEntropyGradient(Tensor logits, int[] targets) doublecrossEntropyLoss(Tensor logits, int[] targets) divideBroadcastCols(Tensor a, Tensor colVector) default voiddivideInPlace(Tensor a, Tensor b) divideScalar(Tensor a, double scalar) default voiddivideScalarInPlace(Tensor a, double s) default voidexpInPlace(Tensor a) double[]geluBackward(Tensor input, Tensor gradOutput) default voiddoublelayerNormBackward(Tensor dXHat, Tensor xHat, Tensor std, int dim) LayerNorm backward through normalization (given dXHat, xHat, std).default voidlogInPlace(Tensor a) default voidMaterialize a tensor: flush any pending GPU computation and download the result to the tensor's CPU data[][].multiplyBroadcastCols(Tensor a, Tensor colVector) multiplyBroadcastRows(Tensor a, Tensor rowVector) default voidmultiplyInPlace(Tensor a, Tensor b) multiplyScalar(Tensor a, double scalar) default voidmultiplyScalarInPlace(Tensor a, double s) default voidnegInPlace(Tensor a) ones(int rows, int cols) voiddefault voidRelease backend-owned resources (GPU buffers, native handles, etc.).reluBackward(Tensor input, Tensor gradOutput) default voidsampleRows(Tensor t, int n, Random rnd) Sample random rows from t.voidscatterAddRows(Tensor target, int[] indices, Tensor grad) Scatter-add: target.data[indices[i]] += grad.data[i] (for embedding backward).voidvoiddefault voidGather rows by index (for embedding lookup).softmaxBackward(Tensor gradOutput, Tensor softmaxOut) softmaxRows(Tensor logits) default voidsubtractBroadcastCols(Tensor a, Tensor colVector) default voidsubtractInPlace(Tensor a, Tensor b) doubledoubledefault voidunflattenToTensor(double[] flat, int rows, int cols) zeros(int rows, int cols)
-
Method Details
-
zeros
-
ones
-
random
-
causalMask
-
unflattenToTensor
-
flattenTensor
-
matmul
-
add
-
subtract
-
multiply
-
divide
-
addRowVector
-
addBroadcastCols
-
divideBroadcastCols
-
subtractBroadcastCols
-
multiplyBroadcastCols
-
addBroadcastRows
-
multiplyBroadcastRows
-
multiplyScalar
-
addScalar
-
divideScalar
-
sumRows
-
sumAlongRows
-
sumAlongCols
-
meanAlongRows
-
varianceAlongRows
-
maxAlongRows
-
sum
-
sumAbs
-
clamp
-
transpose
-
sqrt
-
pow
-
neg
-
exp
-
log
-
tanh
-
sigmoid
-
relu
-
reluBackward
-
gelu
-
geluBackward
-
softmaxRows
-
softmaxBackward
-
crossEntropyLoss
-
crossEntropyGradient
-
adamWUpdate
-
layerNormBackward
-
get
-
set
-
getRow
-
setRow
-
sliceRows
-
scatterAddRows
-
sampleRows
-
print
-
addInPlace
-
subtractInPlace
-
multiplyInPlace
-
divideInPlace
-
multiplyScalarInPlace
-
addScalarInPlace
-
divideScalarInPlace
-
sqrtInPlace
-
negInPlace
-
expInPlace
-
logInPlace
-
reluInPlace
-
geluInPlace
-
tanhInPlace
-
sigmoidInPlace
-
materializeTensor
Materialize a tensor: flush any pending GPU computation and download the result to the tensor's CPU data[][]. Default is a no-op (for CpuBackend). -
releaseResources
default void releaseResources()Release backend-owned resources (GPU buffers, native handles, etc.). Default is a no-op for backends without external resources.
-