Skip to content

Trn2: eager torch.cat(dim=1) producing a ~9.4e9-byte fp32 output silently returns wrong data (63% of elements); exact at ≤8.7e9 bytes #1502

In review

Description

@scttfrdmn

Summary: on Trn2, eager torch.cat(chunks, dim=1) on neuron tensors returns a silently wrong result when the output is about 9.4e9 bytes. 63% of the elements differ from the host result and no error is raised. The same call is bitwise exact at 4.7e9, 8.19e9 and 8.70e9 bytes. Every input chunk is under 2³¹ bytes.

Environment: trn2.3xlarge, Deep Learning AMI Neuron torch-neuronx 2.14.0 (Ubuntu 24.04) SDK 2.33.1, torch-neuronx 2.14.3, neuronx-cc 2.28.7631, runtime 2.35.33, LNC=2, one logical core (NEURON_RT_VISIBLE_CORES=3).

Reproduction (python cat_large_repro.py E F K):

import sys, time, numpy as np, torch, torch_neuronx  # noqa: F401
E, F, K = int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3])   # rows, total cols, chunks
rng = np.random.default_rng(0)
host = rng.standard_normal((E, F), dtype=np.float32)
w = F // K
chunks = [torch.from_numpy(np.ascontiguousarray(host[:, k*w:(k+1)*w])).to("neuron") for k in range(K)]
t = time.time(); out = torch.cat(chunks, dim=1); out_h = out.cpu().numpy(); dt = time.time() - t
bad = np.count_nonzero(out_h != host)
print(f"E={E} F={F} K={K} out_bytes={E*F*4:.3e} mismatched_elements={bad} of {E*F} cat+copy_s={dt:.1f}")
if bad:
    r, c = np.nonzero(out_h != host); print("first bad (row,col):", r[0], c[0], "last:", r[-1], c[-1], "rows affected:", np.unique(r).size)
E × F (5 chunks of F/5) output bytes mismatched elements
229376 × 5120 4.70e9 0
400000 × 5120 8.19e9 0
425000 × 5120 8.70e9 0
458752 × 5120 9.40e9 1,486,199,911 of 2,348,810,240 (rows 0…458751, 404,202 rows affected)

The failing case puts about 18.8 GB (inputs plus output) on one logical core, which may be relevant (cf. #1447). It was found while assembling feature-axis chunks of a graph-network message tensor (MACE-style, 8000 atoms). We now avoid the pattern; a single NKI launch over the full tensor is exact.

Asks:

  • fix or detect the condition;
  • at minimum, raise an error instead of returning wrong data.

Activity

  1. github-actions commented on Nov 25, 2026

    @github-actions

    Hi @scttfrdmn, Thank you for filing the issue! We will take a look and get back to you.

  2. added
    bug
    on Nov 25, 2026
  3. ahoffman-aws commented on Nov 25, 2026

    @ahoffman-aws
    Contributor

    The team reproduced the issue related to memory spans of 4 GB or more on SDK 2.33.1 and are planning to fix in a future release

  4. scttfrdmn commented on Nov 28, 2026

    @scttfrdmn
    Author

    Additional data: the same failure at LNC=1, at half the size, and it also corrupts the inputs.

    Toolchain: Trn2 trn2.3xlarge, DLAMI SDK 2.33.1, torch-neuronx 2.14.3, neuronx-cc 2.28.7631, runtime 2.35.33. Eager mode, fp32.

    Repro (aten only):

    • NEURON_LOGICAL_NC_CONFIG=1, NEURON_RT_VISIBLE_CORES=6 (one physical core);
    • torch.cat([a, b, c], dim=1) of host-generated device tensors of shapes (E, 2048), (E, 2048) and (E, 1024);
    • then compare the result, and the inputs re-read after the cat, with the host values.
    LNC E output bytes cat wrong elements inputs wrong after the cat
    1 229376 4.70e9 (> 2^32) 751,268,366 of 1,174,405,120 input 0: 0; input 1: 251,657,211; input 2: 234,879,997
    1 98304 2.01e9 0 none
    2 229376 4.70e9 0 none
    2 98304 2.01e9 0 none

    The original report (LNC=2) failed at about 9.4e9 output bytes and was exact up to 8.7e9. At LNC=1 the same pattern fails at 4.7e9 and is exact at 2.0e9.

    The threshold roughly doubles from LNC=1 to LNC=2. That suggests an addressing limit of about 2^32 bytes per physical core in the cat lowering; the exact LNC=2 boundary (between 8.7e9 and 9.4e9) is not pinned down:

    • it breaks past 2^32 bytes at LNC=1;
    • it breaks somewhere past about 2^33 at LNC=2, where the logical core spans two physical cores.

    The writes also land in the memory of the cat's own inputs: inputs 1 and 2 are corrupted afterwards. So any later use of those tensors is wrong too, still with no error raised.

    Downstream tracking: trnsci/trnsparse#150.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Trn2bugtraining

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions