Skip to content

[PyTorch] Avoid concatenation copies for compiled split Linear parameters - #3623

Draft
pggPL wants to merge 27 commits into
NVIDIA:mainfrom
pggPL:split_parameters_linear
Draft

pggPL wants to merge 27 commits into
NVIDIA:mainfrom
pggPL:split_parameters_linear

Conversation

@pggPL

@pggPL pggPL commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Compiled te.Linear(parameters_split=...) can consume adjacent parameter parts
without a concatenation copy. Pass the original parts through the custom op and
construct a checked view inside the consumer, preserving separate Parameters,
state-dict names and gradients. Disjoint or noncontiguous parts use concatenation.

This PR targets upstream main and adds split-parameter compile support only to
te.Linear. ConcatInput[T] describes an ordinary operand or immutable
ParameterParts. A single concat_input helper keeps singleton tensors unchanged,
uses noop_cat in eager, and defers supported compiled operands. Original parts
cross the op boundary; fake implementations receive metadata and the real
consumer constructs the view. Linear retains its existing final configuration
validation and setup_saved_tensors(ctx) hook.

Type of change

  • Non-breaking performance improvement and bug fix

Changes

  • Make the early fallback check inspect original parameters without
    concatenating them; retain final validation of the prepared op arguments.
  • Save original parts through autograd and split full gradients outside the
    backward op; recheck storage adjacency on each execution.
  • Preserve dtype promotion under autocast and copy lazy negative/conjugate views.
  • Keep returned or unfused split biases as traceable concatenations under compile.

Validation and remaining work

  • Earlier validation on 5d5c1802, before merging main and removing the separate
    frozen-weight bias-gradient fix: RTX 5880 Ada, PyTorch 2.15 development
    build/CUDA 13.4, compatible prebuilt
    native TE extension: complete test_torch_compile.py passed (187 passed,
    46 skipped, 1 existing non-strict xfail passed). Includes 45 focused split/API
    cases covering storage and parameter replacement, CUDA Graphs, saved hooks,
    version checks, gradient targets, recipes and returned bias.
  • Current source: pre-commit, Black, full Python L0 lint (10.00/10), license,
    AST and whitespace checks passed. Both backward functions match upstream main;
    only the bias-only variant was removed from the selective-gradient test.
    GPU regression tests have not been rerun after these changes.
  • Performance work remains: disjoint storage can be concatenated repeatedly in
    backward, and earlier split-projection measurements found host overhead for
    small shapes. Ordinary-Linear CPU latency has not been benchmarked. No general
    speedup or Blackwell/distributed validation is claimed.

Checklist

  • Added tests and updated the Linear parameter documentation
  • Run full Python L0 lint
  • Rerun GPU regression tests on this revision
  • Complete performance validation and human review before marking ready

pggPL added 15 commits October 5, 2026 11:42
…ters

Pass split Linear parameters through the custom-op boundary, reconstruct checked views at execution time and split full gradients outside backward. Preserve concatenation for disjoint storage and returned biases, handle promoted dtypes, and compute bias gradients when weights are frozen.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Replace ConcatenatedTensor with DeferredCat(parts), expose metadata through to_spec and keep materialization inside the custom op. Preserve deferred backward operands for non-FP8 training, reject quantized parts, and make dimension checks consume explicit metadata.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Keep singleton operands unwrapped and represent split parameters with immutable ParameterParts through the ConcatInput alias. Centralize eager and compiled input preparation, let the custom-op adapter restore saved parts, and select the execution path before concatenating parameters. Name backward weights by their role and update the existing MLA caller.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Restore compile_unsupported_reason, setup_saved_tensors(ctx), the original backward operand names, and the existing adapter contract. Remove the unrelated MLA changes. Retain the parameter-parts alias and helper, split-parameter correctness fixes, and focused regression coverage.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Use None when Linear has no deferred parameter parts, including eager
forward, saved backward arguments and compile fallbacks. This avoids
allocating empty weight and bias lists on the ordinary eager path.

Transport Optional[List[Tensor]] through Tensor[]? custom-op inputs,
preserving None without allocating replacement lists. Keep split-gradient
handling outside the backward op and let the adapter supply absent list
gradients when needed.

Cover ordinary and optional lists, empty lists and None in the adapter
test. Validate the full compile suite (384 passed, 62 skipped, one existing
XPASS), 55 focused cases, 30 numerical Linear cases, pre-commit and Python
L0 lint.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Use the same checked view or concatenation in eager and compiled Linear.
Pass individual parts as explicit autograd inputs and save the materialized
operands for eager backward, which returns views of the full gradients.
Preserve the single-parameter and external-bias paths.

Derive the view strides directly from contiguous parts to avoid symbolic
stride-helper overhead. Extend the existing storage and cat-count tests.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
@pggPL

pggPL commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator Author

TE CI — selected tests

Pipeline ID: 77100152 · Commit: ddb3eaae745e9edb78cbb5fa092d2151877f55c7

Selected CI jobs and pytest filters are listed below.

Frameworks: PyTorch

Mode: PR Python, tests and QA with prebuilt native libraries; no TE rebuild.
Native image digest: sha256:46ede145e9eac17945e528111d8f074d501d83d9c4ef67db651cd127f3dc3dec

Selected jobs: 1

  • L0_pytorch_unittest--H100_1GPU

Not run (manual/skipped): 14

Show jobs not run
  • L0_pytorch_debug_unittest--B200_1GPU
  • L0_pytorch_debug_unittest--H100_1GPU
  • L0_pytorch_lint
  • L0_pytorch_unittest--A100_1GPU
  • L0_pytorch_unittest--B200_1GPU
  • L1_pytorch_distributed_unittest--B200_8GPU
  • L1_pytorch_distributed_unittest--H100_4GPU
  • L1_pytorch_mcore_fsdp_integration--B200_8GPU
  • L1_pytorch_mcore_integration--B200_1GPU
  • L1_pytorch_mcore_integration--H100_1GPU
  • L1_pytorch_onnx_unittest--B200_1GPU
  • L1_pytorch_onnx_unittest--H100_1GPU
  • L3_pytorch_FA_versions_test--B200_8GPU
  • L3_pytorch_FA_versions_test--H100_4GPU

Results are reported as individual commit statuses on this PR.

@pggPL

pggPL commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator Author

TE CI — selected tests

Pipeline ID: 77114224 · Commit: ddb3eaae745e9edb78cbb5fa092d2151877f55c7

Selected CI jobs and pytest filters are listed below.

Frameworks: PyTorch

Mode: PR Python, tests and QA with prebuilt native libraries; no TE rebuild.
Native image digest: sha256:46ede145e9eac17945e528111d8f074d501d83d9c4ef67db651cd127f3dc3dec

Pytest include: tests/pytorch/test_torch_compile.py, tests/pytorch/test_sanity.py

Job results cover this pytest subset. Non-pytest QA commands are unchanged.

Selected jobs: 1

  • L0_pytorch_unittest--B200_1GPU

Not run (manual/skipped): 14

Show jobs not run
  • L0_pytorch_debug_unittest--B200_1GPU
  • L0_pytorch_debug_unittest--H100_1GPU
  • L0_pytorch_lint
  • L0_pytorch_unittest--A100_1GPU
  • L0_pytorch_unittest--H100_1GPU
  • L1_pytorch_distributed_unittest--B200_8GPU
  • L1_pytorch_distributed_unittest--H100_4GPU
  • L1_pytorch_mcore_fsdp_integration--B200_8GPU
  • L1_pytorch_mcore_integration--B200_1GPU
  • L1_pytorch_mcore_integration--H100_1GPU
  • L1_pytorch_onnx_unittest--B200_1GPU
  • L1_pytorch_onnx_unittest--H100_1GPU
  • L3_pytorch_FA_versions_test--B200_8GPU
  • L3_pytorch_FA_versions_test--H100_4GPU

Results are reported as individual commit statuses on this PR.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
@pggPL

pggPL commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

TE CI — selected tests

Pipeline ID: 77123759 · Commit: f5a13d2515cd40a83e21cb364dfe8907adff1178

Selected CI jobs and pytest filters are listed below.

Frameworks: PyTorch

Mode: PR Python, tests and QA with prebuilt native libraries; no TE rebuild.
Native image digest: sha256:46ede145e9eac17945e528111d8f074d501d83d9c4ef67db651cd127f3dc3dec

Pytest exclude: tests/pytorch/test_fused_rope.py, tests/pytorch/test_permutation.py, tests/pytorch/test_cross_entropy.py, tests/pytorch/test_mhc.py, tests/pytorch/test_fused_router.py, tests/pytorch/test_fused_router_perf.py

Job results cover this pytest subset. Non-pytest QA commands are unchanged.

Selected jobs: 7

  • L0_pytorch_debug_unittest--B200_1GPU
  • L0_pytorch_debug_unittest--H100_1GPU
  • L0_pytorch_lint
  • L0_pytorch_unittest--A100_1GPU
  • L0_pytorch_unittest--B200_1GPU
  • L0_pytorch_unittest--H100_1GPU
  • L0_pytorch_unittest--L40_1GPU

Not run (manual/skipped): 9

Show jobs not run
  • L1_pytorch_distributed_unittest--B200_8GPU
  • L1_pytorch_distributed_unittest--H100_4GPU
  • L1_pytorch_mcore_fsdp_integration--B200_8GPU
  • L1_pytorch_mcore_integration--B200_1GPU
  • L1_pytorch_mcore_integration--H100_1GPU
  • L1_pytorch_onnx_unittest--B200_1GPU
  • L1_pytorch_onnx_unittest--H100_1GPU
  • L3_pytorch_FA_versions_test--B200_8GPU
  • L3_pytorch_FA_versions_test--H100_4GPU

Results are reported as individual commit statuses on this PR.

Merge main 9b7e959.
Preserve the existing seven-file split Linear change without conflicts.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
pggPL added a commit to pggPL/TransformerEngine that referenced this pull request Oct 28, 2026
Restore the tree from 917773b. The split-parameter support belongs in PR NVIDIA#3623.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
pggPL added 9 commits October 28, 2026 15:20
Share Linear's checked view/cat helper for split weights and fused biases.
Pass the parts as explicit autograd inputs, save full operands for backward
and return views of the full parameter gradients.

Keep backward computation and saved-tensor restoration unchanged. Compute
split shapes only when configuring weight quantization, and extend the
existing cat-count regression to eager LayerNormLinear.

Remove standalone storage-helper and tensor-list adapter tests at the
user's request.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Replace five split-parameter tests with one parameterized integration test.
Cover gradients, inference, recipes, bias modes, storage and parameter updates,
saved-version checks and concatenation counts in a shared execution flow.
Use ordinary torch.cat in the reference to verify deferred gradient routing.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Rely on concat_input to select nonempty ordinary tensor lists. Preserve
storage, layout, offset and bounds checks before reconstructing a view.

Extend the shared integration test with LayerNormLinear recipes and dtype/
split variants, plus mixed parameter dtypes under autocast. Keep dtype
promotion in fake concatenation to match torch.cat metadata.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Remove the deferred-concatenation switch from Linear and LayerNormLinear
parameter getters. Keep bias routing in the getters and explicitly
concatenate deferred operands in the ONNX inference paths.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Rename concat_input to prepare_parameter and drop the tensors suffix
from the Linear and LayerNormLinear getters, which can return split lists.
Use the same forward operand names in LayerNormLinear as in Linear.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Use the presence of parameter_split_sizes to select gradient splitting
in eager Linear and LayerNormLinear backward instead of counting the
fixed positional autograd inputs.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Restore parameter lists from named input-list lengths already tracked by
the custom-op adapter. Remove the duplicate lengths and the saved weight
alias flag from Linear backward arguments. Resolve a missing plain split
weight in the existing backward workspace reconstruction path.

Extend the split integration test with workspace caching, reconstruction
and high-precision/dequantized backward overrides.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Move selected split scenarios into the Linear compile and LayerNormLinear
sanity tests, and add a split case to the existing microbatch cache test.
Share parameter-update assertions and remove the standalone split test.
Append complete scenarios without multiplying the existing parameter axes.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Move the parameter-update helper from the shared test utilities into
test_torch_compile.py and name it _check_module_outputs_and_grads.
Restore the shared utility module to its upstream contents.

Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant