Simplify model card and document export and optimization setup
Browse files- README.md +19 -143
- SHA256SUMS +1 -1
README.md
CHANGED
|
@@ -23,153 +23,29 @@ an ONNX conversion, not a new upstream LightOn checkpoint.
|
|
| 23 |
Base checkpoint: [`370c600`](https://huggingface.co/lightonai/SlideOn/tree/370c600e9886afc43ff8026695261e56ecfaa011).
|
| 24 |
The original Apache-2.0 license is included in `LICENSE`.
|
| 25 |
|
| 26 |
-
##
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
| `slideon-optimized.onnx` | Single graph supporting query and document encoding |
|
| 31 |
-
| `tokenizer.json` | Matching HF tokenizer, used directly by the Rust `tokenizers` library or DJL |
|
| 32 |
-
| `tokenizer_config.json` | Unmodified upstream tokenizer settings |
|
| 33 |
-
| `config.json` | Unmodified upstream model configuration, including prompts and inference limits |
|
| 34 |
-
| `export_metadata.json` | Checkpoint, model hashes, optimization settings and validation scope |
|
| 35 |
-
| `SHA256SUMS` | Integrity hashes for the repository files |
|
| 36 |
-
|
| 37 |
-
Only the optimized model is distributed here; the source export's SHA256 is recorded
|
| 38 |
-
in `export_metadata.json`. The ONNX file is self-contained and has no external
|
| 39 |
-
weight files.
|
| 40 |
-
|
| 41 |
-
This is **not** an `AutoModel.from_pretrained()` or SentenceTransformers package.
|
| 42 |
-
`config.json` retains the upstream `auto_map` declarations for provenance, but
|
| 43 |
-
upstream Python model code and PyTorch weights are not bundled. Load the ONNX file
|
| 44 |
-
with ONNX Runtime; no `trust_remote_code` execution is needed for the example below.
|
| 45 |
-
|
| 46 |
-
## Graph interface
|
| 47 |
-
|
| 48 |
-
Batch size is fixed at **1**; sequence length is dynamic.
|
| 49 |
-
|
| 50 |
-
| Input | Type | Shape |
|
| 51 |
-
|---|---|---|
|
| 52 |
-
| `input_ids` | INT64 | `[1, sequence]` |
|
| 53 |
-
| `attention_mask` | INT64 | `[1, sequence]` |
|
| 54 |
-
| `is_document` | BOOL | `[]` (scalar) |
|
| 55 |
-
|
| 56 |
-
Set `is_document=False` for queries and `True` for documents. Both tasks use the
|
| 57 |
-
same graph. Do not pass `token_type_ids`.
|
| 58 |
-
|
| 59 |
-
| Output | Type | Shape |
|
| 60 |
-
|---|---|---|
|
| 61 |
-
| `output_idx` | INT64 | `[nonzero_features]` |
|
| 62 |
-
| `output_weights` | FLOAT32 | `[nonzero_features]` |
|
| 63 |
-
|
| 64 |
-
Indices are **latent feature IDs in [0, 32768)**, not tokenizer vocabulary IDs.
|
| 65 |
-
Weights are floating point; the graph does **not** apply a scale-100 integer
|
| 66 |
-
conversion. The exported checkpoint has no final query/document feature cap.
|
| 67 |
-
There is no runtime `max_active_dims` input.
|
| 68 |
-
|
| 69 |
-
## Python usage
|
| 70 |
-
|
| 71 |
-
From a local checkout/download of this repository:
|
| 72 |
-
|
| 73 |
-
```bash
|
| 74 |
-
pip install 'numpy<2' 'onnxruntime==1.17.0' 'tokenizers==0.21.4'
|
| 75 |
-
```
|
| 76 |
-
|
| 77 |
-
```python
|
| 78 |
-
import json
|
| 79 |
-
from pathlib import Path
|
| 80 |
|
| 81 |
-
|
| 82 |
-
import onnxruntime as ort
|
| 83 |
-
from tokenizers import Tokenizer
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
tokenizer = Tokenizer.from_file(str(root / 'tokenizer.json'))
|
| 92 |
-
tokenizer.no_padding()
|
| 93 |
-
tokenizer.enable_truncation(max_length=config['inference'][task + '_length'])
|
| 94 |
-
encoding = tokenizer.encode(
|
| 95 |
-
(config['inference']['prompts'][task] + text).strip(),
|
| 96 |
-
add_special_tokens=True,
|
| 97 |
-
)
|
| 98 |
-
|
| 99 |
-
options = ort.SessionOptions()
|
| 100 |
-
options.intra_op_num_threads = 1
|
| 101 |
-
options.inter_op_num_threads = 1
|
| 102 |
-
session = ort.InferenceSession(
|
| 103 |
-
str(root / 'slideon-optimized.onnx'),
|
| 104 |
-
sess_options=options,
|
| 105 |
-
providers=['CPUExecutionProvider'],
|
| 106 |
-
)
|
| 107 |
-
indices, weights = session.run(
|
| 108 |
-
['output_idx', 'output_weights'],
|
| 109 |
-
{
|
| 110 |
-
'input_ids': np.asarray([encoding.ids], dtype=np.int64),
|
| 111 |
-
'attention_mask': np.asarray([encoding.attention_mask], dtype=np.int64),
|
| 112 |
-
'is_document': np.asarray(task == 'document', dtype=np.bool_),
|
| 113 |
-
},
|
| 114 |
-
)
|
| 115 |
-
sparse_vector = {str(int(i)): float(w) for i, w in zip(indices, weights)}
|
| 116 |
-
```
|
| 117 |
-
|
| 118 |
-
The pinned checkpoint uses `query: ` / `document: ` prompts and has empty special-token
|
| 119 |
-
insertion prefixes. Its query/document token limits are 8192. The tokenizer config's
|
| 120 |
-
`model_max_length` is 512; the example explicitly uses the model's task-specific
|
| 121 |
-
inference limit instead. Longer inputs can require substantial CPU time and memory;
|
| 122 |
-
not every length through 8192 has been validated for this optimized artifact.
|
| 123 |
-
|
| 124 |
-
### Optional retrieval conversion
|
| 125 |
-
|
| 126 |
-
For the published Anserini converter-style q64/d512 workflow, select top-64 query
|
| 127 |
-
or top-512 document features by **floating-point weight before integer conversion**,
|
| 128 |
-
then use float32 `np.rint(weight * 100)` and discard zero integer weights. Apply the
|
| 129 |
-
same representation convention on both sides. Do not sort/select features only
|
| 130 |
-
after integer conversion.
|
| 131 |
-
|
| 132 |
-
For floating-point retrieval, omit multiplication/rounding and use floating-point
|
| 133 |
-
dot products with floating-point document vectors. Equal-weight top-k tie ordering
|
| 134 |
-
must be defined explicitly. Post-output pruning is not guaranteed to select the
|
| 135 |
-
same features as the native model's pre-final-FP16 `max_active_dims` operation.
|
| 136 |
-
|
| 137 |
-
## Optimization and validation
|
| 138 |
-
|
| 139 |
-
The graph was exported in FP32 with native model FP16 roundtrips preserved, then
|
| 140 |
-
serialized using **ONNX Runtime 1.17.0 CPU `ORT_ENABLE_EXTENDED`** graph optimization.
|
| 141 |
-
The graph node count decreased from **3115 to 1475**. No additional FP16/INT8
|
| 142 |
-
conversion or change to pruning settings was requested. This is generic ORT graph
|
| 143 |
-
optimization, not a BERT-specific transformer optimizer pass. The artifact may
|
| 144 |
-
contain ORT-specific fused operators; use ONNX Runtime rather than assuming every
|
| 145 |
-
ONNX backend can execute it.
|
| 146 |
-
|
| 147 |
-
Validation for this exact optimized artifact includes:
|
| 148 |
-
|
| 149 |
-
- ONNX checker validation.
|
| 150 |
-
- Reloading with CPU ONNX Runtime 1.17.0.
|
| 151 |
-
- Input/output interface and custom-metadata consistency checks.
|
| 152 |
-
- One short query and one short document compared against the source graph executed
|
| 153 |
-
with EXTENDED optimization: identical sparse IDs and weights in both cases.
|
| 154 |
-
|
| 155 |
-
Known numerical differences exist relative to PyTorch and across ORT versions.
|
| 156 |
-
Small backbone differences can cross native FP16 rounding boundaries and affect
|
| 157 |
-
top-k selection/max pooling. Graph optimization is intended to preserve semantics,
|
| 158 |
-
but bitwise equivalence for all inputs is not guaranteed. Do not treat retrieval
|
| 159 |
-
metric agreement as proof of raw numerical parity.
|
| 160 |
|
| 161 |
-
|
|
|
|
|
|
|
| 162 |
|
| 163 |
-
|
| 164 |
-
and config paths:
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
-Danserini.slideon.config=/absolute/path/config.json
|
| 170 |
-
```
|
| 171 |
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
The graph itself does not implement query-impact integer conversion or arbitrary
|
| 175 |
-
runtime feature budgets; those are retrieval-layer concerns.
|
|
|
|
| 23 |
Base checkpoint: [`370c600`](https://huggingface.co/lightonai/SlideOn/tree/370c600e9886afc43ff8026695261e56ecfaa011).
|
| 24 |
The original Apache-2.0 license is included in `LICENSE`.
|
| 25 |
|
| 26 |
+
## Setup
|
| 27 |
|
| 28 |
+
The model was exported and optimized on **Linux x86_64** (kernel 6.8.0), using
|
| 29 |
+
**Python 3.12.3** and **CPU execution** (no CUDA).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
### ONNX export
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
| Package | Version |
|
| 34 |
+
|---|---|
|
| 35 |
+
| PyTorch | `2.14.1+cpu` |
|
| 36 |
+
| Transformers | `5.21.0` |
|
| 37 |
+
| ONNX | `1.23.2` |
|
| 38 |
+
| ONNX Runtime (validation) | `1.31.1` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
The export uses `torch.onnx.export` with **opset 18**, `dynamo=False`, eager
|
| 41 |
+
attention, and FP32 model parameters. SlideOn's native FP16 roundtrips are
|
| 42 |
+
preserved. Batch size is fixed at 1; sequence length is dynamic.
|
| 43 |
|
| 44 |
+
### Graph optimization
|
|
|
|
| 45 |
|
| 46 |
+
Optimization was performed in a separate environment using **ONNX Runtime
|
| 47 |
+
1.17.0**, **NumPy 1.26.4**, and `CPUExecutionProvider`, matching the runtime version
|
| 48 |
+
used by the Anserini integration.
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
The exported graph was optimized with `ORT_ENABLE_EXTENDED` and saved as
|
| 51 |
+
`slideon-optimized.onnx`. No additional FP16 or INT8 conversion was applied.
|
|
|
|
|
|
SHA256SUMS
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
ae01838807d3e6d44f0fe7730d68b1b98acddb3b5dd3df640dc4ae7918629aae .gitattributes
|
| 2 |
c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4 LICENSE
|
| 3 |
-
|
| 4 |
7cf8e767fabe8e1d6add12ea061835da90095293b4880faae97c4891a6feab3d config.json
|
| 5 |
40265c7125dbdb1ec69d5a1ed3464dd9784abf9fbd89d3bb60f6299c917dc0a0 export_metadata.json
|
| 6 |
b7fcc1ed93f486c5dcd0c5974a1219e424fda3cd3e4e72760c0317e81c3e99c9 slideon-optimized.onnx
|
|
|
|
| 1 |
ae01838807d3e6d44f0fe7730d68b1b98acddb3b5dd3df640dc4ae7918629aae .gitattributes
|
| 2 |
c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4 LICENSE
|
| 3 |
+
2e469a7f9919457c6cbe120cb0e5b4146ef588707df404e752f13ac9cdb17c61 README.md
|
| 4 |
7cf8e767fabe8e1d6add12ea061835da90095293b4880faae97c4891a6feab3d config.json
|
| 5 |
40265c7125dbdb1ec69d5a1ed3464dd9784abf9fbd89d3bb60f6299c917dc0a0 export_metadata.json
|
| 6 |
b7fcc1ed93f486c5dcd0c5974a1219e424fda3cd3e4e72760c0317e81c3e99c9 slideon-optimized.onnx
|