#!/usr/bin/env python3 # SPDX-License-Identifier: Apache-2.0 """Pack the DEC megakernel weight streams of one profile ahead of the first server start (CPU only, no device): the server finds them in PADDLEOCR_MK_CACHE (default ~/.cache/tt_paddleocr/mk_dec) and skips the ~1-2 min packing. python code/scripts/prepare_mk.py --profile 1.6 [--recipe bfp8] [--weights-dir DIR] """ import argparse import os import sys import time sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) def main(): ap = argparse.ArgumentParser() ap.add_argument("--profile", default="1.6") ap.add_argument("--recipe", default="bfp8h8") ap.add_argument("--weights-dir", default="") args = ap.parse_args() from tt_paddleocr.config import WEIGHTS, resolve_weights_dir from tt_paddleocr.tt.mk_dec import arena as A from tt_paddleocr.tt.mk_dec import weights as E wdir = args.weights_dir or resolve_weights_dir(args.profile) t0 = time.time() w = E.load_dec(wdir) A.build_streams(args.profile, E.RECIPES[args.recipe], w, source=WEIGHTS[args.profile][1]) print(f"done in {time.time() - t0:.0f} s -> {A.streams_path(args.profile, E.RECIPES[args.recipe], source=WEIGHTS[args.profile][1])}") if __name__ == "__main__": main()