Implementation:Tensorflow Tfjs CPU Conv3DBackpropInputV2 Kernel
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Deep_Learning, CPU_Backend |
| Last Updated | 2026-02-10 06:00 GMT |
Overview
The Conv3DBackpropInputV2 kernel computes the gradient of a 3D convolution with respect to the input tensor on the CPU backend. It extends the 2D backpropagation pattern into three spatial dimensions (depth, height, width), iterating over the upstream gradient and transposed filter to accumulate the input gradient. This kernel is used during backpropagation through conv3d layers.
Code Reference
Source Location
tfjs-backend-cpu/src/kernels/Conv3DBackpropInputV2.ts (GitHub)
Signature
export function conv3DBackpropInputV2(args: {
inputs: Conv3DBackpropInputV2Inputs,
backend: MathBackendCPU,
attrs: Conv3DBackpropInputV2Attrs
}): TensorInfo
Imports
import {backend_util, Conv3DBackpropInputV2, Conv3DBackpropInputV2Attrs, Conv3DBackpropInputV2Inputs, KernelConfig, KernelFunc, TensorBuffer, TensorInfo, TypedArray, util} from '@tensorflow/tfjs-core';
import {MathBackendCPU} from '../backend_cpu';
import {assertNotComplex} from '../cpu_util';
Kernel Registration
export const conv3DBackpropInputV2Config: KernelConfig = {
kernelName: Conv3DBackpropInputV2,
backendName: 'cpu',
kernelFunc: conv3DBackpropInputV2 as unknown as KernelFunc
};
I/O Contract
| Parameter | Type | Description |
|---|---|---|
inputs.dy |
TensorInfo |
Upstream gradient tensor from the forward conv3d output |
inputs.filter |
TensorInfo |
The convolution filter of shape [filterDepth, filterHeight, filterWidth, inChannels, outChannels]
|
attrs.inputShape |
[number, number, number, number, number] |
Shape of the original input tensor |
attrs.strides |
[number, number, number] | Stride of the convolution |
attrs.pad |
'same' | number | Padding mode |
| Return | TensorInfo |
The gradient tensor dx with shape matching inputShape
|
Implementation Details
- Asserts that
dyis not a complex tensor. - Computes 3D convolution metadata via
backend_util.computeConv3DInfowith dilation fixed at 1. - Allocates a
TensorBufferfor the output gradientdx. - Precomputes stride arrays for
dx,dy, and the filter for efficient flat-index computation. - Computes padding offsets:
frontPad = filterDepth - 1 - padInfo.front,topPad = filterHeight - 1 - padInfo.top,leftPad = filterWidth - 1 - padInfo.left. - Uses seven nested loops (batch, inChannels, inDepth, inHeight, inWidth, plus output spatial dimensions) to accumulate dot products.
- Filter indices are reversed (e.g.,
filterDepth - 1 - wF) to implement the transposed convolution. - Each output gradient position contributes to the input gradient weighted by the corresponding filter value across all output channels.
Usage Examples
import {conv3DBackpropInputV2} from './Conv3DBackpropInputV2';
const dx = conv3DBackpropInputV2({
inputs: {dy: dyTensor, filter: filterTensor},
backend: cpuBackend,
attrs: {
inputShape: [1, 8, 8, 8, 3],
strides: [1, 1, 1],
pad: 'same'
}
});
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment