Skip to content

Commit dd52183

Browse files
dbarbuzziderekk-nm
andauthored
[Tests] Add tests for "quantization_w4a4_fp4" examples (#1715)
SUMMARY: Adds tests for the example scripts in the `examples/quantization_w4a4_fp4` folder. TEST PLAN: Internal examples test run with just the new tests: https://github.com/neuralmagic/llm-compressor-testing/actions/runs/16831501387/job/47709542536 The failure appears to be a legitimate issue, not a test issue, and has been reported. --------- Signed-off-by: Derek Kozikowski <[email protected]> Signed-off-by: Domenic Barbuzzi <[email protected]> Signed-off-by: Domenic Barbuzzi <[email protected]> Co-authored-by: Derek Kozikowski <[email protected]>
1 parent 8747bae commit dd52183

File tree

1 file changed

+53
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)