package kaun
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=8e277ed56615d388bc69c4333e43d1acd112b5f2d5d352e2453aef223ff59867
sha512=369eda6df6b84b08f92c8957954d107058fb8d3d8374082e074b56f3a139351b3ae6e3a99f2d4a4a2930dd950fd609593467e502368a13ad6217b571382da28c
doc/kaun.huggingface/Kaun_huggingface/index.html
Module Kaun_huggingface
Source
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_result
download_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 ->
dtype:(float, 'a) Rune.dtype ->
unit ->
'a Kaun.params download_result
load_safetensors ~model_id ~dtype ()
downloads and loads safetensors weights. Automatically tries common filenames like "model.safetensors".
val load_config :
?config:Config.t ->
?revision:revision ->
model_id:model_id ->
unit ->
Yojson.Safe.t download_result
load_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 ->
dtype:(float, 'a) Rune.dtype ->
unit ->
'a Kaun.params
from_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