Arm/TOSA: allow int64 through when the spec declares the int64 extension
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 54/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- backend, machine-learning
Hướng nghiên cứu
Start by reading backends/arm/tosa/mapping.py and locating map_dtype, then trace the three int64 cast passes and the node validators and visitor dtype lists named in the issue. Check how each path accesses the TOSA specification and compare lowering under TOSA-1.0+INT and TOSA-1.1+INT+int64. Done means int64 is preserved and serializes with the extension enabled, while the existing int32 casting behavior remains for specs without it.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
🐛 Describe the bug
TosaSpecification accepts TOSA-1.1+INT+int64 and support_extension("int64") returns True, but this is not honored downstream. The Arm backend narrows int64 to int32 anyway, and then refuses to serialize the int64.
Repro, an embedding with an int64 index, lowered under both specs:
import traceback
import torch
from torch.export import export
from torchao.quantization.pt2e.quantize_pt2e import convert_pt2e, prepare_pt2e
from executorch.backends.arm.quantizer.arm_quantizer import (
TOSAQuantizer, get_symmetric_quantization_config,
)
from executorch.backends.arm.tosa import TosaSpecification
from executorch.backends.arm.tosa.compile_spec import TosaCompileSpec
from executorch.backends.arm.tosa.partitioner import TOSAPartitioner
from executorch.exir import to_edge_transform_and_lower
class Embed(torch.nn.Module):
def __init__(self):
super().__init__()
self.emb = torch.nn.Embedding(10, 3)
def forward(self, idx):
return self.emb(idx)
def run(spec_str):
print(f"=== {spec_str} ===", flush=True)
inputs = (torch.tensor([[1, 2, 3, 4]], dtype=torch.int64),)
tosa_spec = TosaSpecification.create_from_string(spec_str)
print(f"support_extension('int64') = {tosa_spec.support_extension('int64')}")
quantizer = TOSAQuantizer(tosa_spec)
quantizer.set_global(get_symmetric_quantization_config())
prepared = prepare_pt2e(
export(Embed().eval(), inputs).module(check_guards=False), quantizer
)
prepared(*inputs)
converted = convert_pt2e(prepared)
try:
to_edge_transform_and_lower(
export(converted, inputs),
partitioner=[TOSAPartitioner(TosaCompileSpec(spec_str))],
)
print("lowered OK")
except Exception:
traceback.print_exc()
for s in ("TOSA-1.0+INT", "TOSA-1.1+INT+int64"):
run(s)
Under TOSA-1.0+INT:
support_extension('int64') = False
WARNING insert_int32_casts_after_int64_placeholders: Inserting a casting node
_to_dim_order_copy_default after idx to cast int64 placeholder to int32 for idx
lowered OK
Under TOSA-1.1+INT+int64:
support_extension('int64') = True
WARNING insert_int32_casts_after_int64_placeholders: Inserting a casting node
_to_dim_order_copy_default after idx to cast int64 placeholder to int32 for idx
File "executorch/backends/arm/tosa/mapping.py", line 98, in map_dtype
raise ValueError(f"Unsupported type: {data_type}")
ValueError: Unsupported type: torch.int64
The above exception was the direct cause of the following exception:
File "executorch/backends/arm/process_node.py", line 188, in process_inputs
ValueError: Failed processing input placeholder: idx. Is the original torch function supported?
InsertInt32CastsAfterInt64PlaceholdersPass is constructed without a spec. It therefore cannot tell whether int64 is allowed, and rewrites the placeholder before serialization runs. Under TOSA-1.0+INT
that is intended and lowering succeeds. The model still ends up computing in 32 bits, with only a log warning.
UNSUPPORTED_DTYPES in backends/arm/tosa/mapping.py is a module-level tuple that lists torch.int64. map_dtype's only argument is a dtype, so there is no spec available to check against. TOSA 1.1 added
the int64 extension after this code was written.
Proposed changes:
map_dtypeto take the spec and allowint64when the spec declares the extension.InsertInt32CastsAfterInt64PlaceholdersPass,ConvertInt64ConstOpsToInt32PassandConvertInt64OutputOpsToInt32Passto skip on the same condition.- Node validators and the per-visitor
dtypelists to acceptint64on the same condition.
Related: #12957 proposes sharing the int64 cast pass across backends, on the basis that the TOSA backend requires int32 inputs. That assumption does not hold with the int64 extension enabled. A
shared pass would need the same spec check.
Happy to put up PRs if this approach sounds right.
Versions
Versions
PyTorch version: 2.14.0+cu130
OS: Rocky Linux 9.8 (Blue Onyx) (x86_64)
GCC version: (GCC) 11.5.0 20240719 (Red Hat 11.5.0-14)
Libc version: glibc-2.34
Python version: 3.11.13 (64-bit runtime)
Python platform: Linux-5.14.0-611.54.1.el9_7.x86_64-x86_64-with-glibc2.34
Versions of relevant libraries:
[pip3] executorch==1.5.1
[pip3] numpy==2.1.3
[pip3] pytorch_tokenizers==1.5.0
[pip3] torch==2.14.0
[pip3] torchao==0.18.0
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani
- Ngôn ngữ chính
- Python
- Star
- 5.1k
- Fork
- 1.2k
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 684
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pytorch/executorch
-
Windows: _get_flatc_path() looks for data/bin/flatc but the wheel ships flatc.exe (WinError 2)Có thể đã có người làm @JacobSzwejbka đã nhận 2 ngày trước. Đang mởbug module: exir triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
pytorch/executorch#23989 · 1 reaction · 3 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Portable remainder kernel: wrong sign for integers and float64 rounded to floatCó thể đã có người làm @JakeStevens đã nhận 11 ngày trước. Đang mởbug module: kernels triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
pytorch/executorch#23682 · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement triaged
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 68/100
pytorch/executorch#21640 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
pytorch/executorch#24125 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
pytorch/executorch#24106 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của pytorch/executorch
Issue tương tự
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
sergey-miryanov/gcmon#230 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Azure-Samples/azure-search-openai-demo#3249 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] Failed archive extraction deletes the dataset cacheCó thể đã có người làm @dajiaohuang đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
alibaba/GraphScope#4674 ·