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
4 changes: 2 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ Exit codes: `0` means nothing reached the `--fail-on` level, `1` means something
| :--- | :--- |
| `quantpreflight suggest <model>` | Rank the quantized versions of a model that start. It takes the same target options as `check`, plus `--limit` |
| `quantpreflight explain QPF006` | Explain a rule |
| `quantpreflight list-rules` | List every rule |
| `quantpreflight list-gpus` | List GPUs and their capabilities |
| `quantpreflight list-rules [--format json]` | List every rule; JSON includes the rule ID, severity, title, and description |
| `quantpreflight list-gpus [--format json]` | List bundled GPU profiles; JSON includes every profile field |
| `quantpreflight validate-profiles` | Check the bundled TOML profiles |

You can pass a GPU alias or architecture such as `rtx4090` or `sm_89`.
Expand Down
28 changes: 21 additions & 7 deletions src/quantpreflight/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from __future__ import annotations

import argparse
from dataclasses import asdict
import json
import os
import pathlib
import sys
Expand Down Expand Up @@ -181,15 +183,20 @@ def _build_parser() -> argparse.ArgumentParser:
explain = sub.add_parser("explain", help="Show what a rule means.")
explain.add_argument("rule", help="Rule ID, such as QPF006.")

sub.add_parser("list-gpus", help="List bundled GPU hardware profiles.")
sub.add_parser("list-rules", help="List all pre-flight rules.")
list_gpus = sub.add_parser("list-gpus", help="List bundled GPU hardware profiles.")
list_rules = sub.add_parser("list-rules", help="List all pre-flight rules.")
for listing in (list_gpus, list_rules):
listing.add_argument("--format", choices=["text", "json"], default="text", help="Output format (default: text).")
sub.add_parser("validate-profiles", help="Validate all TOML architecture and hardware profiles.")

return parser


def _cmd_list_gpus() -> int:
def _cmd_list_gpus(output_format: str) -> int:
gpus = load_gpu_profiles()
if output_format == "json":
print(json.dumps([asdict(gpus[gid]) for gid in sorted(gpus)], indent=2))
return 0
print(f"{'GPU':<12} {'Vendor':<8} {'Arch':<8} {'VRAM':<10} {'BF16':<6} {'FP8':<6} {'BlkFP8':<8} {'NVFP4':<6}")
print("-" * 72)
for gid in sorted(gpus.keys()):
Expand All @@ -202,8 +209,15 @@ def _cmd_list_gpus() -> int:
return 0


def _cmd_list_rules() -> int:
for rid, (sev, title, desc) in sorted(RULE_CATALOG.items()):
def _cmd_list_rules(output_format: str) -> int:
rules = sorted(RULE_CATALOG.items())
if output_format == "json":
print(json.dumps([
{"id": rid, "severity": sev.value, "title": title, "description": desc}
for rid, (sev, title, desc) in rules
], indent=2))
return 0
for rid, (sev, title, desc) in rules:
print(f"{rid} [{sev.value.upper():<8}] {title}")
print(f" {desc}")
return 0
Expand Down Expand Up @@ -314,9 +328,9 @@ def main(argv: Sequence[str] | None = None) -> int:
parser.print_help()
return 0
if args.command == "list-gpus":
return _cmd_list_gpus()
return _cmd_list_gpus(args.format)
if args.command == "list-rules":
return _cmd_list_rules()
return _cmd_list_rules(args.format)
if args.command == "explain":
return _cmd_explain(args.rule)
if args.command == "validate-profiles":
Expand Down
38 changes: 38 additions & 0 deletions tests/test_cli_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,44 @@ def test_list_rules_shows_every_rule(capsys: pytest.CaptureFixture[str]) -> None
assert "[CRITICAL]" in output


def test_list_gpus_json_includes_every_profile_field(capsys: pytest.CaptureFixture[str]) -> None:
assert main(["list-gpus", "--format", "json"]) == 0
captured = capsys.readouterr()
assert captured.err == ""
profiles = json.loads(captured.out)
ids = [profile["id"] for profile in profiles]
assert ids == sorted(set(ids))
h100 = next(profile for profile in profiles if profile["id"] == "H100")
assert set(h100) == {
"id", "aliases", "vendor", "arch", "compute_capability", "vram_gb",
"supports_bf16", "supports_fp8_w8a8", "supports_fp8_block_scale",
"supports_nvfp4", "supports_marlin",
}
assert h100["arch"] == "sm_90"
assert h100["vram_gb"] == 80.0
assert h100["supports_bf16"] is True
assert "sm_90" in h100["aliases"]


def test_list_rules_json_preserves_the_rule_catalog(capsys: pytest.CaptureFixture[str]) -> None:
assert main(["list-rules", "--format", "json"]) == 0
captured = capsys.readouterr()
assert captured.err == ""
expected = [
{"id": rule_id, "severity": severity.value, "title": title, "description": description}
for rule_id, (severity, title, description) in sorted(RULE_CATALOG.items())
]
assert json.loads(captured.out) == expected


@pytest.mark.parametrize("command", ["list-gpus", "list-rules"])
def test_list_explicit_text_matches_default(command: str, capsys: pytest.CaptureFixture[str]) -> None:
assert main([command]) == 0
default = capsys.readouterr()
assert main([command, "--format", "text"]) == 0
assert capsys.readouterr() == default


# Newer options


Expand Down