| Crates.io | mlmf |
| lib.rs | mlmf |
| version | 0.2.0 |
| created_at | 2025-11-11 17:13:47.479528+00 |
| updated_at | 2025-11-11 22:26:01.707372+00 |
| description | Machine Learning Model Files - Loading, saving, and dynamic mapping for ML models |
| homepage | |
| repository | https://github.com/CireSnave/mlmf |
| max_upload_size | |
| id | 1927593 |
| size | 994,181 |
MLMF (Machine Learning Model Files) is a comprehensive Rust crate for working with ML model files. MLMF provides loading, saving, conversion, and dynamic mapping capabilities for transformer models across multiple formats including SafeTensors, GGUF, ONNX, PyTorch, and AWQ. It eliminates code duplication and provides a unified, efficient API for model file operations.
Add mlmf to your Cargo.toml:
[dependencies]
mlmf = "0.1"
use mlmf::{LoadOptions, loader};
use candle_core::{Device, DType};
// Load a LLaMA model from SafeTensors
let device = Device::cuda_if_available(0).unwrap_or(Device::Cpu);
let options = LoadOptions {
device: device.clone(),
dtype: DType::F16,
use_mmap: true,
validate_cuda: false,
progress: Some(mlmf::progress::default_progress()),
};
let loaded_model = loader::load_safetensors("./models/llama-7b", options)?;
// Access components
let var_builder = loaded_model.var_builder;
let config = loaded_model.config;
let name_mapper = loaded_model.name_mapper;
// Use name mapper to convert HF names to your format
if let Some(mapped_name) = name_mapper.map_name("model.layers.0.self_attn.q_proj.weight") {
println!("Mapped name: {}", mapped_name);
}
use mlmf::name_mapping::{TensorNameMapper, Architecture};
let tensor_names = vec![
"model.embed_tokens.weight".to_string(),
"model.layers.0.self_attn.q_proj.weight".to_string(),
"model.norm.weight".to_string(),
];
let mapper = TensorNameMapper::from_tensor_names(&tensor_names)?;
assert_eq!(mapper.architecture(), Architecture::LLaMA);
use mlmf::conversion::{convert_model, ConversionFormat, ConversionOptions};
use std::path::Path;
// Convert from SafeTensors to ONNX
let options = ConversionOptions::default();
let result = convert_model(
Path::new("model.safetensors"),
Path::new("model.onnx"),
ConversionFormat::ONNX,
options,
)?;
println!("Conversion completed in {:.2}s", result.duration.as_secs_f64());
MLMF provides a modular architecture with the following components:
loader: High-level loading APIconversion: Direct model format conversion with batch processingname_mapping: Architecture detection and tensor name mappingconfig: HuggingFace config parsing with field aliasesformats: Format-specific loaders and exporters (SafeTensors, GGUF, ONNX, PyTorch, AWQ)validation: CUDA validation and dtype checkingprogress: Progress reporting utilitiesSee the examples/ directory for complete working examples:
load_llama.rs - Loading LLaMA models from SafeTensorsload_gpt2.rs - Loading GPT-2 modelsload_gguf.rs - Loading quantized GGUF modelsMLMF is optimized for performance:
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
This project is licensed under either of:
at your option.