ONNX
onnxruntime
onnx-mlir
quantization
fp32
File size: 1,595 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
#!/usr/bin/env python3
"""Validate model configs and run results against their schemas."""

from __future__ import annotations

import argparse
import json
import sys
from pathlib import Path

from pipeline_common import REPO_ROOT, basic_validate_config, load_json


def main() -> int:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("paths", nargs="+", type=Path)
    parser.add_argument("--kind", choices=("config", "result"), default="config")
    args = parser.parse_args()
    schema_path = REPO_ROOT / ("schemas/model_config.schema.json" if args.kind == "config" else "schemas/run_result.schema.json")
    schema = load_json(schema_path)
    try:
        import jsonschema  # type: ignore
    except ImportError:
        jsonschema = None
    failed = 0
    for path in args.paths:
        value = load_json(path)
        errors = basic_validate_config(value) if args.kind == "config" else []
        if jsonschema is not None:
            validator = jsonschema.Draft202012Validator(schema)
            errors.extend(error.message for error in validator.iter_errors(value))
        if errors:
            failed += 1
            print(json.dumps({"path": str(path), "status": "FAIL", "errors": sorted(set(errors))}, ensure_ascii=False))
        else:
            print(json.dumps({
                "path": str(path), "status": "PASS",
                "validator": "jsonschema" if jsonschema is not None else "stdlib-structural",
            }, ensure_ascii=False))
    return 1 if failed else 0


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