File size: 5,266 Bytes
cc249f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3bbb0bf
 
 
 
cc249f3
 
 
 
 
 
 
 
 
 
 
 
3bbb0bf
cc249f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3bbb0bf
cc249f3
 
 
 
 
 
 
 
3bbb0bf
cc249f3
f60e0cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from __future__ import annotations

import json

import pytest

from shiftedx_bench.model_card import (
    END_MARKER,
    START_MARKER,
    render_benchmark_block,
    update_model_card,
    validate_post_publish_run,
)


MODEL_REPO = "Shiftedx/example-quant"
MODEL_REVISION = "a" * 40
BENCHMARK_REVISION = "b" * 40
VARIANT = "example"


def _write_run(tmp_path, *, omit_lane=None):
    counts = {"long-context": 15, "quality": 10, "tools": 6, "agentic": 2, "vision": 4}
    names = {"long-context": "context", "quality": "quality", "tools": "tools", "agentic": "agentic", "vision": "vision"}
    for lane, count in counts.items():
        if lane == omit_lane:
            count -= 1
        rows = []
        for index in range(count):
            metadata = {}
            if lane == "long-context":
                metadata = {
                    "target_prompt_tokens": [4096, 16384, 65536, 131072][min(index // 4, 3)],
                    "requested_position": 0.5,
                    "family": "single_key",
                }
            rows.append(
                {
                    "schema_version": "1.0",
                    "variant": VARIANT,
                    "lane": lane,
                    "case_id": f"{lane}-{index}",
                    "passed": index != count - 1 if lane == "quality" else True,
                    "metadata": metadata,
                    "telemetry": {
                        "wall_s": 2.0,
                        "decode_tokens_per_second": 20.0,
                        "active_memory_bytes": 16 * 1024 ** 3,
                    },
                }
            )
        (tmp_path / f"{names[lane]}.jsonl").write_text(
            "".join(json.dumps(row) + "\n" for row in rows), encoding="utf-8"
        )
        manifest = {
            "benchmark_version": "0.3.0",
            "variants": [{"label": VARIANT, "request_overrides": {}}],
            "evaluated_artifact": {"repo_id": MODEL_REPO, "revision": MODEL_REVISION},
            "benchmark_source": {
                "repo_id": "Shiftedx/shiftedx-bench",
                "revision": BENCHMARK_REVISION,
            },
        }
        (tmp_path / f"{names[lane]}.manifest.json").write_text(json.dumps(manifest), encoding="utf-8")


def test_post_publish_model_card_block_is_complete_and_idempotent(tmp_path):
    _write_run(tmp_path)
    rows, version = validate_post_publish_run(
        tmp_path,
        variant=VARIANT,
        profile="vision",
        model_repo=MODEL_REPO,
        model_revision=MODEL_REVISION,
        benchmark_revision=BENCHMARK_REVISION,
    )
    block = render_benchmark_block(
        rows,
        variant=VARIANT,
        model_repo=MODEL_REPO,
        model_revision=MODEL_REVISION,
        benchmark_revision=BENCHMARK_REVISION,
        benchmark_version=version,
        host="Apple Silicon, 64 GiB",
        runtime="MTPLX 2.7.1, reasoning on/medium, native tools",
        kv_cache="off",
        mtp_depth="3",
        max_window_status="host-limited",
    )
    readme = "# Example\n\n## Provenance and integrity\n"
    first = update_model_card(readme, block)
    second = update_model_card(first, block)
    assert first == second
    assert first.count(START_MARKER) == first.count(END_MARKER) == 1
    assert "15/15" in first
    assert "host watchdog" in first
    assert MODEL_REVISION in first and BENCHMARK_REVISION in first


def test_model_card_export_rejects_incomplete_or_wrong_revision(tmp_path):
    _write_run(tmp_path, omit_lane="vision")
    with pytest.raises(ValueError, match="Incomplete"):
        validate_post_publish_run(
            tmp_path,
            variant=VARIANT,
            profile="vision",
            model_repo=MODEL_REPO,
            model_revision=MODEL_REVISION,
            benchmark_revision=BENCHMARK_REVISION,
        )
    with pytest.raises(ValueError, match="provenance mismatch"):
        validate_post_publish_run(
            tmp_path,
            variant=VARIANT,
            profile="text",
            model_repo=MODEL_REPO,
            model_revision="c" * 40,
            benchmark_revision=BENCHMARK_REVISION,
        )


def test_model_card_renders_null_effective_context_as_not_established(tmp_path):
    _write_run(tmp_path)
    context_path = tmp_path / "context.jsonl"
    rows = [json.loads(line) for line in context_path.read_text().splitlines()]
    for row in rows:
        row["passed"] = False
    context_path.write_text(
        "".join(json.dumps(row) + "\n" for row in rows), encoding="utf-8"
    )
    validated, version = validate_post_publish_run(
        tmp_path,
        variant=VARIANT,
        profile="vision",
        model_repo=MODEL_REPO,
        model_revision=MODEL_REVISION,
        benchmark_revision=BENCHMARK_REVISION,
    )
    block = render_benchmark_block(
        validated,
        variant=VARIANT,
        model_repo=MODEL_REPO,
        model_revision=MODEL_REVISION,
        benchmark_revision=BENCHMARK_REVISION,
        benchmark_version=version,
        host="Apple Silicon, 64 GiB",
        runtime="MTPLX 2.7.1",
        kv_cache="off",
        mtp_depth="2",
        max_window_status="not-run",
    )
    assert "effective tested context: not established at the benchmark's 90% threshold" in block