conv3d, maxPool3d and avgPool3d with pad 'same' use the wrong window when the filter is smaller than the stride
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 86/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, typescript
- Domain
- backend, machine-learning
Research direction
Start with tfjs-core/src/ops/conv_util.ts, comparing get3DPadAndOutInfo with the 2D getPadAndOutInfo implementation. Reproduce the issue with the provided stride-2, 1×1×1 example and check the 3D convolution and pooling tests. Done means all three ops sample positions 0 and 2 with pad: 'same', while their output shape remains correct.
Written by the indexing model from the issue text.
Description
Please make sure that this is a bug. As per our
GitHub Policy,
we only address code/doc bugs, performance issues, feature requests and
build/installation issues on GitHub. tag:bug_template
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux x86_64 (Debian 12)
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: n/a
- TensorFlow.js installed from (npm or script link): npm
- TensorFlow.js version (use command below): @tensorflow/tfjs-core, @tensorflow/tfjs-backend-cpu, @tensorflow/tfjs-backend-wasm 4.22.0 (master 7f5309fe is unchanged), Node.js 26.13.0
- Browser version: n/a
- Tensorflow.js Converter Version: n/a
Describe the current behavior
With pad: 'same', the 3D ops (conv3d, maxPool3d, avgPool3d) read the wrong input positions when TensorFlow's SAME padding formula would be negative before clamping in some dimension, which happens whenever the filter is smaller than the stride (for example a 1x1x1 filter with stride 2, as in a strided 1x1x1 projection). The output has the right shape, [1, 1, 1, 2, 1], but is shifted by one element ([2, 4]). The CPU and WASM backends produce the same result.
Describe the expected behavior
Positions 0 and 2 are sampled, giving [1, 3], matching TensorFlow Python and TensorFlow.js 2D ops.
Standalone code to reproduce the issue
const tf = require("@tensorflow/tfjs-core");
require("@tensorflow/tfjs-backend-cpu");
(async () => {
await tf.setBackend("cpu");
const x = tf.tensor5d([1, 2, 3, 4], [1, 1, 1, 4, 1]);
tf.maxPool3d(x, [1, 1, 1], [1, 1, 2], "same").print();
tf.avgPool3d(x, [1, 1, 1], [1, 1, 2], "same").print();
tf.conv3d(x, tf.ones([1, 1, 1, 1, 1]), [1, 1, 2], "same").print();
})();
All three print:
Tensor
[[[[[2],
[4]]]]]
TensorFlow (tf.nn.max_pool3d, tf.nn.avg_pool3d, tf.nn.conv3d with "SAME") and the 2D equivalent tf.maxPool(tf.tensor4d([1, 2, 3, 4], [1, 1, 4, 1]), 1, 2, "same") print [1, 3].
Other info / logs
get3DPadAndOutInfo in tfjs-core/src/ops/conv_util.ts computes padAlongDepth, padAlongHeight, and padAlongWidth as (out - 1) * stride + filter - in without Math.max(0, ...), whereas the 2D version getPadAndOutInfo clamps each to at least 0. Here the width padding is -1, so left becomes -1 and every window starts one element late.
Credit: https://ucsbplse.github.io/
- Dominant language
- TypeScript
- Stars
- 19.2k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tensorflow/tfjs
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
tensorflow/tfjs#8754 ·
-
Review argparse dependency bringing in sprintf-js CVE-2026-97058Possibly taken @Varun-S10 claimed this 19 days ago. Opentype:others
Difficulty 4/5 3-5 days Newbie friendliness 22/100
tensorflow/tfjs#8749 · 1 assignee ·
-
`@tensorflow/tfjs-node` installation issueMay be free again @nileshau-afk claimed this 29 days ago, and no pull request is open. Opentype:build/install
Difficulty 4/5 3-5 days Newbie friendliness 48/100
tensorflow/tfjs#8748 · 1 assignee ·
-
The package tfjs-node is not working in version 26.8.1 of NodeMay be free again @nileshau-afk claimed this 57 days ago, and no pull request is open. Opencomp:node.js type:bug
tensorflow/tfjs#8746 · 4 comments · 1 reaction · 1 assignee ·
-
I'm getting these npm errors while trying to install @tensorflow/tfjs-nodeMay be free again @Varun-S10 claimed this 87 days ago, and no pull request is open. Openstat:awaiting tensorflower type:build/install type:support
tensorflow/tfjs#8740 · 4 comments · 1 reaction · 1 assignee ·
Similar issues
-
content triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
tool-submission
Difficulty 1/5 Under an hour Newbie friendliness 83/100
BraveOPotato/NoSignups#2348 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
code-yeongyu/oh-my-openagent#12784 ·
Maintainers usually reply within 1 day
-
external-issue to-triage
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
MomsBloomOrg/momsbloom-resources#84 ·
Maintainers usually reply within 1 day