File size: 1,102 Bytes
35f2d9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Quantization settings for the published decoder; this script never retrains it."""

import argparse
import hashlib
from pathlib import Path

from onnxruntime.quantization import QuantType, quantize_dynamic


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("input", type=Path, help="Original FP32 decoder_model.onnx")
    parser.add_argument("output", type=Path, help="New INT8 decoder output path")
    args = parser.parse_args()
    expected = "6b1fb216d542c4b2a4fa5b9d7ae3522081eb85fb959d2cecd28055af956a8a5e"
    actual = hashlib.sha256(args.input.read_bytes()).hexdigest()
    if actual != expected:
        parser.error(f"Input SHA-256 mismatch: {actual}")
    if args.output.exists():
        parser.error("Output already exists; choose a new path")
    quantize_dynamic(
        str(args.input), str(args.output),
        op_types_to_quantize=["MatMul"],
        weight_type=QuantType.QInt8,
        per_channel=True,
    )
    print(hashlib.sha256(args.output.read_bytes()).hexdigest(), args.output.name)


if __name__ == "__main__":
    main()