Model Modernizer is a production-ready Python CLI tool that detects a model type and converts it into a more modern/optimized format:
- LLM (Hugging Face) → GGUF (then quantize to q4_0)
- Stable Diffusion (Diffusers/HF) → Diffusers saved with
.safetensors - Whisper (Transformers/HF) → ONNX
Create a venv and install dependencies:
cd model-modernizer
python -m venv .venv
source .venv/bin/activate # Linux/macOS
# .venv\Scripts\activate # Windows PowerShell
pip install -r requirements.txtCommand:
python convert.py <model_path_or_hf_repo> <output_name>Example (Hugging Face repo):
python convert.py mistralai/Mistral-7B-v0.1 mistralExpected output style:
[INFO] Downloading model...
[INFO] Detected: LLM
[INFO] Converting to GGUF...
[INFO] Quantizing (q4)...
[SUCCESS] Model ready at output/mistral-q4.gguf
Outputs are written to output/ and logs to:
logs/success.loglogs/error.log
Detection logic is intentionally heuristic and fast:
- LLM: folder contains
config.jsonwith"architectures" - Diffusion: file/folder names contain
"diffusion","unet", or"vae" - Whisper: filename contains
"whisper"(also checks config markers) - Fallback: if unknown, it tries pipelines in order: LLM → diffusion → whisper
This tool calls llama.cpp’s conversion script and quantizer:
convert-hf-to-gguf.py(HF → GGUF f16)quantize/quantize.exe(GGUF → q4_0)
Clone and build llama.cpp (follow upstream instructions for your OS). Then point Model Modernizer to your llama.cpp checkout/binaries using environment variables:
LLAMA_CPP_DIR: path to llama.cpp folder (the tool will try common locations)- or set explicit paths:
LLAMA_CPP_CONVERT: full path toconvert-hf-to-gguf.pyLLAMA_CPP_QUANTIZE: full path toquantize/quantize.exe
Example (PowerShell):
$env:LLAMA_CPP_DIR="D:\tools\llama.cpp"
python convert.py mistralai/Mistral-7B-v0.1 mistralUses diffusers.StableDiffusionPipeline.from_pretrained() and saves using:
save_pretrained(..., safe_serialization=True)
Output is a directory:
output/<name>-diffusers/containing one or more.safetensorsfiles.
Uses transformers.WhisperForConditionalGeneration and exports an ONNX graph via torch.onnx.export.
Output:
output/<name>.onnx
- Auto-download: If input looks like
org/name, the tool downloads it from Hugging Face intomodels/. - Retry logic: If the detected pipeline fails, it automatically tries the remaining pipelines.
- Validation: Outputs are checked for existence and basic sanity (file size / presence of
.safetensors). - Clean errors: Errors are printed to terminal and always written to
logs/error.log.
- LLM → GGUF requires a working llama.cpp toolchain on your machine.
- Whisper → ONNX exports a generic seq2seq forward; some deployments may prefer separate encoder/decoder exports or additional optimization.
- Some model repos require authentication; set
HF_TOKENif needed.