Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

3.8 KB
Raw Blame
#!/usr/bin/env python3
"""Keep Gemma 4 install artifacts immutable across every platform fallback."""

from __future__ import annotations

import json
import re
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
CATALOG = ROOT / "config" / "model-library.json"
TIER_MAPS = (
    ROOT / "installers" / "lib" / "tier-map.sh",
    ROOT / "installers" / "macos" / "lib" / "tier-map.sh",
    ROOT / "installers" / "windows" / "lib" / "tier-map.ps1",
)

EXPECTED = {
    "gemma-4-E2B-it-Q4_K_M.gguf": {
        "id": "gemma4-e2b-q4",
        "url": (
            "https://huggingface.co/unsloth/gemma-4-E2B-it-GGUF/"
            "resolve/0314792d7f1f7e229411f620751375812bb9faf2/"
            "gemma-4-E2B-it-Q4_K_M.gguf"
        ),
        "sha256": "740185b21d22ceb83a11c3aa62ad5842ef32c70f6096d756bbee85a1e4ec34b8",
        "size_bytes": 3106738272,
        "size_mb": 2963,
    },
    "gemma-4-E4B-it-Q4_K_M.gguf": {
        "id": "gemma4-e4b-q4",
        "url": (
            "https://huggingface.co/unsloth/gemma-4-E4B-it-GGUF/"
            "resolve/bfc15c382204943c3a8fff0c750b94ae2364d7a3/"
            "gemma-4-E4B-it-Q4_K_M.gguf"
        ),
        "sha256": "85a896a047553e842f25297ee5b031d64ff30147d9c4af17b1e4b394cd1fab87",
        "size_bytes": 4977171584,
        "size_mb": 4747,
    },
    # ggml-org deleted its Gemma 4 26B-A4B/31B Q4_K_M files upstream, so the
    # old unpinned resolve/main URLs return 404. unsloth ships no plain
    # Q4_K_M for the 26B-A4B MoE; UD-Q4_K_M is its Q4_K_M-class quant.
    "gemma-4-26B-A4B-it-UD-Q4_K_M.gguf": {
        "id": "gemma4-26b-a4b-q4",
        "url": (
            "https://huggingface.co/unsloth/gemma-4-26B-A4B-it-GGUF/"
            "resolve/c099eb48e663fd284577b04978a94ffccb261841/"
            "gemma-4-26B-A4B-it-UD-Q4_K_M.gguf"
        ),
        "sha256": "f2c28b3dc4776931ac6f879e11f203dec637ea0f14267a86ec8f6165f63f293f",
        "size_bytes": 16947541728,
        "size_mb": 16162,
    },
    "gemma-4-31B-it-Q4_K_M.gguf": {
        "id": "gemma4-31b-q4",
        "url": (
            "https://huggingface.co/unsloth/gemma-4-31B-it-GGUF/"
            "resolve/c1ac76e99d5513b141e8adde7288b85c3f9c32ec/"
            "gemma-4-31B-it-Q4_K_M.gguf"
        ),
        "sha256": "38bd64c852c4b460434cc7162fa9bdcf242faf86502581a754cb72956bb17f84",
        "size_bytes": 18323733440,
        "size_mb": 17475,
    },
}

TIER_ARTIFACT = re.compile(
    r'(?:GGUF_FILE|GgufFile)\s*=\s*"(?P<file>[^"]+)"\s*'
    r'(?:GGUF_URL|GgufUrl)\s*=\s*"(?P<url>[^"]+)"\s*'
    r'(?:GGUF_SHA256|GgufSha256)\s*=\s*"(?P<sha256>[^"]*)"'
)


def test_catalog_pins() -> None:
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    for expected in EXPECTED.values():
        model = by_id[expected["id"]]
        assert model["gguf_url"] == expected["url"]
        assert model["gguf_sha256"] == expected["sha256"]
        assert model["size_bytes"] == expected["size_bytes"]
        assert model["size_mb"] == expected["size_mb"]


def test_platform_fallback_pins() -> None:
    for tier_map in TIER_MAPS:
        matches = [match.groupdict() for match in TIER_ARTIFACT.finditer(
            tier_map.read_text(encoding="utf-8")
        )]
        for filename, expected in EXPECTED.items():
            artifact_matches = [item for item in matches if item["file"] == filename]
            assert artifact_matches, f"{tier_map}: missing {filename}"
            for artifact in artifact_matches:
                assert artifact["url"] == expected["url"], tier_map
                assert artifact["sha256"] == expected["sha256"], tier_map


def main() -> int:
    test_catalog_pins()
    test_platform_fallback_pins()
    print("[PASS] Gemma 4 artifact revisions and checksums are pinned across platforms")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())