diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df6b3cb..1cc9592 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: os: - - ubuntu-latest + - ubuntu-24.04 - macos-latest - windows-latest python-version: @@ -46,6 +46,7 @@ jobs: - name: Verify installed CLI run: | llmrig --version + llmrig preflight --help llmrig check - name: Verify macOS editable CLI outside checkout diff --git a/README.md b/README.md index 81db02a..23d2d2b 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,17 @@ Every applied workflow emits a privacy-safe receipt: plan ID, receipt ID, model/ Verified measurements persist locally as graph-shaped evidence across machine × model × artifact × quantization × runtime × context × measurement. Predictions and measurements are stored as separate facts; calibration deltas are computed only when the same metric exists on both sides. No community upload happens by default. +## Frontier model preflight + +Inspect an exact Hugging Face repository without downloading weights or starting runtimes: + +```bash +llmrig preflight Amazon-FMR/Ergo +llmrig preflight Amazon-FMR/Ergo --json +``` + +Preflight reports the serialized footprint of a complete listed Safetensors set, repository revision, declared precision, and its ratio to total system RAM. Ambiguous or incomplete metadata stays unknown. This is not a peak inference memory estimate, runtime compatibility claim, or benchmark; offloading and alternative conversions are not assessed. Existing execution planning remains unchanged. + ## Runtime intelligence ```bash diff --git a/_llmrig/cli.py b/_llmrig/cli.py index 87a2b45..b6afc49 100644 --- a/_llmrig/cli.py +++ b/_llmrig/cli.py @@ -719,6 +719,7 @@ def _print_augmented_help() -> int: legacy.build_parser().print_help() print("\nRuntime intelligence:") + print(" preflight MODEL Inspect remote Safetensors footprint without downloads.") print(" runtimes Inspect oMLX, Ollama, MLX-LM, and llama.cpp readiness.") print("\nv0.9 Autopilot:") print(" plan MODEL Build a deterministic, read-only execution plan.") @@ -739,6 +740,10 @@ def _print_augmented_help() -> int: def main(argv: Optional[Sequence[str]] = None) -> int: values = list(sys.argv[1:] if argv is None else argv) + if values and values[0] == "preflight": + import llmrig as legacy + from .preflight import command + return command(values[1:], legacy) if values and values[0] == "runtimes": return command_runtimes(_runtimes_parser().parse_args(values[1:])) if values and values[0] == "report": diff --git a/_llmrig/preflight.py b/_llmrig/preflight.py new file mode 100644 index 0000000..595372c --- /dev/null +++ b/_llmrig/preflight.py @@ -0,0 +1,116 @@ +"""Read-only serialized weight footprint assessment, independent of runtimes.""" +from __future__ import annotations + +import argparse +import json +import math +import re +import sys +from urllib.parse import quote + +from .hf_artifacts import safetensors_weight_set, explicit_quantization_metadata + + +def assess(repository, payload, ram_gib, config=None): + """Assess one complete listed Safetensors set; never infer executability.""" + revision = payload.get("sha") + if not isinstance(revision, str) or not re.fullmatch(r"[0-9a-fA-F]{40}", revision): + revision = None + siblings = [x for x in payload.get("siblings", ()) if isinstance(x, dict)] + paths, total, status = safetensors_weight_set(siblings) + seen = set() + for item in siblings: + path = item.get("rfilename") or item.get("path") or "" + if not isinstance(path, str) or not path.lower().endswith(".safetensors"): + continue + if path in seen: + total, status = None, "duplicate_paths" + seen.add(path) + sizes = [item.get("size"), (item.get("lfs") or {}).get("size") + if isinstance(item.get("lfs"), dict) else None] + observed = [v for v in sizes if v is not None] + if any(type(v) is not int or v <= 0 for v in observed) or len(set(observed)) > 1: + total, status = None, "invalid_size" + if not revision: + total, status = None, "missing_revision" + metadata = dict(payload) + if config is not None: + metadata["config"] = config + precision, precision_status, _ = explicit_quantization_metadata(metadata) + cfg = metadata.get("config") + if precision_status == "unknown" and isinstance(cfg, dict): + if not cfg.get("quantization_config") and not cfg.get("quantization"): + dtypes = {cfg[k] for k in ("dtype", "torch_dtype") + if isinstance(cfg.get(k), str)} + if dtypes and dtypes <= {"bfloat16", "bf16"}: + precision, precision_status = "BF16", "declared_dtype" + ram = None + if type(ram_gib) in (int, float) and math.isfinite(ram_gib) and ram_gib > 0: + ram = int(ram_gib * 2**30) + ratio = total / ram if total and ram else None + return { + "schema_version": "0.1", "repository": repository, "revision": revision, + "source": "Hugging Face model API file metadata", + "format": "Safetensors", "precision": precision, + "precision_status": precision_status, "file_count": len(paths), + "artifact_size_bytes": total, "metadata_status": status, + "ram_bytes": ram, "weight_to_ram_ratio": ratio, + "serialized_weight_shortfall_bytes": max(0, total - ram) if ratio is not None else None, + "serialized_weight_fit": ("exceeds_ram" if ratio > 1 else "not_ruled_out") + if ratio is not None else "unknown", + "runtime_compatibility": "unknown", "inference": "not_run", + "weight_downloads": False, + "limitation": "Serialized file size versus total system RAM only; not peak inference memory or proof about offloading, conversion or executability.", + } + + +def command(argv, legacy): + parser = argparse.ArgumentParser(prog="llmrig preflight") + parser.add_argument("model", help="Exact Hugging Face owner/repository") + parser.add_argument("--json", action="store_true") + args = parser.parse_args(argv) + if not re.fullmatch(r"[A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9][A-Za-z0-9_.-]*", args.model): + parser.error("expected an exact Hugging Face owner/repository") + repo = quote(args.model, safe="/") + try: + payload, _ = legacy.http_json( + f"https://huggingface.co/api/models/{repo}?blobs=true", timeout=20) + if not isinstance(payload, dict) or (payload.get("id") or payload.get("modelId")) != args.model: + raise ValueError("repository identity mismatch") + cfg = None + revision = payload.get("sha") + if isinstance(revision, str) and re.fullmatch(r"[0-9a-fA-F]{40}", revision): + if any(isinstance(x, dict) and x.get("rfilename") == "config.json" + for x in payload.get("siblings", ())): + try: + candidate, _ = legacy.http_json( + f"https://huggingface.co/{repo}/resolve/{revision}/config.json", timeout=20) + if isinstance(candidate, dict): + cfg = candidate + except Exception: + pass + result = assess(args.model, payload, legacy.hardware_profile().get("ram_gib"), cfg) + except Exception: + print("llmrig preflight: metadata unavailable or invalid", file=sys.stderr) + return 1 + if args.json: + print(json.dumps(result, indent=2, sort_keys=True)) + else: + print("LLMRig Frontier Model Preflight") + print(f"Model: {result['repository']}") + print(f"Revision: {result['revision'] or 'unknown'}") + print(f"Precision: {result['precision'] or 'unknown'}") + print(f"Weight files: {result['file_count']}") + size = result["artifact_size_bytes"] + if size is not None: + print(f"Serialized weights: {size / 1e9:.2f} GB | {size / 2**30:.2f} GiB") + else: + print(f"Serialized weights: unknown ({result['metadata_status']})") + if result["weight_to_ram_ratio"] is not None: + print(f"System RAM: {result['ram_bytes'] / 2**30:.2f} GiB") + print(f"Weight/RAM ratio: {result['weight_to_ram_ratio']:.2f}x") + print(f"Weight shortfall: {result['serialized_weight_shortfall_bytes'] / 2**30:.2f} GiB") + print(f"Serialized weight fit: {result['serialized_weight_fit']}") + print("Runtime compatibility: unknown | Inference: not run") + print("No weight downloads. " + result["limitation"]) + return 0 diff --git a/tests/test_frontier_preflight.py b/tests/test_frontier_preflight.py new file mode 100644 index 0000000..9a9e9a8 --- /dev/null +++ b/tests/test_frontier_preflight.py @@ -0,0 +1,51 @@ +import unittest + +from _llmrig.preflight import assess + + +def payload(files, **extra): + return {"sha": "a" * 40, "siblings": files, **extra} + + +def shard(i, size): + return {"rfilename": f"model-{i:05d}-of-00002.safetensors", "size": size} + + +class FrontierPreflightTests(unittest.TestCase): + def test_complete_sharded_weights(self): + result = assess("example/model", payload([shard(1, 30 * 2**30), shard(2, 30 * 2**30)]), 48) + assert result["artifact_size_bytes"] == 60 * 2**30 + assert result["serialized_weight_shortfall_bytes"] == 12 * 2**30 + assert result["weight_to_ram_ratio"] == 1.25 + assert result["serialized_weight_fit"] == "exceeds_ram" + assert result["runtime_compatibility"] == "unknown" + assert result["inference"] == "not_run" + assert result["weight_downloads"] is False + + + def test_incomplete_or_ambiguous_sets(self): + for files in ([shard(1, 100)], [shard(1, 100), shard(1, 200), shard(2, 100)], + [shard(1, 100), shard(2, 100), {"rfilename": "alternate.safetensors", "size": 100}]): + assert assess("example/model", payload(files), 48)["artifact_size_bytes"] is None + + + def test_conflicting_size_metadata(self): + item = shard(1, 100) + item["lfs"] = {"size": 200} + assert assess("example/model", payload([item, shard(2, 100)]), 48)["artifact_size_bytes"] is None + + + def test_precision_and_unknown_ram(self): + data = payload([{"rfilename": "model.safetensors", "size": 100}]) + result = assess("example/model", data, None, {"torch_dtype": "bfloat16"}) + assert result["precision"] == "BF16" + assert result["precision_status"] == "declared_dtype" + assert result["serialized_weight_fit"] == "unknown" + for method in ("mxfp4", "mxfp8"): + result = assess("example/model", data, 48, {"quantization_config": {"quant_method": method}}) + assert result["precision"] == method + assert assess("example/bf16", data, 48)["precision"] is None + + + def test_missing_revision(self): + assert assess("example/model", {"siblings": [shard(1, 100), shard(2, 100)]}, 48)["artifact_size_bytes"] is None