Skip to content

[Misc] Use pytest.mark.skipif in sgl-kernel test #5137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2025
Merged
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
11 changes: 10 additions & 1 deletion sgl-kernel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,19 @@ python -m uv build --wheel -Cbuild-dir=build --color=always .

### Testing & Benchmarking

1. Add pytest tests in [tests/](https://github.com/sgl-project/sglang/tree/main/sgl-kernel/tests)
1. Add pytest tests in [tests/](https://github.com/sgl-project/sglang/tree/main/sgl-kernel/tests), if you need to skip some test, please use `@pytest.mark.skipif`

```python
@pytest.mark.skipif(
skip_condition, reason="Nvfp4 Requires compute capability of 10 or above."
)
```

2. Add benchmarks using [triton benchmark](https://triton-lang.org/main/python-api/generated/triton.testing.Benchmark.html) in [benchmark/](https://github.com/sgl-project/sglang/tree/main/sgl-kernel/benchmark)
3. Run test suite



### Release new version

Update version in [pyproject.toml](https://github.com/sgl-project/sglang/blob/main/sgl-kernel/pyproject.toml) and [version.py](https://github.com/sgl-project/sglang/blob/main/sgl-kernel/python/sgl_kernel/version.py)
13 changes: 8 additions & 5 deletions sgl-kernel/tests/test_fp4_gemm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
import torch
from sgl_kernel import cutlass_scaled_fp4_mm, scaled_fp4_quant

if torch.cuda.get_device_capability() < (10, 0):
pytest.skip(
reason="Nvfp4 Requires compute capability of 10 or above.",
allow_module_level=True,
)
skip_condition = torch.cuda.get_device_capability() < (10, 0)

DTYPES = [torch.float16, torch.bfloat16]
# m, n, k
Expand Down Expand Up @@ -108,6 +104,9 @@ def get_ref_results(
return torch.matmul(a_in_dtype, b_in_dtype.t())


@pytest.mark.skipif(
skip_condition, reason="Nvfp4 Requires compute capability of 10 or above."
)
@pytest.mark.parametrize("dtype", DTYPES)
@pytest.mark.parametrize("shape", SHAPES)
@torch.inference_mode()
Expand Down Expand Up @@ -149,3 +148,7 @@ def test_nvfp4_gemm(
)

torch.testing.assert_close(out, expected_out.to(dtype=dtype), atol=1e-1, rtol=1e-1)


if __name__ == "__main__":
pytest.main([__file__])
16 changes: 11 additions & 5 deletions sgl-kernel/tests/test_fp4_quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
import torch
from sgl_kernel import scaled_fp4_quant

if torch.cuda.get_device_capability() < (10, 0):
pytest.skip(
reason="Nvfp4 Requires compute capability of 10 or above.",
allow_module_level=True,
)
skip_condition = torch.cuda.get_device_capability() < (10, 0)

DTYPES = [torch.float16, torch.bfloat16]
SHAPES = [(128, 64), (128, 128), (256, 64), (256, 128)]
Expand Down Expand Up @@ -115,6 +111,9 @@ def recover_swizzled_scales(scale, m, n):
return result[:m, :scale_n]


@pytest.mark.skipif(
skip_condition, reason="Nvfp4 Requires compute capability of 10 or above."
)
@pytest.mark.parametrize("dtype", DTYPES)
@pytest.mark.parametrize("shape", SHAPES)
@torch.inference_mode()
Expand All @@ -140,6 +139,9 @@ def test_quantize_to_fp4(
torch.testing.assert_close(scale_ans, scale_ref)


@pytest.mark.skipif(
skip_condition, reason="Nvfp4 Requires compute capability of 10 or above."
)
@pytest.mark.parametrize("pad_shape", PAD_SHAPES)
@torch.inference_mode()
def test_quantize_to_fp4_padded(pad_shape: tuple[int, int]) -> None:
Expand All @@ -162,3 +164,7 @@ def test_quantize_to_fp4_padded(pad_shape: tuple[int, int]) -> None:

torch.testing.assert_close(out_ans, out_ref)
torch.testing.assert_close(scale_ans, scale_ref)


if __name__ == "__main__":
pytest.main([__file__])
Loading