@hoff97/tensor-js
Version:
PyTorch like deep learning inferrence library
31 lines • 782 B
JavaScript
export class MatMulBack {
constructor(a, b) {
this.a = a;
this.b = b;
}
backward(grad) {
if (!this.b.noGrad) {
const gradB = this.a.value.gemm(grad, true, false);
const needed = this.b.backward(gradB);
if (!needed) {
gradB.delete();
}
}
if (!this.a.noGrad) {
const gradA = grad.gemm(this.b.value, false, true);
const needed = this.a.backward(gradA);
if (!needed) {
gradA.delete();
}
}
}
delete() {
if (!this.a.isLeaf()) {
this.a.delete();
}
if (!this.b.isLeaf()) {
this.b.delete();
}
}
}
//# sourceMappingURL=matMulBack.js.map