Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
一句话:pypto.scatter_update(input, dim, index, src) 自称是"更新 input 中指定位置",但实际行为是"新建一个全 0 的 tensor,只把 index 指定的位置填上 src 的值"——未被 index 指定的位置全变成 0,没有保留 input 的原值。这与 PyTorch scatter_/index_copy 的惯例(保留非索引位原值)不符。
类比:你说"帮我改一下这张表格的第 3、5 行",结果对方把整张表格其他行全擦成空白了。
根因(已定位到源码):scatter_update.cpp:306 创建新 tensor 后只 TILE_INDEX_OUTCAST 填充 index 位置,没有从 input 拷贝非索引位的值。文档 pypto-scatter_update.md:15-28 仅给出单行公式,未说明"输出须预初始化为 input 副本"的约束。
PyPTO API 场景下,pypto.scatter_update(input, dim, index, src) 在输出缓冲区未初始化(torch.empty_like)时仅填充 index 指定位置,不保留 input 中非索引位置的值。这与 PyTorch scatter_/index_copy 保留非索引位的惯例不符;文档称"原地操作"但示例只用零值 input,未说明"输出须预初始化为 input 副本"的约束。
服务器/NPU 型号: A3(910B3) PyPTO 版本/Commit: 0.2.1,本地 HEAD 12ef077d0,远端 master 30830736d CANN 版本: cann-9.2.0(source /home/operation/Ascend/ascend-toolkit/set_env.sh) Python 版本: 3.13.9 操作系统: Huawei Cloud EulerOS 2.0 (aarch64) torch / torch_npu 版本: 2.12.0+cu130 / 2.12.0
环境准备:
source /home/operation/Ascend/ascend-toolkit/set_env.sh export TILE_FWK_DEVICE_ID=4 运行复现脚本(构造 4D input [2,6,1,3],值从 0 到 35 递增;index [[1,4]];src [[101,102,103],[201,202,203]];JIT kernel 执行 pypto.scatter_update(input, -2, index, src),结果 move() 到 torch.empty_like 输出 buffer):
cd /home/l00605417/lxx/benchmark_runs/fracture-points-0918-gen-tune/issues/3_2_issue_conform/issue-10 python3 repro_scatter_semantics.py 观察输出:非索引位置(如 [0,0]、[0,2]、[0,3])输出为 [0,0,0](而非 input 原值 [0,1,2]、[6,7,8])。
pypto.scatter_update 应保留 input 中非 index 位置的值:非索引位的输出应等于 input 对应原值,而不是 0/垃圾值。 若当前行为(不保留非索引位)是有意设计,文档必须在返回值说明中明确"输出(result)的非索引位不会被 input 的值填充;调用方须预初始化输出为期望默认值",并在示例中展示非零 input 的行为。 Related log
DIFF [0,0]: got=[0, 0, 0] exp=[0, 1, 2] DIFF [0,2]: got=[0, 0, 0] exp=[6, 7, 8] non-index positions equal input: False P-10 REPRODUCED: scatter_update result has ZEROS (not input values) at non-index positions 第 1 行说明位置 [0,0] 实际输出 [0,0,0](零),期望为 [0,1,2](input 原值);第 3 行判定"非索引位与 input 不一致";第 4 行确认复现。
Tensor result(dst.GetStorage()->Datatype(), dst.GetStorage()->GetShape(), "", dst.Format()); 这一行说明:只创建了一个新 tensor(初始为全 0),随后只 TILE_INDEX_OUTCAST 填充 index 位置——缺失 input→result 的初始数据拷贝。
a2f54d753e68483db88bd148e01a7474.zip
好的,已收到问题,正在安排分析
已与@liuxiaoxiao11确认,非问题。
当前接口样例给的是全0输入,不太合适,将进行修正重新提供样例
已修改
Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
Describe the current behavior / 问题描述 (Mandatory / 必填)
一句话:pypto.scatter_update(input, dim, index, src) 自称是"更新 input 中指定位置",但实际行为是"新建一个全 0 的 tensor,只把 index 指定的位置填上 src 的值"——未被 index 指定的位置全变成 0,没有保留 input 的原值。这与 PyTorch scatter_/index_copy 的惯例(保留非索引位原值)不符。
类比:你说"帮我改一下这张表格的第 3、5 行",结果对方把整张表格其他行全擦成空白了。
根因(已定位到源码):scatter_update.cpp:306 创建新 tensor 后只 TILE_INDEX_OUTCAST 填充 index 位置,没有从 input 拷贝非索引位的值。文档 pypto-scatter_update.md:15-28 仅给出单行公式,未说明"输出须预初始化为 input 副本"的约束。
PyPTO API 场景下,pypto.scatter_update(input, dim, index, src) 在输出缓冲区未初始化(torch.empty_like)时仅填充 index 指定位置,不保留 input 中非索引位置的值。这与 PyTorch scatter_/index_copy 保留非索引位的惯例不符;文档称"原地操作"但示例只用零值 input,未说明"输出须预初始化为 input 副本"的约束。
Environment / 环境信息 (Mandatory / 必填)
服务器/NPU 型号: A3(910B3)
PyPTO 版本/Commit: 0.2.1,本地 HEAD 12ef077d0,远端 master 30830736d
CANN 版本: cann-9.2.0(source /home/operation/Ascend/ascend-toolkit/set_env.sh)
Python 版本: 3.13.9
操作系统: Huawei Cloud EulerOS 2.0 (aarch64)
torch / torch_npu 版本: 2.12.0+cu130 / 2.12.0
Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)
环境准备:
source /home/operation/Ascend/ascend-toolkit/set_env.sh
export TILE_FWK_DEVICE_ID=4
运行复现脚本(构造 4D input [2,6,1,3],值从 0 到 35 递增;index [[1,4]];src [[101,102,103],[201,202,203]];JIT kernel 执行 pypto.scatter_update(input, -2, index, src),结果 move() 到 torch.empty_like 输出 buffer):
cd /home/l00605417/lxx/benchmark_runs/fracture-points-0918-gen-tune/issues/3_2_issue_conform/issue-10
python3 repro_scatter_semantics.py
观察输出:非索引位置(如 [0,0]、[0,2]、[0,3])输出为 [0,0,0](而非 input 原值 [0,1,2]、[6,7,8])。
Describe the expected behavior / 预期结果 (Mandatory / 必填)
pypto.scatter_update 应保留 input 中非 index 位置的值:非索引位的输出应等于 input 对应原值,而不是 0/垃圾值。
若当前行为(不保留非索引位)是有意设计,文档必须在返回值说明中明确"输出(result)的非索引位不会被 input 的值填充;调用方须预初始化输出为期望默认值",并在示例中展示非零 input 的行为。
Related log
Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
DIFF [0,0]: got=[0, 0, 0] exp=[0, 1, 2]
DIFF [0,2]: got=[0, 0, 0] exp=[6, 7, 8]
non-index positions equal input: False
P-10 REPRODUCED: scatter_update result has ZEROS (not input values) at non-index positions
第 1 行说明位置 [0,0] 实际输出 [0,0,0](零),期望为 [0,1,2](input 原值);第 3 行判定"非索引位与 input 不一致";第 4 行确认复现。
Tensor result(dst.GetStorage()->Datatype(), dst.GetStorage()->GetShape(), "", dst.Format());
这一行说明:只创建了一个新 tensor(初始为全 0),随后只 TILE_INDEX_OUTCAST 填充 index 位置——缺失 input→result 的初始数据拷贝。
Special notes for this issue/备注 (Optional / 选填)
a2f54d753e68483db88bd148e01a7474.zip