Class MetalBackend
java.lang.Object
io.github.kirstenali.deepj.tensor.metal.MetalBackend
- All Implemented Interfaces:
CausalAttentionBackend,TensorBackend
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadamWUpdate(Tensor w, Tensor g, Tensor mt, Tensor vt, float lr, float beta1, float beta2, float eps, float weightDecay, float bc1, float bc2) addBroadcastCols(Tensor a, Tensor v) addBroadcastRows(Tensor a, Tensor v) voidaddInPlace(Tensor a, Tensor b) addRowVector(Tensor a, Tensor v) voidaddScalarInPlace(Tensor a, float s) batchedMatmul(Tensor left, Tensor right, int batches, boolean transposeLeft, boolean transposeRight) causalAttention(Tensor query, Tensor key, Tensor value, int heads, float scale) causalAttention(Tensor query, Tensor key, Tensor value, int queryHeads, int keyValueHeads, float scale) causalAttentionBackward(Tensor query, Tensor key, Tensor value, CausalAttentionResult saved, Tensor gradient, int heads, float scale) causalAttentionBackward(Tensor query, Tensor key, Tensor value, CausalAttentionResult saved, Tensor gradient, int queryHeads, int keyValueHeads, float scale) causalMask(Tensor input, int sequenceLength) causalSoftmax(Tensor input, int sequenceLength, float scale) Independent storage with the same float bits, without recording an autograd operation.voidExplicitly assigns logical values, casting to the destination's storage dtype.crossEntropy(Tensor logits, int[] targets) crossEntropy(Tensor logits, int[] targets, boolean[] mask) crossEntropyGradient(Tensor logits, int[] targets) crossEntropyGradient(Tensor logits, int[] targets, boolean[] mask) floatcrossEntropyLoss(Tensor logits, int[] targets) floatcrossEntropyLoss(Tensor logits, int[] targets, boolean[] mask) divideBroadcastCols(Tensor a, Tensor v) voiddivideInPlace(Tensor a, Tensor b) divideScalar(Tensor a, float scalar) voiddivideScalarInPlace(Tensor a, float s) voidexpInPlace(Tensor a) geluBackward(Tensor input, Tensor gradOutput) voidheadPrefixMatmul(Tensor left, Tensor cache, int heads, int length, boolean transposeCache) voidindexSelect(Tensor input, int axis, int[] indices) indexSelectGradient(Tensor gradient, int[] shape, int axis, int[] indices) static booleanfloatlayerNormBackward(Tensor dXHat, Tensor xHat, Tensor std, int dim) voidlogInPlace(Tensor a) voidmaximumAxes(Tensor input, int[] axes, boolean keep) maximumAxesBackward(Tensor input, Tensor maximum, Tensor gradient, int[] axes, boolean keep) mergeHeads(Tensor input, int heads) voidmultiplyInPlace(Tensor a, Tensor b) multiplyScalar(Tensor a, float scalar) voidmultiplyScalarInPlace(Tensor a, float s) voidnegInPlace(Tensor a) normalizationBackward(Tensor gradient, Tensor normalized, Tensor denominator, Tensor gamma, boolean centered) voidvoidreluBackward(Tensor input, Tensor gradOutput) voidrmsNormBackward(Tensor gradient, Tensor normalized, Tensor rms, Tensor gamma) voidscatterAddRows(Tensor target, int[] indices, Tensor grad) voidsliceGradient(Tensor gradient, int[] shape, int axis, int start, int step) softmaxAxis(Tensor input, int axis) softmaxBackward(Tensor gradOutput, Tensor softmaxOut) softmaxBackward(Tensor gradient, Tensor probabilities, float scale) softmaxRows(Tensor logits) splitHeads(Tensor input, int heads) voidvoidsubtractInPlace(Tensor a, Tensor b) floatfloatbooleansupportsCausalAttention(Tensor query, Tensor key, Tensor value, int heads, float scale) booleansupportsCausalAttention(Tensor query, Tensor key, Tensor value, int queryHeads, int keyValueHeads, float scale) static booleansupportsNative16Matmul(DType dtype) Whether compact matrix products can use native16 operands with FP32 accumulation.swiGluBackward(Tensor gradient, Tensor gate, Tensor up) voidbooleanWhether backend copies reside on a device rather than in ordinary host storage.varianceAxes(Tensor input, int[] axes, boolean keep, int correction) voidwriteHeadCache(Tensor cache, Tensor update, int heads, int offset) zeros(int rows, int columns) Backend-owned positive-zero storage; ordinary Tensor constructors stay CPU-backed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.kirstenali.deepj.tensor.TensorBackend
adamWUpdate, add, addBroadcastCols, addBroadcastRows, addInPlace, addRowVector, addScalar, addScalarInPlace, batchedMatmul, cast, causalMask, causalSoftmax, clamp, copy, copyInto, crossEntropy, crossEntropy, crossEntropyGradient, crossEntropyGradient, crossEntropyLoss, crossEntropyLoss, divide, divideBroadcastCols, divideInPlace, divideScalar, divideScalarInPlace, exp, expand, expInPlace, gelu, geluBackward, geluInPlace, headPrefixMatmul, indexAdd, indexSelect, indexSelectGradient, l2Norm, layerNormBackward, log, logInPlace, materializeTensor, matmul, maxAlongRows, maximumAxes, maximumAxesBackward, meanAlongRows, meanAxes, mergeHeads, multiply, multiplyBroadcastCols, multiplyBroadcastRows, multiplyInPlace, multiplyScalar, multiplyScalarInPlace, neg, negInPlace, normalizationBackward, normalize, permute, pow, releaseResources, releaseTemporaryResources, relu, reluBackward, reluInPlace, reshape, rmsNorm, rmsNormBackward, rotary, scatterAddRows, select, sigmoid, sigmoidInPlace, slice, sliceGradient, sliceRows, softmaxAxis, softmaxAxisBackward, softmaxBackward, softmaxBackward, softmaxRows, splitHeads, sqrt, sqrtInPlace, subtract, subtractBroadcastCols, subtractInPlace, sum, sumAbs, sumAlongCols, sumAlongRows, sumAxes, sumRows, sumToShape, swiGlu, swiGluBackward, tanh, tanhInPlace, transpose, unsqueeze, usesDeviceStorage, varianceAlongRows, varianceAxes, view, writeHeadCache, zeros, zeros
-
Constructor Details
-
MetalBackend
public MetalBackend()
-
-
Method Details
-
supportsCausalAttention
public boolean supportsCausalAttention(Tensor query, Tensor key, Tensor value, int heads, float scale) - Specified by:
supportsCausalAttentionin interfaceCausalAttentionBackend
-
supportsCausalAttention
public boolean supportsCausalAttention(Tensor query, Tensor key, Tensor value, int queryHeads, int keyValueHeads, float scale) - Specified by:
supportsCausalAttentionin interfaceCausalAttentionBackend
-
causalAttention
public CausalAttentionResult causalAttention(Tensor query, Tensor key, Tensor value, int heads, float scale) - Specified by:
causalAttentionin interfaceCausalAttentionBackend
-
causalAttention
public CausalAttentionResult causalAttention(Tensor query, Tensor key, Tensor value, int queryHeads, int keyValueHeads, float scale) - Specified by:
causalAttentionin interfaceCausalAttentionBackend
-
causalAttentionBackward
public AttentionGradients causalAttentionBackward(Tensor query, Tensor key, Tensor value, CausalAttentionResult saved, Tensor gradient, int heads, float scale) - Specified by:
causalAttentionBackwardin interfaceCausalAttentionBackend
-
causalAttentionBackward
public AttentionGradients causalAttentionBackward(Tensor query, Tensor key, Tensor value, CausalAttentionResult saved, Tensor gradient, int queryHeads, int keyValueHeads, float scale) - Specified by:
causalAttentionBackwardin interfaceCausalAttentionBackend
-
writeHeadCache
-
headPrefixMatmul
-
adamWUpdate
-
swiGlu
-
swiGluBackward
-
scatterAddRows
-
releaseTemporaryResources
public void releaseTemporaryResources() -
releaseResources
public void releaseResources() -
crossEntropyGradient
-
crossEntropy
-
crossEntropyLoss
-
crossEntropyLoss
-
crossEntropy
-
crossEntropyGradient
-
layerNormBackward
-
rmsNorm
-
rmsNormBackward
-
normalize
public NormalizationResult normalize(Tensor input, Tensor gamma, Tensor beta, float epsilon, boolean centered) -
normalizationBackward
-
addInPlace
-
subtractInPlace
-
multiplyInPlace
-
divideInPlace
-
multiplyScalarInPlace
-
addScalarInPlace
-
divideScalarInPlace
-
sqrtInPlace
-
negInPlace
-
expInPlace
-
logInPlace
-
reluInPlace
-
geluInPlace
-
tanhInPlace
-
sigmoidInPlace
-
multiplyScalar
-
addScalar
-
divideScalar
-
clamp
-
pow
-
sqrt
-
neg
-
exp
-
log
-
tanh
-
sigmoid
-
relu
-
reluBackward
-
gelu
-
geluBackward
-
softmaxRows
-
softmaxBackward
-
softmaxBackward
-
sumRows
-
sumAlongRows
-
sumAlongCols
-
meanAlongRows
-
varianceAlongRows
-
maxAlongRows
-
sum
-
sumAbs
-
l2Norm
-
transpose
-
sumAxes
-
meanAxes
-
varianceAxes
-
maximumAxes
-
maximumAxesBackward
-
softmaxAxis
-
sliceGradient
-
indexSelect
-
indexAdd
-
indexSelectGradient
-
isAvailable
public static boolean isAvailable() -
supportsNative16Matmul
Whether compact matrix products can use native16 operands with FP32 accumulation. -
usesDeviceStorage
public boolean usesDeviceStorage()Description copied from interface:TensorBackendWhether backend copies reside on a device rather than in ordinary host storage.- Specified by:
usesDeviceStoragein interfaceTensorBackend
-
zeros
Description copied from interface:TensorBackendBackend-owned positive-zero storage; ordinary Tensor constructors stay CPU-backed.- Specified by:
zerosin interfaceTensorBackend
-
zeros
- Specified by:
zerosin interfaceTensorBackend
-
copy
Description copied from interface:TensorBackendIndependent storage with the same float bits, without recording an autograd operation.- Specified by:
copyin interfaceTensorBackend
-
cast
- Specified by:
castin interfaceTensorBackend
-
copyInto
Description copied from interface:TensorBackendExplicitly assigns logical values, casting to the destination's storage dtype.- Specified by:
copyIntoin interfaceTensorBackend
-
materializeTensor
- Specified by:
materializeTensorin interfaceTensorBackend
-
matmul
- Specified by:
matmulin interfaceTensorBackend
-
sliceRows
- Specified by:
sliceRowsin interfaceTensorBackend
-
splitHeads
- Specified by:
splitHeadsin interfaceTensorBackend
-
mergeHeads
- Specified by:
mergeHeadsin interfaceTensorBackend
-
batchedMatmul
public Tensor batchedMatmul(Tensor left, Tensor right, int batches, boolean transposeLeft, boolean transposeRight) - Specified by:
batchedMatmulin interfaceTensorBackend
-
causalMask
- Specified by:
causalMaskin interfaceTensorBackend
-
causalSoftmax
- Specified by:
causalSoftmaxin interfaceTensorBackend
-
rotary
- Specified by:
rotaryin interfaceTensorBackend
-
add
- Specified by:
addin interfaceTensorBackend
-
subtract
- Specified by:
subtractin interfaceTensorBackend
-
multiply
- Specified by:
multiplyin interfaceTensorBackend
-
divide
- Specified by:
dividein interfaceTensorBackend
-
addRowVector
- Specified by:
addRowVectorin interfaceTensorBackend
-
addBroadcastCols
- Specified by:
addBroadcastColsin interfaceTensorBackend
-
divideBroadcastCols
- Specified by:
divideBroadcastColsin interfaceTensorBackend
-
subtractBroadcastCols
- Specified by:
subtractBroadcastColsin interfaceTensorBackend
-
multiplyBroadcastCols
- Specified by:
multiplyBroadcastColsin interfaceTensorBackend
-
addBroadcastRows
- Specified by:
addBroadcastRowsin interfaceTensorBackend
-
multiplyBroadcastRows
- Specified by:
multiplyBroadcastRowsin interfaceTensorBackend
-