Download code/scripts/prepare_mk.py from changh95/DeepSeek-OCR-2: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/changh95/DeepSeek-OCR-2/resolve/main/code/scripts/prepare_mk.py
- Command line
-
hf download hf://changh95/DeepSeek-OCR-2/code/scripts/prepare_mk.py
-
curl -L -o prepare_mk.py https://huggingface.co/changh95/DeepSeek-OCR-2/resolve/main/code/scripts/prepare_mk.py
1.36 kB
| # SPDX-License-Identifier: Apache-2.0 | |
| """Pack the DEC-MoE megakernel weight arena on the CPU ahead of the first server start (no device needed). | |
| python -I prepare_mk.py <weights dir> <geo.json> [recipe=bfp8] [attk=4] | |
| geo.json: {"grid": [gx, gy], "opt0": [[x, y] x 8], "opt1": [...]} (the device's optimal DRAM-bank workers; the | |
| dev / server scripts write it). The arena lands in $DSOCR_MK_CACHE (default ~/.cache/tt_dsocr/mk_moe). | |
| """ | |
| import json | |
| 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 | |
| torch.set_num_threads(int(os.environ.get("DSOCR_THREADS", "3"))) | |
| from tt_dsocr.reference import model as R # noqa: E402 | |
| from tt_dsocr.tt.mk_moe import arena as A # noqa: E402 | |
| from tt_dsocr.tt.mk_moe import geometry as G # noqa: E402 | |
| from tt_dsocr.tt.mk_moe.program import RECIPES # noqa: E402 | |
| wdir, geo_json = sys.argv[1], sys.argv[2] | |
| recipe = RECIPES[sys.argv[3] if len(sys.argv) > 3 else "bfp8"] | |
| attk = int(sys.argv[4]) if len(sys.argv) > 4 else 4 | |
| g = json.load(open(geo_json)) | |
| geo = G.build(g["grid"][0], g["grid"][1], [tuple(c) for c in g["opt0"]], [tuple(c) for c in g["opt1"]], attk=attk) | |
| t0 = time.time() | |
| A.build_arena(R.Weights(wdir), geo, recipe, source=os.path.basename(os.path.normpath(wdir))) | |
| print(f"arena ready in {time.time() - t0:.0f} s") | |