Supported Formats

Entrenar supports multiple model serialization formats for different use cases.

Format Comparison

FormatExtensionBinaryHF CompatibleUse Case
SafeTensors.safetensorsYesYesProduction, sharing
JSON.jsonNoNoDebugging, inspection
YAML.yamlNoNoConfiguration
GGUF.ggufYesNoQuantized models

Choosing a Format

Use SafeTensors for:

  • Production deployments
  • Uploading to HuggingFace Hub
  • Large models (supports memory mapping)
  • Security-sensitive applications
#![allow(unused)]
fn main() {
let config = SaveConfig::new(ModelFormat::SafeTensors);
save_model(&model, "model.safetensors", &config)?;
}

JSON

Use JSON for:

  • Debugging and inspection
  • Small models
  • Human-readable output
  • Version control diffs
#![allow(unused)]
fn main() {
let config = SaveConfig::new(ModelFormat::Json).with_pretty(true);
save_model(&model, "model.json", &config)?;
}

YAML

Use YAML for:

  • Configuration files
  • Human-friendly syntax
  • Small models with metadata focus
#![allow(unused)]
fn main() {
let config = SaveConfig::new(ModelFormat::Yaml);
save_model(&model, "model.yaml", &config)?;
}

GGUF (Future)

GGUF format will be supported for:

  • Quantized model export
  • LLaMA.cpp compatibility
  • Integration with Realizar crate

Format Detection

Format is auto-detected from file extension:

#![allow(unused)]
fn main() {
// Auto-detect based on extension
let model = load_model("model.safetensors")?;  // SafeTensors
let model = load_model("model.json")?;         // JSON
let model = load_model("model.yaml")?;         // YAML
let model = load_model("config.yml")?;         // YAML (alternate extension)
}

Performance Characteristics

Format100MB Save100MB LoadCompression
SafeTensors~100ms~50ms1x
JSON~3s~2.5s~0.33x
YAML~4s~3.5s~0.29x

See Also