File size: 1,592 Bytes
d9f9acd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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()