File size: 1,072 Bytes
aa204f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# SPDX-License-Identifier: Apache-2.0
"""Pack the DEC megakernel weight streams ahead of the first device start (CPU only; cached under GLMOCR_MK_CACHE).

    python scripts/prepare_mk.py <model_dir> [recipe: bfp8 | bf16 | bfp8h8] [source revision]
"""
import os
import sys
import time

HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.dirname(HERE))

import torch  # noqa: E402

from tt_glmocr.tt.mk_dec import arena as A  # noqa: E402
from tt_glmocr.tt.mk_dec import weights as E  # noqa: E402


def main():
    model = sys.argv[1]
    recipe = E.RECIPES[sys.argv[2] if len(sys.argv) > 2 else "bfp8"]
    source = sys.argv[3] if len(sys.argv) > 3 else ""
    torch.set_num_threads(int(os.environ.get("GLMOCR_TORCH_THREADS", "3")))
    t0 = time.time()
    w = E.load_dec(model)
    s = A.build_streams(recipe, w, source=source)
    print(f"streams ready: {A.streams_path(recipe, source=source)} "
          f"({sum(len(x) for st in s for x in st.values()) / 2**20:.0f} MiB, {time.time() - t0:.0f} s)")


if __name__ == "__main__":
    main()