Upload README.md with huggingface_hub
Browse files
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.
|