MCPcopy Create free account
hub / github.com/tensorflow/tfjs / backwardsFunc

Method backwardsFunc

tfjs-core/src/engine.ts:1190–1208  ·  view source on GitHub ↗
(dy: T, saved: Tensor[])

Source from the content-addressed store, hash-verified

1188 };
1189
1190 const backwardsFunc = (dy: T, saved: Tensor[]) => {
1191 const gradRes = res.gradFunc(dy, saved);
1192 const grads: Tensor[] = Array.isArray(gradRes) ? gradRes : [gradRes];
1193 util.assert(
1194 grads.length === inputs.length,
1195 () => 'The function f passed in customGrad(f) must return an ' +
1196 'object where `obj.gradFunc` is a function that returns ' +
1197 'the same number of tensors as inputs passed to f(...).');
1198 util.assert(
1199 grads.every(t => t instanceof Tensor),
1200 () => 'The function f passed in customGrad(f) must return an ' +
1201 'object where `obj.gradFunc` is a function that returns ' +
1202 'a list of only tensors.');
1203 const gradMap: {[key: string]: () => Tensor} = {};
1204 grads.forEach((grad, i) => {
1205 gradMap[i] = () => grad;
1206 });
1207 return gradMap;
1208 };
1209
1210 return this.runKernelFunc({
1211 forwardFunc,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected