Fix portability: runtime paths, missing setup scripts, vocab format bug#1
Open
msitarzewski wants to merge 2 commits intodanveloper:mainfrom
Open
Fix portability: runtime paths, missing setup scripts, vocab format bug#1msitarzewski wants to merge 2 commits intodanveloper:mainfrom
msitarzewski wants to merge 2 commits intodanveloper:mainfrom
Conversation
…ripts, fix vocab format - Replace hardcoded /Users/danielwoods paths with runtime $HOME resolution that auto-discovers the HuggingFace snapshot directory - Add generate_expert_index.py: scans safetensors headers to produce expert_index.json, which repack_experts.py requires but had no generator - Add export_vocab.py: generates vocab.bin in the simple decode format that infer.m's load_vocab() expects. The existing export_tokenizer.py produces a BPE format (magic "BPET") which load_vocab() misreads as num_entries=1.1B, causing an OOM kill on startup - Skip mmap for 120GB expert layer files to avoid OOM kills on systems with memory pressure; pread() fallback works fine Tested on M5 Max (128GB) — 15.66 tok/s with 2-bit experts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
just demo'd using this branch with some minor changes, thanks |
metal_infer/export_vocab.py
Outdated
| if b: | ||
| f.write(b) | ||
|
|
||
| import os |
Addresses review feedback from @0xClandestine — the import was used (for os.path.getsize) but placed inline at the bottom of main(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
crnzkhjcm
reviewed
Mar 23, 2026
|
|
||
| #define MODEL_PATH_DEFAULT "/Users/danielwoods/.cache/huggingface/hub/models--mlx-community--Qwen3.5-397B-A17B-4bit/snapshots/39159bd8aa74f5c8446d2b2dc584f62bb51cb0d3" | ||
| // MODEL_PATH_DEFAULT is resolved at runtime via get_default_model_path() below | ||
| #define MODEL_PATH_DEFAULT NULL |
There was a problem hiding this comment.
We can remove this, since this not used anywhere
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/Users/danielwoods/...paths with$HOME-based auto-discovery of the HuggingFace snapshot directory. Works for any user on any machine.generate_expert_index.py— the missing script that producesexpert_index.jsonfrom safetensors headers.repack_experts.pyrequires this file but the repo had no way to generate it.export_vocab.py— generatesvocab.binin the simple decode format thatinfer.m'sload_vocab()expects. The existingexport_tokenizer.pyproduces a BPE tokenizer format (magic bytes "BPET") whichload_vocab()misreads asnum_entries=1,112,888,660, causing an instant OOM kill on startup.pread()when mmap is unavailable, which is the primary I/O path anyway.Testing
Tested end-to-end on Apple M5 Max (128GB RAM, 8TB SSD):
generate_expert_index.pycorrectly produced 540 entries (60 layers × 9 components)export_vocab.pyproduced 248,077 vocab entries./infer --prompt "hi" --tokens 10 --2bit→ 15.66 tok/s (vs 5.55 on the original M3 Max)./infer --serve 6601 --2bit+./chat --port 6601→ interactive chat workingTest plan
makebuilds without errorsgenerate_expert_index.py --model <path>produces validexpert_index.jsonexport_vocab.py <tokenizer.json>produces workingvocab.bin./infer --prompt "test" --tokens 10 --2bitgenerates coherent output--serve) + chat client work end-to-end🤖 Generated with Claude Code