Skip to main content

Module loader

Module loader 

Source
Expand description

One place to describe where a model’s weights live and how to load them.

Before this module every runner reimplemented the same download block: split the repo id, build an [HFClientSync], download a file, then either unsafe { VarBuilder::from_mmaped_safetensors(..) } or PthTensors::new(..). Six near-identical copies drifted apart — only ESM3 attached any error context, and every one of them inherited the same silently-wrong repo-id split (split_once('/').unwrap_or(("", repo_id)), which turns a malformed id into an empty owner and a confusing 404 rather than a clear error).

The pieces here are:

  • WeightSource — plain const data on each model enum: which repo, which revision, and which on-disk Format the weights use.
  • LoadOptions — the device and dtype to load onto, so the six per-module const *_DTYPE definitions collapse into one field.
  • WeightSource::var_builder — the single place holding the unsafe mmap.
  • optional_prefix — the “is this checkpoint wrapped in an HF *ForMaskedLM class?” probe, generalised from ESMC’s esmc. special case.
const WEIGHTS: WeightSource = WeightSource::safetensors("facebook/esm2_t6_8M_UR50D");

let opts = LoadOptions::new(Device::Cpu);
let vb = WEIGHTS.var_builder("model.safetensors", &opts)?;

Structs§

LoadOptions
Device and dtype to load a model onto.
WeightSource
Where a model’s weights live on the HuggingFace hub, and how to read them.

Enums§

Format
How a checkpoint is stored on disk.

Functions§

optional_prefix
Descend into prefix when the checkpoint nests the backbone under it.
var_builder_from_path
Build a [VarBuilder] over a local weight file of the given Format.