Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
b24d259
[PyTorch][torch.compile] Replace TensorProto with make_empty_traceable
kshitij12345 Jul 1, 2026
c33cd00
[PyTorch][torch.compile] Guard NVFP4Quantizer.copy() tensor access un…
kshitij12345 Jul 2, 2026
a582eb5
[PyTorch][test] Fix NVFP4 value-object test: set with_post_rht_amax=True
kshitij12345 Jul 3, 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
Loading