Qwen3-ASR / code /scripts /prepare_mk.py
changh95's picture
tt-model push qwen3-asr (container)
d9f9acd verified
Raw History Blame Contribute Delete
1.59 kB
# SPDX-License-Identifier: Apache-2.0
"""Pack the DEC megakernel weight streams of a profile on the CPU (no device) ahead of the first start (optional: the
server packs them itself on a cache miss, ~0.5-2.5 min, and reuses them on every later start):
QWEN3ASR_MK_CACHE=<cache dir>/mk_dec python code/scripts/prepare_mk.py --weights <ckpt dir> --profile 1.7b \
[--recipe attn=bfp8,mlp=bfp8,head=bfp8] [--source <weights revision, as the server's TT_MODEL_WEIGHTS_REVISION>]
The cache key covers the profile, the recipe, the revision and the stream layout."""
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("--weights", required=True)
ap.add_argument("--profile", required=True)
ap.add_argument("--recipe", default="attn=bfp8,mlp=bfp8,head=bfp8")
ap.add_argument("--source", default="")
args = ap.parse_args()
import torch
torch.set_num_threads(int(os.environ.get("OMP_NUM_THREADS", "3")))
from tt_qwen3_asr.tt.mk_dec import arena as A
from tt_qwen3_asr.tt.mk_dec.weights import load_dec
recipe = dict(kv.split("=") for kv in args.recipe.split(",") if kv)
t0 = time.time()
w = load_dec(args.weights)
print(f"weights {time.time() - t0:.0f} s", flush=True)
A.build_streams(args.profile, recipe, w, source=args.source)
print(f"done {time.time() - t0:.0f} s -> {A.streams_path(args.profile, recipe, source=args.source)}", flush=True)
if __name__ == "__main__":
main()