manancode/hn
By manancode · ↓ 0 · ♥ 0 · Updated 2025-09-10
What's in this repo
This page lists the files in manancode/hn, including madlad_decoder.onnx, madlad_encoder.onnx, decoder_model.onnx and more.
- 5 ONNX models (.onnx files)
- 20 files, including 8 .json, 5 .onnx, 2 .model, 1 .md, 1 .py, 1 .onnx_data
- Last updated 2025-09-10
ONNX files
| File | Size | Download |
|---|---|---|
| model/madlad_decoder.onnx | — | Download |
| model/madlad_encoder.onnx | — | Download |
| original_models/decoder_model.onnx | — | Download |
| original_models/decoder_with_past_model.onnx | — | Download |
| original_models/encoder_model.onnx | — | Download |
How to use
These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.
README
Madlad-400-3B-MT ONNX Optimized
This repository contains the optimized ONNX export of the jbochi/madlad400-3b-mt model, optimized for reduced memory consumption following the NLLB optimization approach.
Model Description
- Base Model: jbochi/madlad400-3b-mt
- Optimization: Component separation for reduced RAM usage
- Target: Mobile and edge deployment
- Format: ONNX with separated components
Files Structure
Optimized Components (/model/)
madlad_encoder.onnx- Encoder componentmadlad_decoder.onnx- Decoder componentmadlad_decoder.onnx_data- Decoder weights datatokenizer_config.json- Tokenizer configurationspecial_tokens_map.json- Special tokens mappingspiece.model- SentencePiece tokenizer modelinference_script.py- Python inference script
Original Models (/original_models/)
- Complete original ONNX exports for reference
Optimization Benefits
- Memory Reduction: Separated shared components to avoid duplication
- Mobile Ready: Optimized for deployment on mobile devices
- Modular: Components can be loaded independently as needed
Usage
# Basic usage with the optimized models
from transformers import T5Tokenizer
import onnxruntime as ort
# Load tokenizer
tokenizer = T5Tokenizer.from_pretrained("manancode/madlad400-3b-mt-onnx-optimized", subfolder="model")
# Load ONNX models
encoder_session = ort.InferenceSession("model/madlad_encoder.onnx")
decoder_session = ort.InferenceSession("model/madlad_decoder.onnx")
# For detailed inference, see inference_script.py
Translation Example
# Input format: <2xx> text (where xx is target language code)
text = "<2pt> I love pizza!" # Translate to Portuguese
# Expected output: "Eu amo pizza!"
Language Codes
This model supports translation to 400+ languages. Use the format <2xx> where xx is the target language code:
<2pt>- Portuguese<2es>- Spanish<2fr>- French<2de>- German- And many more...
Performance Notes
- Original Model Size: ~3.3B parameters
- Memory Optimization: Reduced RAM usage through component separation
- Inference Speed: Optimized for faster generation with separated components
Technical Details
Optimization Approach
This optimization follows the same principles used for NLLB models:
- Component Separation: Split encoder/decoder into separate files
- Weight Deduplication: Avoid loading shared weights multiple times
- Memory Efficiency: Load only required components during inference
Export Process
The models were exported using:
optimum-cli export onnx --model jbochi/madlad400-3b-mt --task text2text-generation-with-past --optimize O3
Requirements
torch>=1.9.0
transformers>=4.20.0
onnxruntime>=1.12.0
sentencepiece>=0.1.95
optimum[onnxruntime]>=1.14.0
Citation
@misc{madlad-onnx-optimized,
title={Madlad-400-3B-MT ONNX Optimized},
author={manancode},
year={2024},
publisher={Hugging Face},
url={https://huggingface.co/manancode/madlad400-3b-mt-onnx-optimized}
}
Credits
- Base Model: jbochi/madlad400-3b-mt by @jbochi
- Optimization Technique: Inspired by NLLB ONNX optimizations
- Export Tools: HuggingFace Optimum
License
This work is based on the original Madlad-400 model. Please refer to the original model's license terms.
Files (20)
Related models
More from manancode
More models
No task type declared.