FredrikKarlssonSpeech commited on
Commit
e85dc50
·
verified ·
1 Parent(s): 67b17e1

Upload CONVERSION_REPORT.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. CONVERSION_REPORT.md +90 -0
CONVERSION_REPORT.md ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ONNX Conversion Report
2
+
3
+ ## Model
4
+
5
+ - Source: `KBLab/megatron-bert-base-swedish-cased-600k`
6
+ - Architecture: `MegatronBertForMaskedLM` / `MegatronBertModel`
7
+ - Language: Swedish
8
+ - Parameters: about 110M
9
+
10
+ ## Environment
11
+
12
+ - `conda` env: `onnxconv`
13
+ - `optimum`: `2.1.0`
14
+ - `onnxruntime`: `1.24.4`
15
+ - `transformers`: `4.57.6`
16
+ - `onnx`: `1.21.0`
17
+
18
+ ## Constraint
19
+
20
+ `optimum.exporters.tasks.TasksManager` in this environment does not support `megatron-bert` ONNX export. Conversion used direct `torch.onnx.export` wrappers instead of `optimum-cli export onnx`.
21
+
22
+ The default `torch.export`/dynamo ONNX path produced a fill-mask graph that returned all-`NaN` logits in ORT. Final export uses legacy TorchScript ONNX exporter (`dynamo=False`).
23
+
24
+ ## Outputs
25
+
26
+ ### Fill-mask
27
+
28
+ - Inputs: `input_ids`, `attention_mask`, `token_type_ids`
29
+ - Output: `logits`
30
+ - Shape on validation sample: `[1, 10, 64128]`
31
+
32
+ ### Feature-extraction
33
+
34
+ - Inputs: `input_ids`, `attention_mask`, `token_type_ids`
35
+ - Outputs: `last_hidden_state`, `cls_embedding`
36
+ - Shapes on validation sample:
37
+ - `last_hidden_state`: `[1, 18, 768]`
38
+ - `cls_embedding`: `[1, 768]`
39
+
40
+ ## Validation
41
+
42
+ ### PyTorch vs FP32 ONNX
43
+
44
+ #### Fill-mask
45
+
46
+ - Max absolute logit diff: `0.0000688`
47
+ - Mean absolute diff: `0.00000869`
48
+ - Top-5 tokens at mask position matched exactly:
49
+ - `kung`
50
+ - `hertig`
51
+ - `fe`
52
+ - `bonde`
53
+ - `konung`
54
+
55
+ #### Feature-extraction
56
+
57
+ - `last_hidden_state` max diff: `0.00000593`
58
+ - `last_hidden_state` mean diff: `0.00000108`
59
+ - `cls_embedding` max diff: `0.00000295`
60
+ - `cls_embedding` cosine similarity: `1.0`
61
+
62
+ ### Quantized variants vs FP32 ONNX
63
+
64
+ #### Fill-mask
65
+
66
+ | Variant | Status | Notes |
67
+ |---|---|---|
68
+ | fp16 | Good | top-5 exact match, max diff `0.0131` |
69
+ | int8 | Drift | rank-3+ changed |
70
+ | uint8 | Drift | rank-3+ changed |
71
+ | q4 | Moderate drift | rank-3+ changed |
72
+
73
+ #### Feature-extraction
74
+
75
+ | Variant | CLS cosine | Mean abs diff | Notes |
76
+ |---|---:|---:|---|
77
+ | fp16 | `0.9999997` | `0.000222` | best compressed variant |
78
+ | int8 | `0.9731` | `0.05597` | notable drift |
79
+ | uint8 | `0.9717` | `0.05750` | notable drift |
80
+ | q4 | `0.7404` | `0.15967` | poor embedding fidelity on this model |
81
+
82
+ ## FP16 repair note
83
+
84
+ FP16 conversion initially failed in ORT due float32 `Cast` nodes feeding float16 arithmetic in monolithic graphs. Quantization now retargets those casts based on consumer arithmetic patterns before saving, and final fp16 variants load successfully.
85
+
86
+ ## Recommendation
87
+
88
+ - Default: `fp16`
89
+ - Feature extraction: prefer `fp16`; `int8`/`uint8` beat `q4` on this base model
90
+ - Fill-mask ranking-sensitive workloads can stay on `fp32` if absolute caution needed, but `fp16` matched top-5 exactly on validation sample