Download code/export_gpu.py from ivanfioravanti/d1-2B-gestures-CoreAI: direct link, hf CLI and curl.
- Browser
- Download file 982 Bytes
-
https://huggingface.co/ivanfioravanti/d1-2B-gestures-CoreAI/resolve/main/code/export_gpu.py
- Command line
-
hf download hf://ivanfioravanti/d1-2B-gestures-CoreAI/code/export_gpu.py
-
curl -L -o export_gpu.py https://huggingface.co/ivanfioravanti/d1-2B-gestures-CoreAI/resolve/main/code/export_gpu.py
982 Bytes
| """Stage 2: export the fixed d1 decision function to .aimodel (GPU layout, fp16 weights and compute). | |
| .venv/bin/python export_gpu.py # -> out/d1_gpu_fp16.aimodel | |
| """ | |
| import os, sys, time | |
| import torch | |
| from coreai_models.export.macos import export_to_coreai | |
| from d1_common import load_meta | |
| from d1_torch import D1Fixed | |
| out = sys.argv[1] if len(sys.argv) > 1 else "out/d1_gpu_fp16.aimodel" | |
| meta = load_meta() | |
| model = D1Fixed(meta, torch.float16).eval() | |
| _, gh, gw = meta["grid_thw"] | |
| ref = {"image": torch.zeros(1, 3, gh * 16, gw * 16, dtype=torch.float32)} | |
| t = time.time() | |
| program = export_to_coreai(model, ref, input_names=("image",), output_names=("logits",)) | |
| print("export_to_coreai %.1fs" % (time.time() - t), flush=True) | |
| t = time.time() | |
| program.optimize() | |
| print("optimize %.1fs" % (time.time() - t), flush=True) | |
| if os.path.exists(out): | |
| import shutil | |
| shutil.rmtree(out) | |
| from pathlib import Path | |
| program.save_asset(Path(out)) | |
| print("saved", out, flush=True) | |