Skip to content

[Tests] Add tests for "quantization_w4a4_fp4" examples #1715

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 6 commits into from
Aug 13, 2025
Merged
Changes from 3 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
53 changes: 53 additions & 0 deletions tests/examples/test_quantization_w4a4_fp4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import json
from pathlib import Path
from typing import List

import pytest

from tests.examples.utils import (
copy_and_run_script,
gen_cmd_fail_message,
requires_gpu_count,
)


@pytest.fixture
def example_dir() -> str:
return "examples/quantization_w4a4_fp4"


@requires_gpu_count(1)
@pytest.mark.example
class TestQuantizationW4A4_FP4:
"""
Tests for examples in the "quantization_w4a4_fp4" example folder.
"""

@pytest.mark.parametrize(
("script_filename"),
[
pytest.param("llama3_example.py"),
pytest.param("llama4_example.py"),
pytest.param("qwen_30b_a3b.py"),
],
)
def test_quantization_w4a4_fp4_example_script(
self, script_filename: str, example_dir: str, tmp_path: Path
):
"""
Tests the example scripts in the folder.
"""
command, result = copy_and_run_script(tmp_path, example_dir, script_filename)

assert result.returncode == 0, gen_cmd_fail_message(command, result)

# verify the expected directory was generated
nvfp4_dirs: List[Path] = list(tmp_path.rglob("*-NVFP4"))
assert (
len(nvfp4_dirs)
) == 1, f"did not find exactly one generated folder: {nvfp4_dirs}"

# verify the format in the generated config
config_json = json.loads((nvfp4_dirs[0] / "config.json").read_text())
config_format = config_json["quantization_config"]["format"]
assert config_format == "nvfp4-pack-quantized"