Skip to content

feat(mlx-lm): add HuggingFace Hub model loader - #352

Open
fiorelorenzo wants to merge 1 commit into
oxiglade:mainfrom
fiorelorenzo:feat/hf-hub-loader
Open

feat(mlx-lm): add HuggingFace Hub model loader#352
fiorelorenzo wants to merge 1 commit into
oxiglade:mainfrom
fiorelorenzo:feat/hf-hub-loader

Conversation

@fiorelorenzo

Copy link
Copy Markdown

Adds a sync snapshot_download(model_id, &opts) -> LoadedFiles to mlx-lm so callers can fetch model files from the HuggingFace Hub instead of pointing at a hardcoded local path. Resolves config.json, tokenizer.json, tokenizer_config.json (optional), and either a single model.safetensors or the sharded set described by model.safetensors.index.json.

Promotes the existing WeightMap struct from models/qwen3.rs into the new loader module; models/llama.rs and models/qwen3.rs import from there. No behaviour change in the existing model loaders.

Adds hf-hub = "0.4.3" (matching examples/mistral/Cargo.toml) and a hub-test feature gate so the live-network test stays #[ignore] by default in CI (which already runs --test-threads=1 for MLX thread-safety).

Tests:

  • Unit test for WeightMap JSON parsing and value dedup.
  • Integration test (hub-test feature, #[ignore]) that resolves the mlx-community/Qwen3-0.6B-bf16 config.

Prerequisite for #274 (umbrella mlx_lm-equivalent) and #329 (OpenAI-compatible API server). Does not yet update the example in examples/lm/ to use the new loader; that is a follow-up to keep this PR focused on the loader itself.

Adds mlx-lm/src/loader.rs with a sync snapshot_download(model_id, &opts)
that resolves config.json, tokenizer.json, tokenizer_config.json
(optional), and either a single model.safetensors or the sharded set
described by model.safetensors.index.json.

Promotes WeightMap from models/qwen3.rs to the shared loader module;
models/llama.rs and models/qwen3.rs import from there.

Adds hf-hub = "0.4.3" (matching examples/mistral) and a hub-test
feature gate for the live-network integration test (#[ignore] by
default; CI keeps --test-threads=1 since MLX is not thread-safe).

Refs oxiglade#274 (umbrella mlx_lm-equivalent), oxiglade#329 (OpenAI server).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant