Skip to content

fix(data-plane): preserve tensor layouts and avoid int16 widening - #4263

Merged
ZhiyuLi-Nvidia merged 2 commits into
NVIDIA-NeMo:mainfrom
Alvorecer721:fix/data-plane-broadcast-layout-bytes
Oct 10, 2026
Merged

ZhiyuLi-Nvidia merged 2 commits into
NVIDIA-NeMo:mainfrom
Alvorecer721:fix/data-plane-broadcast-layout-bytes

Conversation

@Alvorecer721

@Alvorecer721 Alvorecer721 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Preserves noncontiguous tensor values in replica leader broadcasts and eliminates int16 widening buffers.

The broadcast descriptor carries shape/dtype/device, while receiving ranks allocate contiguous storage. Sending a transposed tensor without normalizing its layout therefore changes its logical values with Gloo: [[0, 3], [1, 4], [2, 5]] arrives as [[0, 1], [2, 3], [4, 5]]. NCCL also requires contiguous input. The local data plane can preserve tensor views, so this is not guaranteed by the caller.

Two separate signed-off commits:

  1. Stage ordinary tensor fields in contiguous logical order on the transport device, preserving the leader's original tensor view and device. Request contiguous format during a device transfer to avoid an extra staging copy; retain .contiguous() because .to() can return its input unchanged when dtype and device already match.
  2. Broadcast ordinary and packed int16 payloads through uint8 views of their original bytes. This preserves the complete signed-int16 range, halves wire bytes relative to int32 widening, and removes widening/narrowing allocations. Scalars are flattened before reinterpretation.

Packed metadata, segment deduplication, preprocessing settings, and per-field staging remain unchanged. The patch changes only the broadcast helper and its tests; there are no dependency or configuration changes.

Issues

Fixes #4262

Usage

Applies automatically to replica leader broadcasts. To run the focused tests in a configured upstream environment:

uv run --group test pytest tests/unit/data_plane/test_leader_broadcast.py -q

CPU tests use two Gloo ranks; NCCL coverage requires two CUDA devices.

Before your PR is "Ready for review"

Pre checks:

  • Read Contributor guidelines; commits carry DCO sign-offs and the title follows Conventional Commits.
  • Added necessary tests: contiguous/transposed/sliced tensors, scalar/empty tensors, CPU/CUDA sources, both leader ranks for ordinary layouts, all 65,536 int16 values, and two-byte wire-size checks for ordinary/packed payloads.
  • Complete the full local test matrix (Testing Guide). Normal-package broadcast, Gym data-plane, Megatron setup, and a three-step Megatron TP2 functional smoke pass. The unmodified full suite is not green; completed attempts and remaining limitations are recorded below.
  • Updated the helper's transport documentation; no user-facing configuration changes require a documentation page.

Additional Information

Validation performed

  • Follow-up in a freshly synchronized upstream base+test environment: all 14 tests in tests/unit/data_plane/test_leader_broadcast.py pass through normal package imports, including all five NCCL cases and the mixin-default test. No exclusions or skips in this file. Python 3.13.14, Ray 2.56.1, Transformers 5.12.1, TransferQueue 0.1.9, Lens 0.2.0+b0f977d, Torch 2.11.0+cu130, NCCL 2.28.9. The earlier isolated results below are retained for context.
  • Megatron functional smoke passed: tests/functional/sft_v2_energon.sh policy.megatron_cfg.tensor_model_parallel_size=2, using Qwen2.5-VL-3B, the local data plane, two GH200 GPUs, and three optimizer steps. Losses were 6.2562, 5.8304, and 7.5371; checkpoint saving and the script's finite-loss check passed. This is training integration coverage, not a convergence or numerical-parity claim.
  • The functional test used the exact locked Megatron environment (Bridge 1f8873bb, MCore 6a366090, TE 2.18.0) inside the v0.7.0 base container. Its first attempt failed because cuDNN loaded duplicate graph libraries from the Python environment and base container. Session-local library aliases made both filename forms resolve to the same locked cuDNN installation; a standalone convolution reproducer and the unchanged functional test then passed. No PR source or dependency pins were changed.
  • Package validation completed with qualified coverage: default-suite attempts plus targeted backend checks record 7,782 distinct passing test node IDs, deduplicated across retries. This includes 552 data-plane cases (all 32 tests in the three Gym-dependent data-plane modules) and 259 Megatron setup cases. The distributed continuation passed all 108 selected runnable cases after allowing the temporary Megatron environment to finish shared-filesystem cleanup; two unsupported collectives remained skipped.
  • The full matrix is not green. Ten cases retain failed outcomes: a recipe dry-run invokes a privileged audio installer; DailyOmni lacks optional torchaudio; three vLLM generation cases fail with cuBLAS initialization errors; two telemetry tests fail on metric-registration order; and three Llama-2 FLOPs cases receive Hugging Face HTTP 403. There are 46 recorded runtime skips, plus module-level collection skips/backend exclusions; 11 data-plane cases require unavailable mlx5 RDMA. No unrelated production source was changed to address these.
  • The unmodified whole-suite attempt also exposed a TransferQueue worker unpickle error (No module named megatron) and blocked client. That exact case and the complete data-plane group pass in fresh processes; the interaction remains unresolved. A later vLLM generation attempt was interrupted cleanly after a worker initialization error left its controlling test blocked. Its unfinished generation cases remain unqualified; the other model files passed 539 additional cases in a fresh continuation. Test selections and earlier failures are retained. A cold OpenMathInstruct-2 timeout passed on retry.
  • Both new regression categories fail before their respective changes.
  • Two GH200 GPUs, PyTorch 2.11.0+cu130, NCCL 2.28.9: 13 focused tests passed in each of two complete final runs, including five NCCL cases, with and without diagnostic logging.
  • These runs execute the exact helper and complete real PackedTensor/BatchedDataDict class source with isolated imports. Test bodies are unchanged; Gloo/NCCL collectives are real. One unrelated default-mixin-method test was excluded. This validates helper behavior, not full-package imports, training, or upstream CI.
  • One initial NCCL case hit the inherited process-join timeout. Its isolated retry and both complete final runs passed without changing the candidate; the timeout's cause is unresolved.
  • Ruff 0.9.9 lint, import-order, and format checks pass. The configured Pyrefly check reports zero shown errors for the changed module. Full-project pre-commit/type checks have not been run.

Measured allocation benefit

For a contiguous 64 MiB int16 payload sourced on CPU, three repeated two-rank NCCL measurements reduce peak extra PyTorch CUDA allocation from 256 MiB to 64 MiB on both sender and receiver. Wire payload drops from 128 MiB to 64 MiB. Every received value is checked exactly.

These measurements exclude preexisting input storage, allocator-reserved memory, and NCCL allocations outside PyTorch. They establish a helper-level allocation reduction, not total training-memory or throughput gains.

CI request

This PR is ready for maintainer review. The complete local matrix and upstream CI are not yet passing; the package and training checks above are the current evidence. Could a maintainer assign the appropriate CI tier (suggested CI:L1 because this changes training-input transport) and authorize testing of c4871a09ed95d758f51e88e0f13cce0be95783dc with /ok to test <full-sha> after review? I do not have permission to set upstream labels or authorize external-fork CI.

@copy-pr-bot

copy-pr-bot Bot commented Sep 25, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

Thanks @Alvorecer721 for the fix! LGTM! Just several nit questions.

  1. Behaviour change worth noting in the description: with NCCL + CPU-sourced TQ data, the leader previously kept the GPU staging copy in out; it now returns its original CPU tensors (matching followers). Good for peak GPU memory, at the cost of one extra copy to the GPU on the leader downstream. Intended?

  2. Is there an observed failure behind the strided-layout fix? All current producers on this path (value[indices], to_padded_tensor, F.pad, torch.full) return contiguous tensors. Fine as hardening; just want the commit message to be accurate.

  3. Could you paste a run of the -k nccl tests? They skip without 2 GPUs, and NCCL is the production backend.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Oct 6, 2026

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Verified old vs new logic on 2× GB300 / NCCL 2.30.7:

  • Correct: int8 / int16 / int32 (incl. -1, min/max), CPU + CUDA source, contiguous + permuted.
  • Fixes a hang: old path with a non-contiguous CUDA tensor raises Tensors must be contiguous on the leader while followers hang.
  • int16, 384 MiB: 2.3 → 0.8 ms (CUDA source); peak extra GPU memory ~1.5 GiB → ≤384 MiB.

@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia enabled auto-merge (squash) October 8, 2026 00:25
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

/ok to test afc9d6c

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia added Run CICD CI:L1 Run doctests, unit tests, and functional tests labels Oct 8, 2026
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia force-pushed the fix/data-plane-broadcast-layout-bytes branch from afc9d6c to b1870b4 Compare October 9, 2026 06:50
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

/ok to test b1870b4

Stage ordinary tensors in contiguous logical order without replacing the source tensor. Restore receiver device types and release temporary staging between fields. Add real Gloo/NCCL regressions for strided, scalar and empty tensors from either sender rank.

Signed-off-by: Alvorecer721 <[email protected]>
Send ordinary and packed int16 payloads through uint8 views of their existing storage instead of widening to int32. Preserve packed metadata and check the complete signed int16 domain and exact two-byte payload size on Gloo and NCCL.

Signed-off-by: Alvorecer721 <[email protected]>
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia force-pushed the fix/data-plane-broadcast-layout-bytes branch from b1870b4 to ba7f315 Compare October 9, 2026 17:29
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

/ok to test ba7f315

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-customer Waiting on the original author to respond labels Oct 10, 2026
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia merged commit 9d4ab56 into NVIDIA-NeMo:main Oct 10, 2026
142 of 145 checks passed
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Oct 11, 2026
ZhiyuLi-Nvidia pushed a commit that referenced this pull request Oct 11, 2026
ZhiyuLi-Nvidia pushed a commit that referenced this pull request Oct 11, 2026
ZhiyuLi-Nvidia pushed a commit that referenced this pull request Oct 12, 2026
yuki-97 pushed a commit that referenced this pull request Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests community-request Run CICD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leader broadcast corrupts noncontiguous tensor values

3 participants