FredrikKarlssonSpeech commited on
Commit
67b17e1
Β·
verified Β·
1 Parent(s): 7e4dfbe

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +117 -0
README.md ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - sv
4
+ license: unknown
5
+ tags:
6
+ - onnx
7
+ - swedish
8
+ - bert
9
+ - fill-mask
10
+ - feature-extraction
11
+ - megatron-bert
12
+ library_name: onnxruntime
13
+ base_model: KBLab/megatron-bert-base-swedish-cased-600k
14
+ ---
15
+
16
+ # megatron-bert-base-swedish-cased-600k - ONNX
17
+
18
+ ONNX export of [`KBLab/megatron-bert-base-swedish-cased-600k`](https://huggingface.co/KBLab/megatron-bert-base-swedish-cased-600k).
19
+
20
+ This package contains two task-specific exports:
21
+
22
+ - `fill-mask/onnx/model.onnx` for masked language modeling logits
23
+ - `feature-extraction/onnx/model.onnx` for `last_hidden_state` and `cls_embedding`
24
+
25
+ ## Available variants
26
+
27
+ Each task folder contains:
28
+
29
+ - `model.onnx` - FP32 baseline
30
+ - `model_fp16.onnx` - FP16, recommended
31
+ - `model_int8.onnx` - dynamic INT8
32
+ - `model_uint8.onnx` - dynamic UINT8
33
+ - `model_q4.onnx` - 4-bit MatMul quantization
34
+
35
+ ## File sizes
36
+
37
+ ### Fill-mask
38
+
39
+ - `model.onnx`: 738.6 MB
40
+ - `model_fp16.onnx`: 369.4 MB
41
+ - `model_int8.onnx`: 185.6 MB
42
+ - `model_uint8.onnx`: 185.6 MB
43
+ - `model_q4.onnx`: 283.8 MB
44
+
45
+ ### Feature-extraction
46
+
47
+ - `model.onnx`: 539.0 MB
48
+ - `model_fp16.onnx`: 269.6 MB
49
+ - `model_int8.onnx`: 135.4 MB
50
+ - `model_uint8.onnx`: 135.4 MB
51
+ - `model_q4.onnx`: 252.4 MB
52
+
53
+ ## Accuracy summary
54
+
55
+ ### FP32 parity vs PyTorch
56
+
57
+ - Fill-mask max logit diff: `0.000069`
58
+ - Fill-mask top-5 tokens: exact match
59
+ - Feature `last_hidden_state` max diff: `0.000006`
60
+ - Feature `cls_embedding` cosine similarity: `1.0`
61
+
62
+ ### Quantized variants vs FP32 ONNX
63
+
64
+ #### Fill-mask
65
+
66
+ - `fp16`: top-5 exact match, max diff `0.0131`
67
+ - `int8`: top-5 drift after rank 2
68
+ - `uint8`: top-5 drift after rank 2
69
+ - `q4`: top-5 drift after rank 2
70
+
71
+ #### Feature-extraction
72
+
73
+ - `fp16`: CLS cosine `0.9999997`
74
+ - `q4`: CLS cosine `0.7404`
75
+ - `int8`: CLS cosine `0.9731`
76
+ - `uint8`: CLS cosine `0.9717`
77
+
78
+ ## Recommendation
79
+
80
+ - Use `model_fp16.onnx` by default.
81
+ - For feature extraction, prefer `fp16`; `int8`/`uint8` preserve embeddings better than `q4` on this model.
82
+ - Avoid `int8` and `uint8` for fill-mask if token ranking fidelity matters.
83
+
84
+ ## Layout
85
+
86
+ ```text
87
+ megatron-bert-base-swedish-cased-600k/
88
+ β”œβ”€β”€ fill-mask/
89
+ β”‚ β”œβ”€β”€ config.json
90
+ β”‚ β”œβ”€β”€ tokenizer.json
91
+ β”‚ β”œβ”€β”€ tokenizer_config.json
92
+ β”‚ β”œβ”€β”€ special_tokens_map.json
93
+ β”‚ └── onnx/
94
+ β”‚ β”œβ”€β”€ model.onnx
95
+ β”‚ β”œβ”€β”€ model_fp16.onnx
96
+ β”‚ β”œβ”€β”€ model_int8.onnx
97
+ β”‚ β”œβ”€β”€ model_uint8.onnx
98
+ β”‚ └── model_q4.onnx
99
+ └── feature-extraction/
100
+ β”œβ”€β”€ config.json
101
+ β”œβ”€β”€ tokenizer.json
102
+ β”œβ”€β”€ tokenizer_config.json
103
+ β”œβ”€β”€ special_tokens_map.json
104
+ └── onnx/
105
+ β”œβ”€β”€ model.onnx
106
+ β”œβ”€β”€ model_fp16.onnx
107
+ β”œβ”€β”€ model_int8.onnx
108
+ β”œβ”€β”€ model_uint8.onnx
109
+ └── model_q4.onnx
110
+ ```
111
+
112
+ ## Export notes
113
+
114
+ - Native `optimum 2.1.0` task export does not support `megatron-bert`.
115
+ - These graphs were exported with direct `torch.onnx.export` wrappers using legacy TorchScript exporter (`dynamo=False`).
116
+ - Feature extraction export uses `cls_embedding = last_hidden_state[:, 0, :]`.
117
+ - No pooler output included, because loading `MegatronBertModel` from this MLM checkpoint would introduce randomly initialized pooler weights.