Download code/scripts/prepare_mk.py from changh95/GLM-OCR: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/changh95/GLM-OCR/resolve/main/code/scripts/prepare_mk.py
- Command line
-
hf download hf://changh95/GLM-OCR/code/scripts/prepare_mk.py
-
curl -L -o prepare_mk.py https://huggingface.co/changh95/GLM-OCR/resolve/main/code/scripts/prepare_mk.py
1.07 kB
| # 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() | |