Views
No views yet
softcatala/translate-eus-cat, translating
Basque (eu) to Catalan (ca).PegasusForConditionalGeneration
checkpoint and an ONNX export that were reconstructed from that binary.
Nothing was retrained. The weights are the original weights.mit, the same as
the source.| Path | What it is |
|---|---|
model.safetensors, config.json | PyTorch PegasusForConditionalGeneration |
encoder_model.onnx, decoder_model.onnx, decoder_with_past_model.onnx | ONNX, float32 |
int8/ | the same three graphs, dynamic int8 |
tokenizer.json | fast Unigram tokenizer over the original sentencepiece model |
ct2_reader.py, ct2_to_pegasus.py, spm_tokenizer.py | the converter |
1from transformers import AutoTokenizer
2from optimum.onnxruntime import ORTModelForSeq2SeqLM
3
4tok = AutoTokenizer.from_pretrained("TigreGotico/translate-eus-cat-onnx")
5model = ORTModelForSeq2SeqLM.from_pretrained("TigreGotico/translate-eus-cat-onnx", use_cache=True, use_merged=False)
6
7ids = tok('Katua sofan lo dago.', return_tensors="pt")
8out = model.generate(**ids, num_beams=4, max_new_tokens=256)
9print(tok.decode(out[0], skip_special_tokens=True))
10# El gat dorm al sofà.subfolder="int8".with_source_eos = 0, so the encoder never saw </s> during training.
MarianTokenizer, PegasusTokenizer and T5Tokenizer all append </s>,
which puts the model off its training distribution. The tokenizer shipped here
appends nothing.shared_vocabulary order, which is not the
sentencepiece order: CT2 puts <blank> (the pad token) at id 0 and moves
<unk> to the end of the table.<s>, not from </s>.ctranslate2.Translator running the source model.bin:| Comparison | greedy | beam 4 |
|---|---|---|
| reconstructed PyTorch | 100% | 93% |
| ONNX float32 | 100% | 93% |
| ONNX int8 | 100% | 87% |
model.bin is a flat self-describing binary: binary_version,
the spec name and revision, then one record per variable (name, rank,
dimensions, dtype code, byte count, raw bytes), then a table of aliases for tied
weights. ct2_reader.py reads it and dequantizes int8 variables with their
*_scale companion. ct2_to_pegasus.py recovers the architecture from the spec
scalars and maps every variable onto a HuggingFace parameter.1{
2 "encoder_layers": 6,
3 "decoder_layers": 6,
4 "vocab_size": 50001,
5 "d_model": 512,
6 "heads": 8,
7 "ffn_dim": 2048,
8 "pre_norm": true,
9 "activation": "relu",
10 "layernorm_embedding": false,
11 "relative_position": false,
12 "scale_embeddings": true,
13 "output_bias": true,
14 "stored_positions": false,
15 "source_bos": false,
16 "source_eos": false,
17 "target_bos": true,
18 "decoder_start_token": "<s>",
19 "ct2_spec": "TransformerSpec rev 7, binary_version 6"
20}layernorm_embedding. That rules out BART, mBART and PLBart, whose
layernorm_embedding cannot be neutralised — a LayerNorm with weight 1 and
bias 0 still normalises. It also rules out Marian, which is post-norm.decoder/projection/bias). Neither Marian nor M2M100 has
one. Pegasus does, as final_logits_bias.model.bin. CTranslate2
builds it with the OpenNMT-tf formula, spacing log(10000)/(dim/2 - 1) and
layout [sin all | cos all]. Pegasus rebuilds it on load with
10000^(2i/dim), which is a different table. The converter writes the CT2
table into embed_positions.weight, clears _keys_to_ignore_on_save so it is
actually persisted, and reloads the checkpoint to assert the table survived.
Skipping this produces a model that runs and translates plausibly but wrongly.linear_0 of shape
(3d, d) in that order. Cross-attention splits differently: linear_0 is Q
alone, linear_1 is [K; V] fused, linear_2 is the output projection.(out, in), the layout torch.nn.Linear uses, so nothing
is transposed. gamma and beta are the layer-norm weight and bias.MatMul with /lm_head/MatMul excluded.
Quantizing every operator destroys a 512-dimension NMT decoder.mit.
Source repository: softcatala/translate-eus-cat.
This repository only changes the file format.