Skip to main content

Crate ferrotorch_hub

Crate ferrotorch_hub 

Source
Expand description

Pretrained model registry, download, and caching for ferrotorch.

This crate provides a central hub for discovering, downloading, and caching pretrained model weights. It mirrors the workflow of torch.hub and torchvision.models with pretrained weight support.

§Quick start

use ferrotorch_core::FerrotorchError;
use ferrotorch_hub::{list_models, load_pretrained};

fn main() -> Result<(), FerrotorchError> {
    // Browse available models.
    for model in list_models() {
        println!("{}: {} ({} params)", model.name, model.description, model.num_parameters);
    }

    // Load pretrained weights (requires cached weights on disk).
    let _state_dict = load_pretrained::<f32>("resnet50")?;
    Ok(())
}

§REQ status (per .design/ferrotorch-hub/lib.md)

REQStatusEvidence
REQ-1SHIPPEDpub mod declarations in lib.rs (auth / discovery http-gated; cache / download / hf_config / registry unconditional); non-test consumer: ferrotorch-llama/src/config.rs imports HfTransformerConfig from the crate root.
REQ-2SHIPPEDpub use re-export block in lib.rs flattening the user-facing surface; non-test consumer: ferrotorch/src/lib.rs pub mod hub { pub use ferrotorch_hub::*; } (feature hub) re-exports the whole flat surface through the meta-crate; ferrotorch-jit/examples/jit_trace_dump.rs imports load_pretrained directly from the crate root.
REQ-3SHIPPEDcrate-level #![warn(clippy::all, clippy::pedantic)] + #![deny(rust_2018_idioms)] + per-lint #![allow] block with one-line justifications in lib.rs; non-test consumer: every dependent crate (ferrotorch-llama, ferrotorch-bert, ferrotorch-diffusion, ferrotorch-jit, ferrotorch-rl, ferrotorch-graph) requires cargo clippy -p ferrotorch-hub --lib -- -D warnings to pass before its own build can succeed.
REQ-4SHIPPEDthe deliberately-omitted unsafe_code deny in the lint-header block (documented in the comment); non-test consumer: auth.rs::mod tests is #[cfg(test)]-only so production callers never trip the unsafe paths; the lint posture lets the test module compile without crate-root override.
REQ-5SHIPPED#[cfg(feature = "http")] guards on pub mod auth;, pub mod discovery;, pub use auth::…;, pub use discovery::…;, and pub use download::hf_download_model;; offline path in download.rs::download_weights; non-test consumer: ferrotorch-jit/Cargo.toml declares ferrotorch-hub = { workspace = true, features = ["http"] } for the jit_trace_dump example; the meta-crate’s hub cargo feature flows through to the same conditional.

Re-exports§

pub use auth::hf_token;
pub use auth::with_auth;
pub use cache::HubCache;
pub use cache::default_cache_dir;
pub use discovery::HfModelInfo;
pub use discovery::HfModelSummary;
pub use discovery::HfRepoFile;
pub use discovery::SearchQuery;
pub use discovery::get_model;
pub use discovery::search_models;
pub use download::hf_download_model;
pub use download::download_weights;
pub use download::load_pretrained;
pub use hf_config::HfTransformerConfig;
pub use registry::EntryKind;
pub use registry::ModelInfo;
pub use registry::WeightsFormat;
pub use registry::get_model_info;
pub use registry::list_models;

Modules§

auth
HuggingFace Hub authentication helpers (#509).
cache
Local cache for pretrained model weights.
discovery
Dynamic model discovery via the HuggingFace Hub API.
download
Download and load pretrained model weights.
hf_config
HuggingFace transformer config.json parser.
registry
Pretrained model registry.