Skip to content

Commit ebab63f

Browse files
committed
add TestQuantizationW4A4_FP4 test cases
Signed-off-by: Derek Kozikowski <[email protected]>
1 parent 0a20392 commit ebab63f

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
import shlex
3+
from pathlib import Path
4+
from typing import List
5+
6+
import pytest
7+
8+
from tests.examples.utils import (
9+
copy_and_run_script,
10+
gen_cmd_fail_message,
11+
requires_gpu_count,
12+
)
13+
14+
15+
@pytest.fixture
16+
def example_dir() -> str:
17+
return "examples/quantization_w4a4_fp4"
18+
19+
20+
@requires_gpu_count(1)
21+
@pytest.mark.example
22+
class TestQuantizationW4A4_FP4:
23+
"""
24+
Tests for examples in the "quantization_w4a4_fp4" example folder.
25+
"""
26+
27+
@pytest.mark.parametrize(
28+
"script_filename",
29+
[
30+
pytest.param("llama3_example.py"),
31+
pytest.param("llama4_example.py"),
32+
pytest.param("qwen_30b_a3b.py"),
33+
],
34+
)
35+
def test_quantization_w4a4_fp4_example_script(
36+
self, script_filename: str, example_dir: str, tmp_path: Path
37+
):
38+
"""
39+
Tests the example scripts in the folder.
40+
"""
41+
command, result = copy_and_run_script(tmp_path, example_dir, script_filename)
42+
43+
assert result.returncode == 0, gen_cmd_fail_message(command, result)
44+
45+
# verify that the expected directory got generated
46+
nvfp4_dirs: List[Path] = list(Path.cwd().glob("*-NVFP4"))
47+
assert(len(nvfp4_dirs)) == 1, (
48+
f"unexpectedly found more than one generated folder: {nvfp4_dirs}"
49+
)
50+
print("generated model directory:/n")
51+
print(list(nvfp4_dirs[0].iterdir()))
52+
53+
# is the generated content in the expected format?
54+
config_json = Path(nvfp4_dirs[0] / "config.json").read_text()
55+
config_format = config_json["quantization_config"]["format"]
56+
assert(config_format == "nvfp4-pack-quantized")

0 commit comments

Comments
 (0)