Prompt as inputs (no baked questions), split Neural Engine model for iOS, card and code
7011ac6 verified Download code/export_ane.py from ivanfioravanti/d1-2B-gestures-CoreAI: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/ivanfioravanti/d1-2B-gestures-CoreAI/resolve/main/code/export_ane.py
- Command line
-
hf download hf://ivanfioravanti/d1-2B-gestures-CoreAI/code/export_ane.py
-
curl -L -o export_ane.py https://huggingface.co/ivanfioravanti/d1-2B-gestures-CoreAI/resolve/main/code/export_ane.py
1.15 kB
| """Stage 2: export the BC1S (Neural Engine layout) d1 function to .aimodel, fp16. | |
| .venv/bin/python export_ane.py [out/d1_ane_prompt_fp16.aimodel] | |
| """ | |
| import os, shutil, sys, time | |
| from pathlib import Path | |
| import torch | |
| from coreai_models.export.macos import export_to_coreai | |
| from d1_common import embeddings, load_meta, prompt_inputs | |
| from d1_torch import D1Fixed | |
| from d1_ane import D1ANE | |
| out = Path(sys.argv[1] if len(sys.argv) > 1 else "out/d1_ane_prompt_fp16.aimodel") | |
| meta = load_meta() | |
| D1ANE.MLP_SPLIT = int(os.environ.get("MLP_SPLIT", D1ANE.MLP_SPLIT)) | |
| model = D1ANE(D1Fixed(meta, torch.float16)).eval() | |
| _, gh, gw = meta["grid_thw"] | |
| ref = {"image": torch.zeros(1, 3, gh * 16, gw * 16, dtype=torch.float32), | |
| **{k: torch.from_numpy(v) for k, v in prompt_inputs(meta, embeddings()).items()}} # the questions are inputs | |
| t = time.time() | |
| program = export_to_coreai(model, ref, input_names=("image", "text", "head", "attend", "slots"), output_names=("logits",)) | |
| print("export_to_coreai %.1fs" % (time.time() - t), flush=True) | |
| program.optimize() | |
| if out.exists(): | |
| shutil.rmtree(out) | |
| program.save_asset(out) | |
| print("saved", out, flush=True) | |