Skip to main content

load_model

Function load_model 

Source
pub fn load_model(path: impl AsRef<Path>) -> Result<LoadedModel>
Expand description

Loads a model file, choosing GGUF or SafeTensors by sniffing its content.

§Why content, not extension

GGUF files always start with the four-byte magic b"GGUF" (GgufLoader::probe), so sniffing it is exact. SafeTensors has no magic number at all — a file starting with anything other than the GGUF magic is assumed to be SafeTensors and handed to SafeTensorsLoader, which will itself fail with Error::MalformedModel if that assumption is wrong. This is still preferable to trusting a .gguf/.safetensors extension: an extension is metadata about the file, supplied by whoever named it, not a fact about the bytes — sniffing means a renamed or extension-less file still loads correctly, and a genuinely unrecognized file still fails loudly rather than silently mis-parsing.