Views
No views yet
projecte-aina/aina-translator-gl-ca.M2M100ForConditionalGeneration checkpoint and an ONNX export that
were reconstructed from that binary. No retraining took place. The weights
are the original weights.apache-2.0, the same as
the source.| Files | What it is |
|---|---|
model.safetensors, config.json | PyTorch M2M100ForConditionalGeneration |
encoder_model.onnx, decoder_model.onnx, decoder_with_past_model.onnx | ONNX, float32 |
int8/ | the same three graphs, dynamic int8 |
source.spm, target.spm, vocab.json | MarianTokenizer over the original shared sentencepiece model |
1from transformers import AutoTokenizer
2from optimum.onnxruntime import ORTModelForSeq2SeqLM
3
4tok = AutoTokenizer.from_pretrained("TigreGotico/aina-translator-gl-ca-onnx")
5model = ORTModelForSeq2SeqLM.from_pretrained("TigreGotico/aina-translator-gl-ca-onnx", use_cache=True, use_merged=False)
6
7ids = tok("O goberno aprobou unha nova lei sobre o cambio climático.", return_tensors="pt")
8out = model.generate(**ids, num_beams=4, max_new_tokens=256)
9print(tok.decode(out[0], skip_special_tokens=True))subfolder="int8".MatMul with /lm_head/MatMul excluded.
Quantizing every operator destroys a 512-dimension NMT decoder.model.bin is a flat, self-describing binary: a version header, a
spec name and revision, then one record per variable (name, rank, dimensions,
dtype code, byte count, raw data), then a table of aliases for tied weights. The
converter reads that file, recovers the architecture from the spec scalars, and
maps every variable onto a HuggingFace parameter name.{
"encoder_layers": 24,
"decoder_layers": 6,
"vocab_size": 55328,
"d_model": 1024,
"heads": 16,
"ffn_dim": 4096,
"pre_norm": true,
"activation": "relu",
"layernorm_embedding": false,
"relative_position": false,
"scale_embeddings": 32.0,
"max_positions": 1024,
"source_eos": true,
"source_bos": false,
"target_bos": false,
"tied_embeddings": true,
"decoder_start_token": "</s>"
}M2M100ForConditionalGeneration,
so it is the target architecture. Marian's HuggingFace class does not fit,
because it is post-norm and uses learned positions.linear_0 of shape
(3*d, d), in that order. Cross-attention is split differently: linear_0 is
Q alone, linear_1 is [K; V] fused, linear_2 is the output projection.(out, in), the same layout torch.nn.Linear uses, so no
transpose is needed.gamma and beta are the layer-norm weight and bias.decoder/projection/weight and encoder/embeddings_0/weight aliases mean
the embedding matrix is shared three ways; lm_head is tied.</s>, not <s>. Starting from <s> degrades the
first-token log probability by about 2 nats.| Comparison | greedy | beam 4 |
|---|---|---|
| reconstructed PyTorch vs CTranslate2 | 100% | 100% |
| ONNX float32 vs CTranslate2 | 100% | 100% |
| ONNX int8 vs CTranslate2 | 100% | 100% |
ct2_to_hf.py and ct2_reader.py in this repository do the whole conversion:python ct2_to_hf.py <ct2_model_dir> <output_hf_dir>