"""Export final inference weights and reference logits; no converter dependency.""" import argparse import hashlib import gzip import shutil import json from pathlib import Path import numpy as np import tensorflow as tf from train import Config, make_model def main(): parser = argparse.ArgumentParser() parser.add_argument("run", type=Path) parser.add_argument("output", type=Path) parser.add_argument("--quantize", action="store_true", help="Export affine uint8 download weights") args = parser.parse_args() tf.config.threading.set_intra_op_parallelism_threads(4) tf.config.threading.set_inter_op_parallelism_threads(1) gpus = tf.config.list_physical_devices('GPU') if gpus: tf.config.set_visible_devices(gpus[0], 'GPU') tf.config.experimental.set_memory_growth(gpus[0], True) config = Config(**json.loads((args.run / "config.json").read_text())["model"]) model = make_model(config) checkpoint = tf.train.latest_checkpoint(str(args.run / "checkpoints")) tf.train.Checkpoint(model=model).restore(checkpoint).expect_partial().assert_existing_objects_matched() args.output.mkdir(parents=True, exist_ok=True) specs = [] digest = hashlib.sha256() original_digest = hashlib.sha256() binary = args.output / ("weights-int8.bin" if args.quantize else "weights.bin") with binary.open("wb") as stream: def weight(name, value, shape=None): array = value.numpy().astype("