Expand description
CLI-level model source resolution.
Centralises the lookup chain that run / serve / bench were
reinventing each in their own copy:
- Curated GGUF alias — resolve an explicit quantized alias to one repository and filename.
- GGUF file path — if the user passed an existing
*.gguffile, build aResolvedModelSourcedirectly without HF lookup. - Local model dir — if the path is an existing directory with
config.json+ weights, treat it as a direct source. - HF cache hit —
~/.cache/huggingface/hub/models--<owner>--<repo>/snapshots/<rev>. - HF download — fall back to [
HfDownloader] (run/serveonly;benchcallers may opt out). - GPU-memory autosizing — for GPU backends, run the chat
autosizer once on the resolved snapshot so
FERRUM_KV_MAX_BLOCKSetc. are populated before the engine starts.
Before this module each command had its own find_cached_model /
detect_format (some forked, some pub fn-imported across files),
its own GGUF early-return, and its own autosize call site. The
duplication caused subtle drift (e.g. serve accepting a non-existent
.gguf path because it didn’t call looks_like_gguf_path exactly the
same way as run). All callers now go through
resolve_model_source.
Structs§
- Product
Engine Input - Atomic handoff from source resolution into a product engine composition. Keeping the original source inside the base config prevents entrypoints or architecture arms from retaining only the resolved cache path.
- Product
Source Args - Explicit role-specific model metadata sources shared by
runandserve. The physical weight source remains the positional MODEL argument. - Resolved
- Resolution outcome — a fully-resolved local source plus a flag the caller can use to decide whether to apply GPU autosize.
Enums§
- Download
Policy - Should the resolver attempt to download from HF if the model isn’t
found locally?
run/servesay yes;benchdefaults to no (caller handles per-bench-flow download policy).
Constants§
- CUDA_
FIRST_ SUCCESS_ MODEL - METAL_
FIRST_ SUCCESS_ MODEL - Small, release-supported starter models used by CLI guidance. These are intentionally not implicit defaults: users should see what will download.
Functions§
- apply_
chat_ profile_ env - Chat-profile runtime defaults for
ferrum run. Sniffs the arch (dense vs MoE — works for both GGUF files and safetensors snapshot dirs) and materializes missing compatibility env vars for: - chat_
profile_ runtime_ entries - detect_
format - Detect the on-disk format of a model directory or file.
- detect_
model_ family - detect_
moe_ arch - Detect whether
pathis a Mixture-of-Experts model. Handles both a.gguffile (peekgeneral.architecturefrom GGUF metadata) and a safetensors snapshot directory (readconfig.jsonand matcharchitectures/model_typeagainstmoe, case-insensitive). - find_
cached_ gguf - Locate one exact GGUF artifact in the Hugging Face cache.
- find_
cached_ model - Look up
model_idin the HF cache (hub/models--owner--repo/snapshots/<rev>). Returns the resolved snapshot path + detected format, orNoneif not cached. - first_
success_ model_ help - Keep missing-model guidance identical for
runandserve. - hf_
cache_ dir - Resolve the single Hugging Face cache root used by product entrypoints.
- load_
model_ chat_ template - Load a model-provided chat template, if the source carries one.
- load_
prepared_ product_ chat_ template - load_
product_ chat_ template - Load the chat template from bytes retained by the immutable tokenizer source lease. The legacy path-based loader remains for direct GGUF files.
- looks_
like_ gguf_ path - True iff
modelis a path to an existing*.gguffile. - metal_
gguf_ moe_ correctness_ entries - Correctness fallback for Metal GGUF MoE.
- prepare_
registered_ product_ model - Prepare a migrated typed family exactly once at the product composition
boundary. Explicit legacy registrations return
None; unknown metadata is rejected by the model registry instead of gaining an implicit fallback. - prepared_
product_ source_ identity - public_
model_ id - Stable product-facing model id derived from one resolved source.
- resolve_
gguf_ alias - Resolve a GGUF alias to its repository and exact quantized filename.
- resolve_
model_ alias - Resolve an ergonomic model alias to its canonical Hugging Face model id.
- resolve_
model_ source - One-stop model resolution. Caller passes the user’s model arg
(alias / HF id / local dir /
.ggufpath), the HF cache dir, and a download policy + autosize profile. Returns a resolved source. - resolve_
model_ source_ with_ product_ sources - Resolve one physical model and then replace only the explicitly selected semantic/tokenizer roles. This keeps the positional MODEL as the sole weight source while allowing quantized checkpoints to consume canonical base-model semantics without a model-name mapping or hidden environment.
- serve_
profile_ runtime_ entries - Product defaults for
ferrum serveon GGUF LLMs. - serve_
profile_ runtime_ entries_ for_ arch - tokenizer_
sibling_ repo - Resolve the tokenizer sidecar repository for a GGUF repository.