tf.stridedSlice returns wrong values or throws when shrinkAxisMask is combined with a non-unit stride on another axis
@nileshau-afk 已经在做这个了。
开始于 2026年11月9日。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
调研方向
Start with tfjs-backend-cpu/src/kernels/StridedSlice.ts and tfjs-core/src/ops/slice_util.ts, where the issue points to a rank mismatch between the processing shape and the stride and begin arrays. Check the existing strided-slice tests and reproduce both examples on the CPU and WASM backends. Done means both slices return [1, 5] and [3, 5] on both backends without an out-of-range error.
由索引模型根据 Issue 内容生成。
描述
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 has no changes to the files involved), Node.js 26.13.0
- Browser version: n/a
- Tensorflow.js Converter Version: n/a
Describe the current behavior
When one axis is shrunk (shrinkAxisMask) and another axis has a stride other than 1, tf.stridedSlice reads the wrong elements on the cpu backend or throws Requested out of range element. The wasm backend returns different, also wrong, values. These are the slices Python writes as y[::2, 1] or x[1, ::2], so converted models that contain such a StridedSlice op are affected too.
Describe the expected behavior
Same result as tf.strided_slice in TensorFlow: [1, 5] and [3, 5].
Standalone code to reproduce the issue
const tf = require("@tensorflow/tfjs-core");
require("@tensorflow/tfjs-backend-cpu");
require("@tensorflow/tfjs-backend-wasm");
(async () => {
await tf.setBackend(process.argv[2]);
const y = tf.tensor2d([0, 1, 2, 3, 4, 5], [3, 2]);
// y[::2, 1] -> expected [1, 5]
console.log(Array.from(tf.stridedSlice(y, [0, 1], [0, 2], [2, 1], 1, 1, 0, 0, 2).dataSync()));
const x = tf.tensor2d([0, 1, 2, 3, 4, 5], [2, 3]);
// x[1, ::2] -> expected [3, 5]
try { console.log(Array.from(tf.stridedSlice(x, [1, 0], [2, 0], [1, 2], 0, 2, 0, 0, 1).dataSync())); } catch (e) { console.log("Error: " + e.message); }
})();
$ node ss.js cpu
[ 0, 2 ]
Error: Requested out of range element at 2. Buffer shape=2,3
$ node ss.js wasm
[ 0, 2 ]
[ 1, 2 ]
TensorFlow 2.21 (y[::2, 1], x[1, ::2], or tf.strided_slice with the same masks) gives [1. 5.] and [3. 5.].
Other info / logs
On cpu the general path calls stridedSliceImpl(finalShapeSparse, xBuf, $strides, $begin). finalShapeSparse has the shrunk axes removed, while $begin and $strides are per dense axis, so the location arrays have the wrong rank (tfjs-backend-cpu/src/kernels/StridedSlice.ts, tfjs-core/src/ops/slice_util.ts sliceInfo). Using the processing shape (shrunk axes kept as size 1) there and reshaping to finalShape afterwards should fix it.
Credit: https://ucsbplse.github.io/
- 主要语言
- TypeScript
- 星标
- 19.2k
- 派生
- 2k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tensorflow/tfjs 的其他 Issue
-
[CPU] ResizeBilinearGrad swaps height and width for rectangular inputs in TensorFlow.js 4.22.0可能已有人在做 @nileshau-afk 于 3 天前认领。 未关闭comp:backend-cpu type:bug
难度 2/5 1-3 小时 新手友好度 77/100
tensorflow/tfjs#8757 · 已指派 1 人 ·
-
conv3d, maxPool3d and avgPool3d with pad 'same' use the wrong window when the filter is smaller than the stride可能已有人在做 @nileshau-afk 于 3 天前认领。 未关闭comp:core type:bug
难度 2/5 1-3 小时 新手友好度 86/100
tensorflow/tfjs#8753 · 已指派 1 人 ·
-
WASM backend: cast to bool, conv2d/maxPool3d with pad "same", and oneHot with float values disagree with the CPU backend可能已有人在做 @nileshau-afk 于 1 天前认领。 未关闭comp:wasm type:bug
难度 4/5 3-5 天 新手友好度 28/100
tensorflow/tfjs#8759 · 已指派 1 人 ·
-
Review argparse dependency bringing in sprintf-js CVE-2026-97058可能已有人在做 @nileshau-afk 于 3 天前认领。 未关闭type:others type:support
难度 4/5 3-5 天 新手友好度 22/100
tensorflow/tfjs#8749 · 已指派 1 人 ·
-
`@tensorflow/tfjs-node` installation issue可能重新可做 @nileshau-afk 于 34 天前认领,目前没有进行中的 PR。 未关闭comp:node.js type:build/install
难度 4/5 3-5 天 新手友好度 48/100
tensorflow/tfjs#8748 · 已指派 1 人 ·
相似的 Issue
-
grep and find tools search inside VCS directories (.git, .svn, .hg, .jj)可能已有人在做 @acmerfight 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
earendil-works/pi#12084 ·
维护者通常 1 天内回复
-
comp/desktop P3 type/feature
难度 2/5 1-3 小时 新手友好度 78/100
NousResearch/hermes-agent#154285 ·
维护者通常 1 天内回复
-
agent-reported bug from-app needs-triage
难度 2/5 1-3 小时 新手友好度 72/100
nightly-labs/openbot#8154 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
jdx/mise-action#730 ·
维护者通常 1 天内回复
-
area:cards enhancement hand-tail ready-for-agent
难度 2/5 1-3 小时 新手友好度 70/100
fil-donadoni/tolaria#9275 ·
维护者通常 1 天内回复