Optimized le.Tensor_out returns b <= a for reverse-argument broadcasts
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
Start with kernels/optimized/cpu/op_le.cpp and the reverse-argument handling described in the issue; then inspect the related tests in kernels/test/op_le_test.cpp. Add regression coverage that exercises the optimized paths with matching input and output dtypes. Done means those paths produce the expected a <= b results for the listed broadcast shapes.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
With the optimized CPU kernels, le.Tensor_out returns b <= a instead of a <= b when the left operand is the one being broadcast and both inputs and the output share a dtype (for example two Bool masks, or a non-Bool output).
Repro (C++ kernel test)
TensorFactory<ScalarType::Bool> tf;
Tensor a = tf.make({4}, {false, true, false, true});
Tensor b = tf.make({2, 4}, {false, false, true, true, true, true, false, false});
Tensor out = tf.zeros({2, 4});
torch::executor::aten::le_outf(context_, a, b, out);
| Result | |
|---|---|
Expected (a <= b, also what the portable kernel returns) |
{1, 0, 1, 1, 1, 1, 1, 0} |
| Optimized kernel | {1, 1, 0, 1, 0, 1, 1, 1} (that is b <= a) |
The same happens for Float and Int inputs with a Float/Int output, on all three reverse-argument broadcast paths: (4,) vs (2, 4), (2, 1) vs (2, 3), and (2, 1, 2) vs (2, 3, 2). Float inputs with a Bool output are not affected, because select_optimized_path returns kNone when the output dtype differs and the portable comparison is used.
Cause
select_optimized_path returns kBroadcast2dBy1dReverseArguments, kBroadcastLastDimReverseArguments or kBroadcastNdByNdReverseArguments when the left operand is the broadcast one, and handle_broadcast_elementwise then calls the lambda with the operands swapped. op_div.cpp and op_add_sub_impl.h account for this by swapping their lambda on those paths, but op_le.cpp always passes x.le(y):
https://github.com/pytorch/executorch/blob/aed328df53/kernels/optimized/cpu/op_le.cpp#L57-L63
The existing BroadcastLastDimReverseTest, BroadcastNdByNdReverseTest and similar tests in kernels/test/op_le_test.cpp use a Bool output with Int inputs, so they take the portable path and never exercise the optimized broadcast code.
I have a fix with regression tests and will open a PR.
Versions
main at aed328df53, built from source with CMake (EXECUTORCH_BUILD_TESTS=ON, EXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON), Ubuntu, x86_64, GCC 15.2.0.
- 主要语言
- Python
- 星标
- 5.2k
- 派生
- 1.2k
- 平均合并
- 1 天 22 小时
- 30 天内合并 PR
- 675
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pytorch/executorch 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
pytorch/executorch#24434 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
pytorch/executorch#24410 ·
维护者通常 1 天内回复
-
enhancement triaged
难度 2/5 半天 新手友好度 68/100
pytorch/executorch#21640 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
pytorch/executorch#24502 ·
维护者通常 1 天内回复
-
`install_executorch.sh` fails in a fresh uv virtual environment: `No module named pip`可能已有人在做 @mshr-h 于 3 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 45/100
pytorch/executorch#24417 ·
维护者通常 1 天内回复
查看 pytorch/executorch 的全部 Issue
相似的 Issue
-
bug severity:low
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复
-
curriculum documentation quality
难度 2/5 1-3 小时 新手友好度 77/100
githubnext/gh-aw-workshop#5367 ·
维护者通常 3 天内回复
-
OAuth documentation for GET /api/v2/users/me/ appears inconsistent with required global read scope未关闭
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
Create Noise Latents ignores randomize_seed and produces the same noise every run可能已有人在做 @griptapeops 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
griptape-ai/griptape-nodes-library-diffusers#127 ·
维护者通常 1 天内回复
-
Jenkins capacity report: metrics history is lost when archiving a month fails可能已有人在做 @RaphaelFakhri 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
adoptium/infrastructure#4568 ·
维护者通常 1 天内回复