package kaun
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=93abc49d075a1754442ccf495645bc4fdc83e4c66391ec8aca8fa15d2b4f44d2
sha512=5eb958c51f30ae46abded4c96f48d1825f79c7ce03f975f9a6237cdfed0d62c0b4a0774296694def391573d849d1f869919c49008acffca95946b818ad325f6f
doc/kaun.huggingface/Kaun_huggingface/index.html
Module Kaun_huggingfaceSource
Kaun_huggingface: HuggingFace model hub integration for Kaun.
Provides seamless loading of pretrained models from HuggingFace, with automatic downloading, caching, and type-safe model definitions.
Types
HuggingFace model identifier (e.g., "gpt2", "bert-base-uncased")
Local cache directory for downloaded models
Configuration
Model Registry
Registry of known model architectures with their loading functions
Core Loading Functions
val download_file :
?config:Config.t ->
?revision:revision ->
model_id:model_id ->
filename:string ->
unit ->
string download_resultdownload_file ~model_id ~filename () downloads a single file from HuggingFace. Returns the local path to the file (either cached or newly downloaded).
val load_safetensors :
?config:Config.t ->
?revision:revision ->
model_id:model_id ->
unit ->
Kaun.params download_resultload_safetensors ~model_id ~dtype () downloads and loads safetensors weights. Checks for sharded checkpoints via "model.safetensors.index.json" (and similar) and merges the shards, falling back to single-file safetensors names only when no index is present.
val load_config :
?config:Config.t ->
?revision:revision ->
model_id:model_id ->
unit ->
Yojson.Safe.t download_resultload_config ~model_id () downloads and parses the model's config.json
High-level Model Loading
val from_pretrained :
?config:Config.t ->
?revision:revision ->
model_id:model_id ->
unit ->
Kaun.paramsfrom_pretrained ~model_id ~dtype () loads a complete model.
This is the main entry point for loading models. It: 1. Downloads the model configuration 2. Downloads the model weights 3. Loads and returns the parameter tree
Example:
let gpt2_params =
Kaun_huggingface.from_pretrained ~model_id:"gpt2" ~dtype:Rune.Float32 ()Utilities
List all models in the local cache
Clear the cache for a specific model or all models
Fetch model card/info from HuggingFace API