[diffusion] refactor: reuse the single-process parallel test fixture (#42964)

Co-authored-by: Mick Qian <mickqian@users.noreply.github.com>
This commit is contained in:
Mick
2026-10-08 09:24:53 +08:00
committed by GitHub
co-authored by Mick Qian
parent b91919ffe2
commit 35608e48d1
2 changed files with 16 additions and 43 deletions
@@ -513,20 +513,6 @@ def test_cosmos_unipc_recovers_x0_on_a_straight_flow():
# ---------------------------------------------------------------- DiT
def _init_single_process_parallel() -> None:
from sglang.multimodal_gen.runtime.distributed.parallel_state import (
maybe_init_distributed_environment_and_model_parallel,
model_parallel_is_initialized,
)
from sglang.multimodal_gen.test.single_test_file.component_accuracy.utils import (
ensure_distributed_env_defaults,
)
if not model_parallel_is_initialized():
ensure_distributed_env_defaults()
maybe_init_distributed_environment_and_model_parallel(tp_size=1, sp_size=1)
def _tiny_arch() -> Flux3ArchConfig:
return Flux3ArchConfig(
hidden_size=64,
@@ -542,12 +528,12 @@ def _tiny_arch() -> Flux3ArchConfig:
@pytest.mark.skipif(
not torch.cuda.is_available(), reason="needs the CUDA parallel runtime"
)
def test_dit_loads_released_checkpoint_names():
def test_dit_loads_released_checkpoint_names(request):
"""Released checkpoints load by name; a renamed module or mapping breaks them."""
from sglang.multimodal_gen.runtime.loader.utils import get_param_names_mapping
from sglang.multimodal_gen.runtime.models.dits.flux3 import Flux3Transformer
_init_single_process_parallel()
request.getfixturevalue("single_process_model_parallel")
with torch.device("meta"):
model = Flux3Transformer(Flux3DiTConfig(arch_config=_tiny_arch()))
params = set(model.state_dict())
@@ -594,14 +580,14 @@ def test_dit_loads_released_checkpoint_names():
@pytest.mark.skipif(not torch.cuda.is_available(), reason="needs CUDA attention")
def test_dit_cached_streams_match_full_forward():
def test_dit_cached_streams_match_full_forward(request):
"""The pipeline's per-caption / per-request caching must not change predictions."""
from sglang.multimodal_gen.runtime.managers.forward_context import (
set_forward_context,
)
from sglang.multimodal_gen.runtime.models.dits.flux3 import Flux3Transformer
_init_single_process_parallel()
request.getfixturevalue("single_process_model_parallel")
torch.manual_seed(0)
model = Flux3Transformer(Flux3DiTConfig(arch_config=_tiny_arch())).cuda().bfloat16()
for p in model.parameters():
@@ -648,7 +634,7 @@ def test_dit_cached_streams_match_full_forward():
@pytest.mark.skipif(not torch.cuda.is_available(), reason="needs CUDA graphs")
def test_cuda_graph_replays_match_eager_denoise_steps():
def test_cuda_graph_replays_match_eager_denoise_steps(request):
"""Replays with fresh inputs must match eager steps bit for bit."""
from sglang.multimodal_gen.runtime.managers.forward_context import (
set_forward_context,
@@ -656,7 +642,7 @@ def test_cuda_graph_replays_match_eager_denoise_steps():
from sglang.multimodal_gen.runtime.models.dits.flux3 import Flux3Transformer
from sglang.multimodal_gen.runtime.vla.cuda_graph import VLATensorGraphRunner
_init_single_process_parallel()
request.getfixturevalue("single_process_model_parallel")
torch.manual_seed(0)
model = Flux3Transformer(Flux3DiTConfig(arch_config=_tiny_arch())).cuda().bfloat16()
for p in model.parameters():
@@ -734,7 +720,7 @@ def test_fp8r_native_format_preserves_values(monkeypatch, fnuz, tuple_output):
not torch.cuda.is_available() or torch.cuda.get_device_capability() < (8, 9),
reason="needs FP8 scaled_mm",
)
def test_fp8r_checkpoint_loads_fused_rowwise_linears():
def test_fp8r_checkpoint_loads_fused_rowwise_linears(request):
"""Native FP8r payloads (E4M3 + per-row scales) must fuse and dequantize consistently."""
from sglang.multimodal_gen.runtime.models.dits.flux3 import (
Flux3Fp8RowwiseLinear,
@@ -743,7 +729,7 @@ def test_fp8r_checkpoint_loads_fused_rowwise_linears():
quantize_fp8_rowwise,
)
_init_single_process_parallel()
request.getfixturevalue("single_process_model_parallel")
with torch.device("meta"):
model = Flux3Transformer(Flux3DiTConfig(arch_config=_tiny_arch()))
reference = {}
@@ -11,20 +11,6 @@ import torch
pytestmark = pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA required")
def _init_parallel() -> None:
from sglang.multimodal_gen.runtime.distributed.parallel_state import (
maybe_init_distributed_environment_and_model_parallel,
model_parallel_is_initialized,
)
from sglang.multimodal_gen.test.single_test_file.component_accuracy.utils import (
ensure_distributed_env_defaults,
)
if not model_parallel_is_initialized():
ensure_distributed_env_defaults()
maybe_init_distributed_environment_and_model_parallel(tp_size=1, sp_size=1)
def _layer(
in_f: int, out_f: int, bias: bool, params_dtype: torch.dtype = torch.bfloat16
):
@@ -41,10 +27,10 @@ def _layer(
).to("cuda")
def test_mxfp8_linear_matches_bf16_and_accepts_prequantized() -> None:
def test_mxfp8_linear_matches_bf16_and_accepts_prequantized(request) -> None:
if torch.cuda.get_device_capability()[0] < 10:
pytest.skip("cuBLASLt MXFP8 block scaling requires Blackwell or newer")
_init_parallel()
request.getfixturevalue("single_process_model_parallel")
from sglang.kernels.ops.diffusion import silu_mul_mxfp8
in_f, out_f, rows = 512, 384, 200
@@ -72,7 +58,6 @@ def test_mxfp8_linear_matches_bf16_and_accepts_prequantized() -> None:
def _assert_aligned_layer_falls_back(params_dtype: torch.dtype) -> None:
_init_parallel()
layer = _layer(512, 384, bias=False, params_dtype=params_dtype)
g = torch.Generator(device="cpu").manual_seed(1)
weight = (torch.randn(384, 512, generator=g) * 0.02).to("cuda", params_dtype)
@@ -87,23 +72,25 @@ def _assert_aligned_layer_falls_back(params_dtype: torch.dtype) -> None:
assert rel < 0.05, rel
def test_pre_blackwell_aligned_layer_falls_back_to_channelwise() -> None:
def test_pre_blackwell_aligned_layer_falls_back_to_channelwise(request) -> None:
if torch.cuda.get_device_capability()[0] >= 10:
pytest.skip("requires a pre-Blackwell GPU")
request.getfixturevalue("single_process_model_parallel")
_assert_aligned_layer_falls_back(torch.bfloat16)
def test_fp16_layer_falls_back_to_channelwise() -> None:
def test_fp16_layer_falls_back_to_channelwise(request) -> None:
"""The swizzled quantizer takes bf16 only; an fp16 layer must not fail at load."""
request.getfixturevalue("single_process_model_parallel")
_assert_aligned_layer_falls_back(torch.float16)
def test_unaligned_layer_falls_back_to_channelwise() -> None:
def test_unaligned_layer_falls_back_to_channelwise(request) -> None:
"""The block-scaled GEMM needs K % 32 == 0; such a layer keeps the
per-channel fp8 path and still answers a forward. K is 16 rather than a
smaller odd size because the fallback's scaled GEMM still wants K % 16 == 0
(ROCm rejects anything else outright)."""
_init_parallel()
request.getfixturevalue("single_process_model_parallel")
layer = _layer(16, 128, bias=True)
layer.quant_method.process_weights_after_loading(layer)
assert not layer.mxfp8 and not layer.quant_method.accepts_mxfp8_input(layer)