[Vulkan] scalar_tensor uploads float bytes to integer scalar shaders
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 66/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
Start in backends/vulkan/runtime/graph/ops/impl/ScalarTensor.cpp and compare its parameter upload with the declaration in backends/vulkan/runtime/graph/ops/glsl/scalar_tensor.glsl. Run the provided Vulkan regression cases with the scalar-tensor exporter fixes from #23156. Done means the buffer type matches the shader declaration and integer outputs preserve values such as 16777217.
由索引模型根据 Issue 内容生成。
描述
🐛 Describe the bug
While implementing the scalar-tensor delegation fixes in #23156, I found a separate runtime parameter-type mismatch in ScalarTensor.cpp.
The runtime always extracts the scalar as float and uploads a float parameter buffer, but selects the shader's scalar parameter type from graph.dtype_of(scalar_in). An integer literal therefore selects an integer parameter declaration while receiving float bytes. For example, 3.0f has the bit pattern 0x40400000, which an int32 parameter reads as 1077936128.
Converting every integer scalar through float also loses precision for exactly representable int32 values above 2**24, such as 16777217.
The relevant code is in ScalarTensor.cpp, and the parameter declaration comes from scalar_tensor.glsl.
This becomes reachable through ordinary exported models after fixing the raw ATen registration and serialized operator name described in item 2 of #23156. Without those exporter fixes, the scalar tensors fall back to CPU and hide this runtime defect.
The following regression cases exercise mixed scalar types and integer precision. They require a Vulkan-enabled runtime and the scalar-tensor exporter fixes from #23156:
import torch
from executorch.backends.vulkan.partitioner.vulkan_partitioner import VulkanPartitioner
from executorch.exir import to_edge_transform_and_lower
from executorch.extension.pybindings.portable_lib import (
_load_for_executorch_from_buffer,
)
class WhereScalars(torch.nn.Module):
def __init__(self, positive, negative):
super().__init__()
self.positive = positive
self.negative = negative
def forward(self, x):
return torch.where(x, self.positive, self.negative)
inputs = (torch.tensor([True, False, True, False]),)
for positive, negative in ((3, -7.0), (3.0, -7), (16777217, -7)):
model = WhereScalars(positive, negative)
edge = to_edge_transform_and_lower(
torch.export.export(model, inputs),
partitioner=[VulkanPartitioner()],
)
program_buffer = edge.to_executorch().buffer
module = _load_for_executorch_from_buffer(program_buffer)
actual = module.run_method("forward", inputs)[0]
torch.testing.assert_close(actual, model(*inputs), atol=0, rtol=0)
The parameter buffer's type must match the shader declaration. Integer outputs should preserve the integer value without an intermediate float conversion. A local fix using int32 parameters for integer outputs and float parameters for floating-point outputs passes all three cases on MoltenVK. The surrounding Vulkan regression suite also passes: 36 tests, including dynamic eager attention and SDPA.
Versions
ExecuTorch base commit 0c7ce72758c0cbb832c5ac5970626beb347ca745, with local changes for #23156; PyTorch 2.13.0; Python 3.11; macOS arm64 on Apple M1 Pro using MoltenVK.
Drafted with OpenAI Codex. The parameter-type diagnosis is based on the runtime source; the local fix and regression cases were executed on the GPU.
cc @SS-JIA @manuelcandales @digantdesai @cbilgin
- 主要语言
- Python
- 星标
- 5k
- 派生
- 1.2k
- 平均合并
- 2 天 7 小时
- 30 天内合并 PR
- 521
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pytorch/executorch 的其他 Issue
-
enhancement triaged
难度 2/5 半天 新手友好度 68/100
pytorch/executorch#21640 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
pytorch/executorch#23263 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 68/100
pytorch/executorch#23262 ·
维护者通常 1 天内回复
-
XNNPACK never delegates slice_copy with stride != 1, but op-support.csv only excludes zero-dim/dynamic shapes可能已有人在做 @JakeStevens 今天认领。 未关闭module: xnnpack
pytorch/executorch#23258 · 已指派 1 人 ·
维护者通常 1 天内回复
-
[RFC] ExecuTorch Persisting Device Specialized Delegate Artifacts可能已有人在做 @JacobSzwejbka 于 1 天前认领。 未关闭
pytorch/executorch#23192 · 1 条评论 · 1 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
查看 pytorch/executorch 的全部 Issue
相似的 Issue
-
customer-reported
难度 2/5 1-3 小时 新手友好度 68/100
Azure/azure-cli#34150 · 1 条评论 ·
维护者通常 1 天内回复
-
community-request
难度 1/5 1 小时以内 新手友好度 95/100
NVIDIA-NeMo/Curator#2464 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
WeblateOrg/translation-finder#1099 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
trezor/trezor-firmware#7997 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复