ONNX
onnxruntime
onnx-mlir
quantization
fp32
File size: 2,440 Bytes
ed3aeeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

import argparse
import csv
import hashlib
from pathlib import Path

from scripts import validate_mlir_ir_graphs as validator


def digest(path: Path) -> str:
    return hashlib.sha256(path.read_bytes()).hexdigest()


def test_primary_graph_validator_accepts_exact_42_image_set(tmp_path: Path) -> None:
    rows: list[dict[str, str]] = []
    report_dir = tmp_path / "reports/graphs/mlir"
    for model_index in range(21):
        model_id = f"M{model_index:02d}"
        for variant in ("fp32", "public_quantized"):
            source = tmp_path / "models" / model_id / variant / "onnx.mlir"
            source.parent.mkdir(parents=True)
            source.write_text("module {}\n", encoding="utf-8")
            rows.append(
                {
                    "model_id": model_id,
                    "variant": variant,
                    "onnx_status": "PASS",
                    "onnx_artifact": str(source.relative_to(tmp_path)),
                    "onnx_sha256": digest(source),
                }
            )
            graph_dir = report_dir / "graphs" / model_id / variant / "onnx"
            graph_dir.mkdir(parents=True)
            graph_id = f"{model_id}:{variant}:ONNX"
            (graph_dir / "execution_dependency_graph.svg").write_text(
                f"<svg><text>{graph_id} STATIC_MLIR_PROGRAM_ORDER</text></svg>\n",
                encoding="utf-8",
            )
            (graph_dir / "execution_dependency_graph.png").write_bytes(
                b"\x89PNG\r\n\x1a\nfixture"
            )

    matrix = tmp_path / "reports/conversion/ir_stage_coverage.csv"
    matrix.parent.mkdir(parents=True)
    with matrix.open("w", newline="", encoding="utf-8") as stream:
        writer = csv.DictWriter(stream, fieldnames=list(rows[0]))
        writer.writeheader()
        writer.writerows(rows)

    result, exit_code = validator.validate(
        argparse.Namespace(
            repo_root=tmp_path,
            report_dir=Path("reports/graphs/mlir"),
            coverage_matrix=Path("reports/conversion/ir_stage_coverage.csv"),
            output=Path("logs/validation.json"),
        )
    )
    assert exit_code == 0
    assert result["status"] == "PASS"
    assert result["counts"]["models"] == 21
    assert result["counts"]["variants"] == 42
    assert result["counts"]["svg"] == 42
    assert result["counts"]["png"] == 42
    assert result["counts"]["failed"] == 0