Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions docs/features/quantization/b12x.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ NVIDIA SM120 and SM121 GPUs. Install the dependency with:
uv pip install "vllm[b12x]"
```

b12x linear kernels participate in automatic selection after established
optimized backends and before emulation. Select the linear and MoE backends
explicitly with:
b12x linear and MoE kernels participate in automatic selection when the
optional package is installed and the deployment is supported. They are tried
after established optimized backends and before fallback or emulation kernels.
Select either backend explicitly with:

```bash
vllm serve <model> \
Expand Down
50 changes: 50 additions & 0 deletions tests/kernels/moe/test_b12x.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,56 @@ def is_supported_config(cls, config, weight_key, activation_key, activation_form
assert selected_activation_keys == [expected_activation_key]


@pytest.mark.parametrize(
"b12x_supported,expected_backend",
[
(True, NvFp4MoeBackend.B12X),
(False, NvFp4MoeBackend.MARLIN),
],
)
def test_auto_b12x_nvfp4_selection_precedes_marlin(
monkeypatch: pytest.MonkeyPatch,
b12x_supported: bool,
expected_backend: NvFp4MoeBackend,
) -> None:
selected_backends: list[NvFp4MoeBackend] = []

class CandidateExperts:
@staticmethod
def is_supported_config(
cls, config, weight_key, activation_key, activation_format
):
backend = selected_backends[-1]
if backend == NvFp4MoeBackend.B12X:
return b12x_supported, None if b12x_supported else "unavailable"
if backend == NvFp4MoeBackend.MARLIN:
return True, None
return False, "unsupported in selector-order test"

def backend_to_kernel_cls(backend: NvFp4MoeBackend):
selected_backends.append(backend)
return [CandidateExperts]

monkeypatch.setattr(nvfp4_oracle, "backend_to_kernel_cls", backend_to_kernel_cls)
config = make_dummy_moe_config(hidden_dim=128, intermediate_size=64)

backend, experts_cls = select_nvfp4_moe_backend(
config,
weight_key=kNvfp4Static,
activation_key=None,
)

assert backend == expected_backend
assert experts_cls is CandidateExperts
assert NvFp4MoeBackend.B12X in selected_backends
if b12x_supported:
assert NvFp4MoeBackend.MARLIN not in selected_backends
else:
assert selected_backends.index(NvFp4MoeBackend.B12X) < selected_backends.index(
NvFp4MoeBackend.MARLIN
)


@pytest.mark.parametrize(
"force_a16,expected_quant_dtype", [(False, "nvfp4"), (True, None)]
)
Expand Down
5 changes: 5 additions & 0 deletions vllm/model_executor/layers/fused_moe/oracle/nvfp4.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ def select_nvfp4_moe_backend(
NvFp4MoeBackend.FLASHINFER_CUTEDSL_BATCHED,
NvFp4MoeBackend.FLASHINFER_CUTLASS,
NvFp4MoeBackend.VLLM_CUTLASS,
# B12X is optional. Its support predicate checks that the package,
# device, quantization scheme, shape, and parallel configuration are
# all compatible, so an unavailable installation falls through
# without changing the existing Marlin fallback.
NvFp4MoeBackend.B12X,
NvFp4MoeBackend.MARLIN,
NvFp4MoeBackend.HUMMING,
NvFp4MoeBackend.EMULATION,
Expand Down
Loading