Masked bf16 attention rounds its scores to bf16 on Jetson Thor (sm_110), but not on A100
Maintainer thường phản hồi trong vòng 6 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 8/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
- machine-learning
Hướng nghiên cứu
The repro is a single Python script that compiles one scaled_dot_product_attention with Torch-TensorRT and prints channel 0 for no mask, a bool mask and a float mask. Run it on a Jetson AGX Thor and on an A100 to confirm the masked outputs differ. Done means the masked Thor output matches the float32-score result (+0.4219) and the random-input error falls back to about the PyTorch level, which needs a fix inside TensorRT's attention kernels.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What is wrong
On Jetson AGX Thor, a bf16 attention layer with a mask (bool or additive float) computes its softmax scores in
bf16. Without a mask it keeps them in float32. On A100 (sm_80), with the same
TensorRT, the masked layer keeps float32 scores, like PyTorch.
When 2 scores are close, bf16 rounding makes them equal, so the softmax weights change. On random inputs the error
grows about 13 times.
What this blocks
On Jetson Thor, evo1 misses its accuracy check and fails (pytorch/executorch#24353).
lingbot_vla_v2 passes there only because LeRobot keeps its attention out of TensorRT on Thor. That splits it into hundreds of pieces and makes it slower than eager PyTorch.
A fix lets both use fused attention on Thor, as they do on the other GPUs.
Repro
The script compiles one scaled_dot_product_attention with Torch-TensorRT, which builds one IAttention layer.
A query and 2 keys are chosen so that their scaled scores (200.45 and 199.55) round to the same bf16 value. With
float32 scores, output channel 0 is +0.42. With bf16 scores it is 0.
import torch, torch.nn.functional as F, torch_tensorrt, tensorrt
B, H, L, S, D = 8, 8, 50, 805, 64
dev = "cuda"
class Attention(torch.nn.Module):
def forward(self, q, k, v, mask=None):
return F.scaled_dot_product_attention(q, k, v, attn_mask=mask)
def near_tie():
q = torch.zeros(B, H, L, D, device=dev); q[..., 0], q[..., 1] = 16.0, 2.0
k = torch.zeros(B, H, S, D, device=dev)
k[..., 0, 0], k[..., 0, 1] = 100.0, 1.796875
k[..., 1, 0], k[..., 1, 1] = 100.0, -1.796875
v = torch.zeros(B, H, S, D, device=dev); v[..., 0, 0], v[..., 1, 0] = 1.0, -1.0
return q.bfloat16(), k.bfloat16(), v.bfloat16()
def random_qkv():
g = torch.Generator(device=dev).manual_seed(0)
return tuple((torch.randn(B, H, n, D, device=dev, generator=g) * s).bfloat16()
for n, s in ((L, 2.0), (S, 3.0), (S, 1.0)))
def reference(q, k, v, mask):
s = q.double() @ k.double().transpose(-2, -1) / D**0.5
if mask is not None:
s = s.masked_fill(~mask, float("-inf")) if mask.dtype == torch.bool else s + mask.double()
return s.softmax(-1) @ v.double()
keep = torch.ones(B, 1, 1, S, dtype=torch.bool, device=dev)
keep[1::2, ..., S - S // 8:] = False # key padding; keys 0 and 1 stay visible
additive = torch.zeros(B, 1, 1, S, device=dev).masked_fill(~keep, float("-inf")).bfloat16().expand(B, H, 1, S).contiguous()
print(torch.cuda.get_device_name(), torch.cuda.get_device_capability(), "TensorRT", tensorrt.__version__)
model = Attention().eval()
for name, mask in (("none", None), ("bool", keep), ("float", additive)):
args = near_tie() + (() if mask is None else (mask,))
trt = torch_tensorrt.dynamo.compile(torch.export.export(model, args), arg_inputs=list(args), min_block_size=1)
with torch.no_grad():
tie = trt(*args)[..., 0].float().mean().item()
rargs = random_qkv() + (() if mask is None else (mask,))
ref = reference(*rargs[:3], mask)
ok = torch.isfinite(ref)
err_trt = (trt(*rargs).double() - ref)[ok].abs().max().item()
err_pt = (model(*rargs).double() - ref)[ok].abs().max().item()
print(f"mask={name:5} channel 0: {tie:+.4f} (float32 scores give +0.4219); "
f"random max error vs float64: TensorRT {err_trt:.4f}, PyTorch {err_pt:.4f}")
Results
| no mask | bool mask | float mask | random error, masked | |
|---|---|---|---|---|
| Thor (11,0) | +0.4219 | +0.0000 | +0.0000 | 0.1206 (PyTorch 0.0090) |
| A100 (8,0) | +0.4219 | +0.4219 | +0.4219 | 0.0106 (PyTorch 0.0106) |
Versions: torch 2.15.0 (CUDA 13.2), torch_tensorrt 2.15.0, TensorRT 11.4.0.106 (all from pip install "torch_tensorrt[executorch]"). Thor: JetPack 7.2.1, driver 595.78, CUDA 13.2.
A100: driver 580.126.09.
Actual
Jetson AGX Thor, driver 595.78:
NVIDIA Thor (11, 0) TensorRT 11.4.0.106
mask=none channel 0: +0.4219 (float32 scores give +0.4219); random max error vs float64: TensorRT 0.0090, PyTorch 0.0084
mask=bool channel 0: +0.0000 (float32 scores give +0.4219); random max error vs float64: TensorRT 0.1206, PyTorch 0.0090
mask=float channel 0: +0.0000 (float32 scores give +0.4219); random max error vs float64: TensorRT 0.1206, PyTorch 0.0090
A100 80 GB, driver 580.126.09:
NVIDIA PG509-210 (8, 0) TensorRT 11.4.0.106
mask=none channel 0: +0.4219 (float32 scores give +0.4219); random max error vs float64: TensorRT 0.0106, PyTorch 0.0106
mask=bool channel 0: +0.4219 (float32 scores give +0.4219); random max error vs float64: TensorRT 0.0106, PyTorch 0.0106
mask=float channel 0: +0.4219 (float32 scores give +0.4219); random max error vs float64: TensorRT 0.0106, PyTorch 0.0106
Expected
Float32 scores for masked attention on Thor, as on A100.
- Ngôn ngữ chính
- C++
- Star
- 13.5k
- Fork
- 2.4k
- Merge trung bình
- 6 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không 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 NVIDIA/TensorRT
-
Module:Polygraphy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 6 ngày
-
Polygraphy NumPy Top-K sorts unsigned and minimum signed integers incorrectlyCó thể đã có người làm @0z5a đã nhận 16 ngày trước. Đang mởModule:Polygraphy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 6 ngày
-
Polygraphy INT32 comparison can overflow and falsely pass at zero toleranceCó thể đã có người làm @0z5a đã nhận 16 ngày trước. Đang mởModule:Polygraphy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 6 ngày
-
onnx-graphsurgeon: Graph.toposort() hits RecursionError when a graph has a local function and an If/Loop nodeCó thể đã có người làm @gabortar đã nhận 39 ngày trước. Đang mởModule:GraphSurgeon
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 6 ngày
-
Polygraphy parse_meta accepts a shape with a missing bracketCó thể đã có người làm @SashaMIT đã nhận 51 ngày trước. Đang mởModule:Polygraphy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 6 ngày
Tất cả issue của NVIDIA/TensorRT
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/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 69/100
maplibre/maplibre-native#5072 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[UBSan] spawn_simulator passes null child_options.args to uv_spawn (execvp nonnull violation)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
tenstorrent/tt-umd#4017 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
difficulty:easy func:gui prio:low type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NatronGitHub/Natron#1538 ·
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 72/100
hyprwm/hyprsunset#103 · 1 bình luận ·