Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
f3401df
[PyTorch] Make tensorless quantizers opaque value objects for torch.c…
pggPL Jun 6, 2026
c4ad54c
[PyTorch] Drop quantizer value registry; reconstruct via __fx_repr__ …
pggPL Jun 6, 2026
a06324b
[PyTorch] Split dynamo.py into a dynamo/ package
pggPL Jun 7, 2026
ea5b396
[PyTorch] Raise in quantizer __fx_repr__ when a process group is stored
pggPL Jun 8, 2026
aa65e34
[PyTorch] Cover NVFP4 in quantizer value-object test
pggPL Jun 8, 2026
e1b1db6
Reject a value quantizer that carries an amax reduction group in __eq…
pggPL Jun 16, 2026
8c33d0e
Recognize value-opaque quantizers via a class flag
pggPL Jun 16, 2026
945f62d
Address review: narrow opaque-type except, add fullgraph test, fix nv…
pggPL Jun 29, 2026
e3c8f43
Restore NVFP4 rht_matrix on value-key rebuild; assert quantize round-…
pggPL Jun 29, 2026
3f68621
Enforce process-group rejection in _value_key, not __fx_repr__; add test
pggPL Jun 29, 2026
32d1768
Strengthen fullgraph test: quantize/dequantize via a custom op, not p…
pggPL Jun 29, 2026
28bde9e
Clarify comments: rht_matrix_random_sign_mask_t derivation; why the o…
pggPL Jun 29, 2026
2c3c5df
Reword opaque-flag comment: self-contained, no Linear reference
pggPL Jun 29, 2026
826f271
Cover is_opaque_value_type with the import-safety guard too
pggPL Jun 29, 2026
ad1ccce
Add TensorProto mechanism for data-free quantized tensor allocation
pggPL Jun 16, 2026
ea3df7a
[PyTorch] torch.compile: dedup cached FP8 weight from saved-for-backward
pggPL Jun 22, 2026
4997929
[PyTorch] nvfp4: emit _describe_buffers in canonical flatten order
pggPL Jun 22, 2026
50c11cd
Address review: error on undescribed buffers, gate nvfp4 test on HW s…
pggPL Jun 29, 2026
ff48e52
[PyTorch] Workaround torch.compile staticmethod guard bug in NVFP4 _d…
pggPL Jun 29, 2026
e1e271c
[PyTorch] torch.compile: wrap pybind11 UB methods as compile-time con…
pggPL Jun 15, 2026
598a07c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 15, 2026
05af2a0
Provide explicit QuantizerRoles in torch.compile custom-recipe test
pggPL Jun 16, 2026
9bd16fd
Add torch.compile custom-op path for Linear
pggPL Jun 16, 2026
fdac659
[PyTorch] torch.compile: register TE custom ops via torch.library.cus…
pggPL Jun 22, 2026
554f5a8
[PyTorch] custom_op: note pytorch/pytorch#187434 enables dropping Non…
pggPL Jun 30, 2026
6d3eece
Add TensorProto mechanism for data-free quantized tensor allocation
pggPL Jun 16, 2026
4bdaa60
[PyTorch] torch.compile: dedup cached FP8 weight from saved-for-backward
pggPL Jun 22, 2026
3be6fc7
[PyTorch] nvfp4: emit _describe_buffers in canonical flatten order
pggPL Jun 22, 2026
8a9d90c
Address review: error on undescribed buffers, gate nvfp4 test on HW s…
pggPL Jun 29, 2026
e36cf6d
[PyTorch] Workaround torch.compile staticmethod guard bug in NVFP4 _d…
pggPL Jun 29, 2026
90fc494
[PyTorch] Document TensorOrQuantized union (review feedback)
pggPL Jul 13, 2026
a3bf5c1
[PyTorch] Add shape property to QuantizedTensorStorage
pggPL Jul 13, 2026
37b0d17
[PyTorch] Test parity of Python alloc vs C++ make_empty
pggPL Jul 13, 2026
4feacdc
[PyTorch] Simplify comment on captured requires_grad flags
pggPL Jul 13, 2026
5adb6e4
[PyTorch] Drop redundant None guards in wt_save alias dedup
pggPL Jul 13, 2026
40d2d7b
[PyTorch] Use torch._prims_common.make_contiguous_strides_for
pggPL Jul 13, 2026
78e95a6
[PyTorch] Raise on update_usage of a non-quantized TensorProto
pggPL Jul 13, 2026
b3229cc
[PyTorch] Collapse to_tensor_proto branches
pggPL Jul 13, 2026
2b19368
[PyTorch] Drop dead weight_fp8 fallback in fake backward
pggPL Jul 13, 2026
c3dec83
[PyTorch] Drop redundant comment on saved_weight
pggPL Jul 13, 2026
cb53cc3
Merge branch 'main' of https://github.com/NVIDIA/TransformerEngine in…
pggPL Jul 13, 2026
ce230b7
[PyTorch] Rename _Bucket.pack/unpack to to_slots/from_slots
pggPL Jul 15, 2026
4600cc4
[PyTorch] Drop dead weight_fp8 fallbacks for saved_weight in backward
pggPL Jul 15, 2026
a5dccf5
[PyTorch] Drop underscore prefixes on fake-backward dgrad locals
pggPL Jul 15, 2026
acdaa91
[PyTorch] Trim verbose cublas_workspace field comment
pggPL Jul 15, 2026
d405c3b
[PyTorch] Handle PEP 604 X | Y unions in annotation introspection
pggPL Jul 15, 2026
b1b24bf
[PyTorch] Note None in _UniversalTensorBucket docstring
pggPL Jul 15, 2026
94fcf82
[PyTorch] Match universal-tensor field by exact TensorOrQuantized mem…
pggPL Jul 15, 2026
75f41a9
[PyTorch] Keep OpaqueValueBundle _frozen consistent when tagging __ki…
pggPL Jul 15, 2026
c6cd8e1
[PyTorch] Collapse _QuantizerBucket.try_build guard into one condition
pggPL Jul 15, 2026
754f0a4
[PyTorch] Rename _UniversalTensorBucket -> _TensorOrQuantizedBucket
pggPL Jul 15, 2026
6536692
[PyTorch] Document that _SimpleBundleBucket is one-per-op
pggPL Jul 15, 2026
5b752be
[PyTorch] Rename _UnknownBucket -> _UnsupportedBucket, document behavior
pggPL Jul 15, 2026
7482658
[PyTorch] Keep _UnsupportedBucket docstring framework-generic
pggPL Jul 15, 2026
011c268
[PyTorch] Make _Bucket.to_slots return a dict
pggPL Jul 15, 2026
e5d4985
[PyTorch] Move proto reassembly into TensorProto.assemble
pggPL Jul 15, 2026
a01c774
[PyTorch] Dedup flatten branches in _value_to_flat_tensors
pggPL Jul 15, 2026
858603c
[PyTorch] Use explicit None check for saved-tensors slot (review nit)
pggPL Jul 15, 2026
55de0e2
[PyTorch] Drop dead tensor_objects slot from fwd-impl return contract
pggPL Jul 15, 2026
5947035
[PyTorch] Validate fwd-impl return contract at the boundary
pggPL Jul 15, 2026
d1c0827
[PyTorch] Run fwd-result check only on the fake path (compile-time)
pggPL Jul 15, 2026
b70bf8c
[PyTorch] Document the custom-op callable + arg-container contract
pggPL Jul 15, 2026
db5d902
[PyTorch] Fix eager _Linear.forward unpack after tensor_objects slot …
pggPL Jul 15, 2026
246a74f
[PyTorch] Drop redundant fwd_slot_defaults in backward grad layout
pggPL Jul 15, 2026
d55d38c
[PyTorch] Drop redundant fwd_arg_type from _resolve_grad_targets
pggPL Jul 15, 2026
c4c8313
[PyTorch] Split input_tensors_for_grad validation into existence + di…
pggPL Jul 15, 2026
197325d
[PyTorch] Rename _pack/_unpack -> _args_to_slots/_args_from_slots
pggPL Jul 15, 2026
f4e6dbe
[PyTorch] Merge backward_obj into backward_arg_type
pggPL Jul 15, 2026
7334811
[PyTorch] Check len(user_outputs) not len(user_fakes) (review nit)
pggPL Jul 15, 2026
c18b8ac
[PyTorch] Pass resolved bwd_op object to _register_autograd_for_op
pggPL Jul 15, 2026
a550a6b
[PyTorch] Drop redundant 'val is None or' in subclass flatten check (…
pggPL Jul 15, 2026
844832b
[PyTorch] Drop redundant list() copy of storage inner tensors (nit)
pggPL Jul 15, 2026
c752bbb
[PyTorch] Rename two-tier op inner/outer -> base/wrapper
pggPL Jul 15, 2026
1fe18b2
[PyTorch] Pass resolved base_op object to _register_wrapper_op
pggPL Jul 15, 2026
dd99206
[PyTorch] Add TensorProto.assemble for rebuilding from ready-made buf…
pggPL Jul 15, 2026
12ad055
Merge remote-tracking branch 'origin/tensor_proto_mechanism' into lin…
pggPL Jul 15, 2026
33f2110
[PyTorch] Rename field _Bucket -> _Adapter in custom-op framework
pggPL Jul 16, 2026
8ecd10c
[PyTorch] Add architecture overview to custom_op.py module docstring
pggPL Jul 16, 2026
7aefcdb
[PyTorch] Decouple TensorOrQuantized comment from the custom-op detail
pggPL Jul 16, 2026
2b0ab1e
[PyTorch] Drop dead getattr guard for types.UnionType in _is_union
pggPL Jul 16, 2026
f26b059
[PyTorch] Fix _SimpleBundleAdapter doc: at most one per op, not exact…
pggPL Jul 16, 2026
2d9de11
[PyTorch] Mention reference-opaque types in unsupported-field error
pggPL Jul 16, 2026
a6cca41
[PyTorch] Guard Float8 __repr__ against materializing fake tensors un…
pggPL Jul 16, 2026
d1b6b6e
[PyTorch] Compute quantized subclasses inside _register_wrapper_op
pggPL Jul 16, 2026
a9858cd
[PyTorch] Reword nullable-return note to not trip pylint fixme (W0511)
pggPL Jul 16, 2026
9bce3ad
[PyTorch] Drop dead rht_matrix field from LinearFwdArgs
pggPL Jul 16, 2026
2c28aa1
Merge remote-tracking branch 'upstream/main' into tensor_proto_mechanism
pggPL Jul 27, 2026
a30ea45
Merge remote-tracking branch 'upstream/main' into tensor_proto_mechanism
pggPL Jul 28, 2026
7e72013
Fix blockwise alloc parity test and drop dead CUDA skips
pggPL Jul 28, 2026
65cc334
Mirror quantize_weight's cache semantics in the Linear fake forward
pggPL Jul 28, 2026
3d10222
Honor the dequantized backward override in the Linear fake forward
pggPL Jul 28, 2026
a257fa3
Include the bias in the Linear fake output's differentiability
pggPL Jul 28, 2026
0414586
Move the Linear fake impls out to the custom-op branch
pggPL Jul 28, 2026
cb79da2
Fix three fake/eager divergences in the Linear fake forward
pggPL Jul 28, 2026
d5e1f20
Keep attributes attached to quantized parameters across _apply
pggPL Jul 29, 2026
cfe3bf2
[PyTorch] Drop _STORAGE_REGISTRY; carry the class itself in the flatt…
pggPL Jul 29, 2026
6343317
[PyTorch] Make to_tensor_proto idempotent so the weight workspace kee…
pggPL Jul 29, 2026
c0ab88d
[PyTorch] Stop re-describing the weight workspace proto in the Linear…
pggPL Jul 29, 2026
6e61d36
Fail loudly if a buffer vanishes from a parameter during _apply
pggPL Jul 29, 2026
693f592
[PyTorch] Warn once when the torch.compile registrations fall back to…
pggPL Jul 31, 2026
0228c9c
Merge remote-tracking branch 'upstream/main' into tensor_proto_mechanism
pggPL Jul 31, 2026
1523d15
[PyTorch] Trim the weight-workspace validity comment in the fake forward
pggPL Jul 31, 2026
00c4d90
Merge tensor_proto_mechanism (up to date with main) into linear_compile
pggPL Jul 31, 2026
4c4519c
[PyTorch] Drop the weight-workspace comment in the fake forward
pggPL Jul 31, 2026
a24e4e0
Raise when a parameter vanishes during _apply instead of skipping it
pggPL Jul 31, 2026
a8b8873
Drop the vanished-buffer check from _apply
pggPL Jul 31, 2026
6bb030f
Declare flat buffers on the field instead of in a parallel tuple
pggPL Jul 31, 2026
e0bbb18
Name the flat buffers after PyTorch's own term for them
pggPL Jul 31, 2026
9a4fa8a
Carry the storage class itself through the flatten context
pggPL Jul 31, 2026
984d9f6
Merge remote-tracking branch 'tp/tensor_proto_mechanism' into linear_…
pggPL Jul 31, 2026
7514cf9
Enable post-RHT amax in the NVFP4 value-object test factory
pggPL Jul 31, 2026
58f3775
Reformat test_torch_compile.py with black
pggPL Jul 31, 2026
ef427f3
[PyTorch] torch.compile: dedup cached FP8 weight from saved-for-backward
pggPL Jul 31, 2026
2dc0bcf
Take requires_grad from the args bundle, not from the input tensors
pggPL Jul 31, 2026
47229f0
Carry symbolic shapes through compile custom ops
shino16 Aug 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/pytorch/distributed/run_layer_with_overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,19 @@ def _parse_args(argv=None, namespace=None):
parser.add_argument(
"--use-cuda-graphs", action="store_true", default=False, help="Use CUDA Graphs."
)
parser.add_argument(
"--compile",
action="store_true",
default=False,
help="Wrap each layer in torch.compile (tests Userbuffers on the compiled path).",
)
parser.add_argument(
"--compile-mode",
type=str,
default="default",
choices=["default", "reduce-overhead"],
help="torch.compile mode used when --compile is set.",
)
parser.add_argument(
"--ub-cfg", type=str, default=None, help="Optional TP config yaml file input."
)
Expand Down Expand Up @@ -485,6 +498,9 @@ def dist_print(msg, src=None, end="\n", debug=False, error=False):
torch.testing.assert_close(test_param, ref_param, rtol=0.0, atol=0.0)
dist_print("Copied parameters from test model to reference model...", debug=True)

if opts.compile and opts.use_cuda_graphs:
raise ValueError("--compile and --use-cuda-graphs are mutually exclusive.")

# Fp8 recipe setup
fp8_format = Format.HYBRID
fp8_recipe = None
Expand Down Expand Up @@ -535,6 +551,18 @@ def run_fwd_bwd(model, x):
loss.backward()
return out

if opts.compile:
for i, layer in enumerate(test_model.layers):
# dynamic=False for now: symbolic shapes would land in an OpaqueValueBundle
# op arg whose hash chokes on non-nested SymInt (see run_numerics).
test_model.layers[i] = torch.compile(
layer, fullgraph=True, mode=opts.compile_mode, dynamic=False
)
dist_print(
f"Compiled test model layers with torch.compile (mode={opts.compile_mode})...",
debug=True,
)

torch_rng_state = torch.get_rng_state()
cuda_rng_state = torch.cuda.get_rng_state(torch.device(f"cuda:{LOCAL_RANK}"))
if opts.use_cuda_graphs:
Expand Down
51 changes: 46 additions & 5 deletions tests/pytorch/distributed/run_numerics.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,22 +310,45 @@ def _copy_params(model_distributed, model_single):


def _apply_models(
model_single_node, model_distributed, input_single_node, input_distributed, **kwargs
model_single_node,
model_distributed,
input_single_node,
input_distributed,
use_compile=False,
compile_mode="default",
**kwargs,
):
_alloc_main_grad(model_single_node, model_distributed) # for fuse_wgrad_accumulation=True
input_single_node.requires_grad_()
input_distributed.requires_grad_()
forward_single_node = model_single_node
forward_distributed = model_distributed
if use_compile:
# Each parametrized case compiles the same module.forward code object with
# a different shape/recipe; with dynamic=False those guards accumulate and
# eventually trip Dynamo's recompile_limit. Reset so every case starts from
# a clean compile cache (mirrors the single-GPU torch.compile tests).
torch._dynamo.reset()
# dynamic=False for now: a symbolic shape would land in an OpaqueValueBundle
# (value-opaque op arg) whose hash chokes on non-nested SymInt. Force static
# shapes (recompile per shape) until the bundle handles symbolic shapes.
forward_single_node = torch.compile(
model_single_node, fullgraph=True, mode=compile_mode, dynamic=False
)
forward_distributed = torch.compile(
model_distributed, fullgraph=True, mode=compile_mode, dynamic=False
)
with te.autocast(
enabled=QUANTIZATION is not None,
recipe=quantization_recipe(),
):
output_single_node = model_single_node(input_single_node, **kwargs)
output_single_node = forward_single_node(input_single_node, **kwargs)
with te.autocast(
enabled=QUANTIZATION is not None,
recipe=quantization_recipe(),
amax_reduction_group=NCCL_WORLD,
):
output_distributed = model_distributed(input_distributed, **kwargs)
output_distributed = forward_distributed(input_distributed, **kwargs)
return output_single_node, output_distributed


Expand Down Expand Up @@ -641,12 +664,20 @@ def test_quantized_all_gather():
# Linear #
############################################
@run_distributed_test()
def _test_linear(parallel_mode=None, sequence_parallel=False, **kwargs):
def _test_linear(
parallel_mode=None,
sequence_parallel=False,
use_compile=False,
compile_mode="default",
**kwargs,
):
"""Test the linear layer with specified parallel mode and sequence parallelization.

Args:
parallel_mode (str): 'row' or 'column' parallelism.
sequence_parallel (bool): Enable sequence parallelism if True.
use_compile (bool): Wrap the modules in ``torch.compile`` before running.
compile_mode (str): ``torch.compile`` mode ("default" or "reduce-overhead").
kwargs (dict): Additional arguments for the linear layer.
"""
# Set parameter data type
Expand Down Expand Up @@ -696,7 +727,12 @@ def _test_linear(parallel_mode=None, sequence_parallel=False, **kwargs):

# Apply models
output_single_node, output_distributed = _apply_models(
model_single_node, model_distributed, input_single_node, input_distributed
model_single_node,
model_distributed,
input_single_node,
input_distributed,
use_compile=use_compile,
compile_mode=compile_mode,
)

if "return_bias" in kwargs:
Expand Down Expand Up @@ -740,13 +776,18 @@ def test_linear():
{"params_dtype": torch.float16 if QUANTIZATION != "nvfp4" else torch.bfloat16},
{"delay_wgrad_compute": True},
{"save_original_input": True},
{"use_compile": True},
{"use_compile": True, "compile_mode": "reduce-overhead"},
]

for kwargs in kwargs_list:
if kwargs.get("save_original_input", False) and QUANTIZATION == "fp8":
continue
if kwargs.get("delay_wgrad_compute", False) and NVTE_TEST_NVINSPECT_ENABLED:
continue
# debug instrumentation forces the eager fallback, so compile is a no-op there.
if kwargs.get("use_compile", False) and NVTE_TEST_NVINSPECT_ENABLED:
continue
for parallel_mode in ["column", "row"]:
for sequence_parallel in [False, True]:
_test_linear(parallel_mode, sequence_parallel, **kwargs)
Expand Down
40 changes: 40 additions & 0 deletions tests/pytorch/distributed/test_comm_gemm_overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def _run_layer_with_overlap(
quantization,
num_layers=1,
use_cublasmp=False,
compile=False,
compile_mode="default",
):
test_path = TEST_ROOT / "run_layer_with_overlap.py"
test_cmd = LAUNCH_CMD + [
Expand All @@ -129,6 +131,10 @@ def _run_layer_with_overlap(
if overlap_rs_dgrad:
test_cmd.append("--overlap-rs-dgrad")

if compile:
test_cmd.append("--compile")
test_cmd.append(f"--compile-mode={compile_mode}")

if fp8:
if quantization in ("fp8_delayed_scaling", "fp8_current_scaling") and not fp8_available:
pytest.skip(reason_for_no_fp8)
Expand Down Expand Up @@ -281,6 +287,40 @@ def test_layers_with_overlap_bf16(
)


@pytest.mark.parametrize("compile_mode", ["default", "reduce-overhead"])
@pytest.mark.parametrize(
"linear_parallel_mode,overlap_rs_dgrad",
[
("row", False),
("column", False),
("column", True),
],
ids=[
"ROW-PARALLEL",
"COL-PARALLEL - BULK DGRAD/WGRAD",
"COL-PARALLEL - DGRAD+RS",
],
)
def test_linear_with_overlap_compile(linear_parallel_mode, overlap_rs_dgrad, compile_mode):
"""te.Linear comm+GEMM overlap (Userbuffers) under torch.compile (BF16).

Userbuffers is expected to stay on Linear's compiled custom-op path (the
collective lives inside the opaque op), so this checks that torch.compile +
Userbuffers stays numerically correct against the eager, non-overlap reference.
``compile_mode="reduce-overhead"`` additionally exercises CUDA-graph trees on
top of the Userbuffers collectives.
"""
_run_layer_with_overlap(
te.Linear.__name__,
linear_parallel_mode,
overlap_rs_dgrad,
False,
None,
compile=True,
compile_mode=compile_mode,
)


@pytest.mark.parametrize("use_cublasmp", (False, True))
@pytest.mark.parametrize(
"quantization",
Expand Down
35 changes: 35 additions & 0 deletions tests/pytorch/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,41 @@ def test_quantized_model_init_high_precision_init_val():
), "clear_high_precision_init_val() not work"


@pytest.mark.skipif(not fp8_available, reason=reason_for_no_fp8)
@pytest.mark.parametrize("move", ["cuda", "cpu", "half"])
def test_quantized_param_attrs_survive_apply(move):
"""Attributes attached to a quantized parameter survive nn.Module._apply.

Quantized parameters implement the flatten protocol, so ``_apply`` moves them
with ``swap_tensors``, which exchanges the parameter's whole ``__dict__``.
Anything attached from the outside rides out on the discarded tensor unless
the module re-attaches it.
"""
with quantized_model_init(preserve_high_precision_init_val=True):
model = Linear(64, 64)

weight = model.weight
expected = weight.get_high_precision_init_val()
weight.probe_attr = "attached-from-outside"

if move == "cuda":
model = model.cuda()
elif move == "cpu":
model = model.cpu()
else:
model = model.half()

weight = model.weight
assert hasattr(weight, "get_high_precision_init_val"), f"accessor lost by .{move}()"
assert hasattr(weight, "clear_high_precision_init_val"), f"accessor lost by .{move}()"
torch.testing.assert_close(weight.get_high_precision_init_val(), expected, rtol=0, atol=0)
assert weight.probe_attr == "attached-from-outside", f"custom attr lost by .{move}()"

# The accessor must read the surviving parameter, not the discarded one.
weight.clear_high_precision_init_val()
assert weight.get_high_precision_init_val() is None


@pytest.mark.skipif(not mxfp8_available, reason=reason_for_no_mxfp8)
def test_grouped_linear_single_param_preserves_high_precision_init(monkeypatch):
"""Grouped MXFP8 and discrete weights produce identical FP32 master initialization."""
Expand Down
Loading