* This method is called instead of the public-facing tensor.clone() when * saving a tensor for backwards pass. It makes sure to add the clone * operation to the tape regardless of being called inside a kernel * execution.
(x: Tensor)
| 503 | * execution. |
| 504 | */ |
| 505 | private clone(x: Tensor): Tensor { |
| 506 | const y: Tensor = ENGINE.runKernel(Identity, |
| 507 | {x} as unknown as NamedTensorMap); |
| 508 | const inputs = {x}; |
| 509 | const grad = (dy: Tensor) => ({ |
| 510 | x: () => { |
| 511 | const dtype = 'float32'; |
| 512 | const gradInputs = {x: dy}; |
| 513 | const attrs = {dtype}; |
| 514 | |
| 515 | return ENGINE.runKernel( |
| 516 | Cast, gradInputs as unknown as NamedTensorMap, |
| 517 | // tslint:disable-next-line: no-unnecessary-type-assertion |
| 518 | attrs as unknown as NamedAttrMap) as Tensor; |
| 519 | } |
| 520 | }); |
| 521 | const saved: Tensor[] = []; |
| 522 | this.addTapeNode(this.state.activeScope.name, inputs, [y], grad, saved, {}); |
| 523 | return y; |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * Execute a kernel with the given name and return the output tensor. |
no test coverage detected