Isa0 commited on
Commit
5097547
·
1 Parent(s): 4aaffa6

Add onnxscript dependency and set dynamo=False for classic ONNX export

Browse files
Files changed (4) hide show
  1. pyproject.toml +1 -0
  2. requirements.txt +32 -4
  3. train.py +18 -9
  4. uv.lock +45 -0
pyproject.toml CHANGED
@@ -12,4 +12,5 @@ dependencies = [
12
  "numpy>=1.24.0",
13
  "onnx>=1.14.0",
14
  "onnxruntime>=1.15.0",
 
15
  ]
 
12
  "numpy>=1.24.0",
13
  "onnx>=1.14.0",
14
  "onnxruntime>=1.15.0",
15
+ "onnxscript>=0.1.0",
16
  ]
requirements.txt CHANGED
@@ -86,9 +86,15 @@ markupsafe==3.0.3
86
  mdurl==0.1.2 ; python_full_version >= '3.10'
87
  # via markdown-it-py
88
  ml-dtypes==0.5.4 ; python_full_version < '3.10'
89
- # via onnx
 
 
 
90
  ml-dtypes==0.6.0 ; python_full_version >= '3.10'
91
- # via onnx
 
 
 
92
  mpmath==1.3.0
93
  # via sympy
94
  narwhals==2.25.0 ; python_full_version >= '3.11'
@@ -104,7 +110,9 @@ numpy==2.0.2 ; python_full_version < '3.10'
104
  # hatespeech
105
  # ml-dtypes
106
  # onnx
 
107
  # onnxruntime
 
108
  # pandas
109
  # scikit-learn
110
  # scipy
@@ -114,7 +122,9 @@ numpy==2.2.6 ; python_full_version == '3.10.*'
114
  # hatespeech
115
  # ml-dtypes
116
  # onnx
 
117
  # onnxruntime
 
118
  # pandas
119
  # scikit-learn
120
  # scipy
@@ -124,7 +134,9 @@ numpy==2.4.6 ; python_full_version == '3.11.*'
124
  # hatespeech
125
  # ml-dtypes
126
  # onnx
 
127
  # onnxruntime
 
128
  # pandas
129
  # scikit-learn
130
  # scipy
@@ -134,7 +146,9 @@ numpy==2.5.2 ; python_full_version >= '3.12'
134
  # hatespeech
135
  # ml-dtypes
136
  # onnx
 
137
  # onnxruntime
 
138
  # pandas
139
  # scikit-learn
140
  # scipy
@@ -218,19 +232,30 @@ nvidia-nvtx==13.0.85 ; (python_full_version >= '3.10' and platform_machine == 'a
218
  nvidia-nvtx-cu12==12.8.90 ; python_full_version < '3.10' and platform_machine == 'x86_64' and sys_platform == 'linux'
219
  # via torch
220
  onnx==1.19.1 ; python_full_version < '3.10'
221
- # via hatespeech
 
 
 
222
  onnx==1.22.0 ; python_full_version >= '3.10'
223
- # via hatespeech
 
 
 
 
 
224
  onnxruntime==1.20.1 ; python_full_version < '3.10'
225
  # via hatespeech
226
  onnxruntime==1.24.3 ; python_full_version == '3.10.*'
227
  # via hatespeech
228
  onnxruntime==1.29.0 ; python_full_version >= '3.11'
229
  # via hatespeech
 
 
230
  packaging==26.3
231
  # via
232
  # huggingface-hub
233
  # onnxruntime
 
234
  # transformers
235
  pandas==2.3.3 ; python_full_version < '3.11'
236
  # via hatespeech
@@ -294,6 +319,7 @@ six==1.17.0
294
  # via python-dateutil
295
  sympy==1.14.0
296
  # via
 
297
  # onnxruntime
298
  # torch
299
  threadpoolctl==3.6.0
@@ -326,6 +352,8 @@ typing-extensions==4.16.0
326
  # exceptiongroup
327
  # huggingface-hub
328
  # onnx
 
 
329
  # torch
330
  tzdata==2026.3 ; python_full_version < '3.11' or sys_platform == 'emscripten' or sys_platform == 'win32'
331
  # via pandas
 
86
  mdurl==0.1.2 ; python_full_version >= '3.10'
87
  # via markdown-it-py
88
  ml-dtypes==0.5.4 ; python_full_version < '3.10'
89
+ # via
90
+ # onnx
91
+ # onnx-ir
92
+ # onnxscript
93
  ml-dtypes==0.6.0 ; python_full_version >= '3.10'
94
+ # via
95
+ # onnx
96
+ # onnx-ir
97
+ # onnxscript
98
  mpmath==1.3.0
99
  # via sympy
100
  narwhals==2.25.0 ; python_full_version >= '3.11'
 
110
  # hatespeech
111
  # ml-dtypes
112
  # onnx
113
+ # onnx-ir
114
  # onnxruntime
115
+ # onnxscript
116
  # pandas
117
  # scikit-learn
118
  # scipy
 
122
  # hatespeech
123
  # ml-dtypes
124
  # onnx
125
+ # onnx-ir
126
  # onnxruntime
127
+ # onnxscript
128
  # pandas
129
  # scikit-learn
130
  # scipy
 
134
  # hatespeech
135
  # ml-dtypes
136
  # onnx
137
+ # onnx-ir
138
  # onnxruntime
139
+ # onnxscript
140
  # pandas
141
  # scikit-learn
142
  # scipy
 
146
  # hatespeech
147
  # ml-dtypes
148
  # onnx
149
+ # onnx-ir
150
  # onnxruntime
151
+ # onnxscript
152
  # pandas
153
  # scikit-learn
154
  # scipy
 
232
  nvidia-nvtx-cu12==12.8.90 ; python_full_version < '3.10' and platform_machine == 'x86_64' and sys_platform == 'linux'
233
  # via torch
234
  onnx==1.19.1 ; python_full_version < '3.10'
235
+ # via
236
+ # hatespeech
237
+ # onnx-ir
238
+ # onnxscript
239
  onnx==1.22.0 ; python_full_version >= '3.10'
240
+ # via
241
+ # hatespeech
242
+ # onnx-ir
243
+ # onnxscript
244
+ onnx-ir==1.0.0
245
+ # via onnxscript
246
  onnxruntime==1.20.1 ; python_full_version < '3.10'
247
  # via hatespeech
248
  onnxruntime==1.24.3 ; python_full_version == '3.10.*'
249
  # via hatespeech
250
  onnxruntime==1.29.0 ; python_full_version >= '3.11'
251
  # via hatespeech
252
+ onnxscript==0.7.1
253
+ # via hatespeech
254
  packaging==26.3
255
  # via
256
  # huggingface-hub
257
  # onnxruntime
258
+ # onnxscript
259
  # transformers
260
  pandas==2.3.3 ; python_full_version < '3.11'
261
  # via hatespeech
 
319
  # via python-dateutil
320
  sympy==1.14.0
321
  # via
322
+ # onnx-ir
323
  # onnxruntime
324
  # torch
325
  threadpoolctl==3.6.0
 
352
  # exceptiongroup
353
  # huggingface-hub
354
  # onnx
355
+ # onnx-ir
356
+ # onnxscript
357
  # torch
358
  tzdata==2026.3 ; python_full_version < '3.11' or sys_platform == 'emscripten' or sys_platform == 'win32'
359
  # via pandas
train.py CHANGED
@@ -265,19 +265,28 @@ def export_to_onnx(
265
  dummy_encodings["attention_mask"],
266
  )
267
 
268
- torch.onnx.export(
269
- model,
270
- dummy_inputs,
271
- raw_onnx_path,
272
- input_names=["input_ids", "attention_mask"],
273
- output_names=["logits"],
274
- dynamic_axes={
275
  "input_ids": {0: "batch_size", 1: "sequence_length"},
276
  "attention_mask": {0: "batch_size", 1: "sequence_length"},
277
  "logits": {0: "batch_size"},
278
  },
279
- opset_version=14,
280
- do_constant_folding=True,
 
 
 
 
 
 
 
 
 
 
 
 
281
  )
282
 
283
  # Verify raw ONNX model validity
 
265
  dummy_encodings["attention_mask"],
266
  )
267
 
268
+ export_kwargs = {
269
+ "input_names": ["input_ids", "attention_mask"],
270
+ "output_names": ["logits"],
271
+ "dynamic_axes": {
 
 
 
272
  "input_ids": {0: "batch_size", 1: "sequence_length"},
273
  "attention_mask": {0: "batch_size", 1: "sequence_length"},
274
  "logits": {0: "batch_size"},
275
  },
276
+ "opset_version": 14,
277
+ "do_constant_folding": True,
278
+ }
279
+
280
+ import inspect
281
+ sig = inspect.signature(torch.onnx.export)
282
+ if "dynamo" in sig.parameters:
283
+ export_kwargs["dynamo"] = False
284
+
285
+ torch.onnx.export(
286
+ model,
287
+ dummy_inputs,
288
+ raw_onnx_path,
289
+ **export_kwargs,
290
  )
291
 
292
  # Verify raw ONNX model validity
uv.lock CHANGED
@@ -462,6 +462,7 @@ dependencies = [
462
  { name = "onnxruntime", version = "1.20.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
463
  { name = "onnxruntime", version = "1.24.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.10.*'" },
464
  { name = "onnxruntime", version = "1.29.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
 
465
  { name = "pandas", version = "2.3.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" },
466
  { name = "pandas", version = "3.0.5", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
467
  { name = "scikit-learn", version = "1.6.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
@@ -478,6 +479,7 @@ requires-dist = [
478
  { name = "numpy", specifier = ">=1.24.0" },
479
  { name = "onnx", specifier = ">=1.14.0" },
480
  { name = "onnxruntime", specifier = ">=1.15.0" },
 
481
  { name = "pandas", specifier = ">=2.0.0" },
482
  { name = "scikit-learn", specifier = ">=1.2.0" },
483
  { name = "torch", specifier = ">=2.0.0" },
@@ -1648,6 +1650,27 @@ wheels = [
1648
  { url = "https://files.pythonhosted.org/packages/00/50/257a880384a1dd502d543b0067945074d63cd17d0840e958355bc8197da8/onnx-1.22.0-cp314-cp314t-win_arm64.whl", hash = "sha256:8e268cdc0547e3949799ffd4a44451dc2b9080b57d0824a2db680b6ec65506f0", size = 17231391, upload-time = "2026-06-15T12:50:03.047Z" },
1649
  ]
1650
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1651
  [[package]]
1652
  name = "onnxruntime"
1653
  version = "1.20.1"
@@ -1780,6 +1803,28 @@ wheels = [
1780
  { url = "https://files.pythonhosted.org/packages/60/21/d0c04b561b46e9bff89b5f500fb7415b8ca0669f7902204f76ab06bb0c7e/onnxruntime-1.29.0-cp314-cp314t-manylinux_2_28_x86_64.whl", hash = "sha256:1ea91cef3b971506e51ae9c37c16d027774ec64994a524ec1bdfb027d68a9832", size = 23138547, upload-time = "2026-08-17T22:54:37.491Z" },
1781
  ]
1782
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1783
  [[package]]
1784
  name = "packaging"
1785
  version = "26.3"
 
462
  { name = "onnxruntime", version = "1.20.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
463
  { name = "onnxruntime", version = "1.24.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.10.*'" },
464
  { name = "onnxruntime", version = "1.29.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
465
+ { name = "onnxscript" },
466
  { name = "pandas", version = "2.3.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" },
467
  { name = "pandas", version = "3.0.5", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
468
  { name = "scikit-learn", version = "1.6.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
 
479
  { name = "numpy", specifier = ">=1.24.0" },
480
  { name = "onnx", specifier = ">=1.14.0" },
481
  { name = "onnxruntime", specifier = ">=1.15.0" },
482
+ { name = "onnxscript", specifier = ">=0.1.0" },
483
  { name = "pandas", specifier = ">=2.0.0" },
484
  { name = "scikit-learn", specifier = ">=1.2.0" },
485
  { name = "torch", specifier = ">=2.0.0" },
 
1650
  { url = "https://files.pythonhosted.org/packages/00/50/257a880384a1dd502d543b0067945074d63cd17d0840e958355bc8197da8/onnx-1.22.0-cp314-cp314t-win_arm64.whl", hash = "sha256:8e268cdc0547e3949799ffd4a44451dc2b9080b57d0824a2db680b6ec65506f0", size = 17231391, upload-time = "2026-06-15T12:50:03.047Z" },
1651
  ]
1652
 
1653
+ [[package]]
1654
+ name = "onnx-ir"
1655
+ version = "1.0.0"
1656
+ source = { registry = "https://pypi.org/simple" }
1657
+ dependencies = [
1658
+ { name = "ml-dtypes", version = "0.5.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
1659
+ { name = "ml-dtypes", version = "0.6.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.10'" },
1660
+ { name = "numpy", version = "2.0.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
1661
+ { name = "numpy", version = "2.2.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.10.*'" },
1662
+ { name = "numpy", version = "2.4.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.11.*'" },
1663
+ { name = "numpy", version = "2.5.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.12'" },
1664
+ { name = "onnx", version = "1.19.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
1665
+ { name = "onnx", version = "1.22.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.10'" },
1666
+ { name = "sympy" },
1667
+ { name = "typing-extensions" },
1668
+ ]
1669
+ sdist = { url = "https://files.pythonhosted.org/packages/d6/c2/61194cec0dbc5622273c0ebd592d37cc1dca0d7f1a744f02edd45ac905a3/onnx_ir-1.0.0.tar.gz", hash = "sha256:9e261f25fde8da9612ae5cb43b3b374d5ff469c04af0363cad588b2bb000b812", size = 163121, upload-time = "2026-08-11T14:49:46.895Z" }
1670
+ wheels = [
1671
+ { url = "https://files.pythonhosted.org/packages/91/cd/6d1637172eb59c7b18ac90ed089d1f599a11fe0e63b4db2d017f3bb38a32/onnx_ir-1.0.0-py3-none-any.whl", hash = "sha256:e578f0d608d3062866b48223616eb2d10a6d6d01f8b8faac596129034f483cc7", size = 185849, upload-time = "2026-08-11T14:49:45.524Z" },
1672
+ ]
1673
+
1674
  [[package]]
1675
  name = "onnxruntime"
1676
  version = "1.20.1"
 
1803
  { url = "https://files.pythonhosted.org/packages/60/21/d0c04b561b46e9bff89b5f500fb7415b8ca0669f7902204f76ab06bb0c7e/onnxruntime-1.29.0-cp314-cp314t-manylinux_2_28_x86_64.whl", hash = "sha256:1ea91cef3b971506e51ae9c37c16d027774ec64994a524ec1bdfb027d68a9832", size = 23138547, upload-time = "2026-08-17T22:54:37.491Z" },
1804
  ]
1805
 
1806
+ [[package]]
1807
+ name = "onnxscript"
1808
+ version = "0.7.1"
1809
+ source = { registry = "https://pypi.org/simple" }
1810
+ dependencies = [
1811
+ { name = "ml-dtypes", version = "0.5.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
1812
+ { name = "ml-dtypes", version = "0.6.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.10'" },
1813
+ { name = "numpy", version = "2.0.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
1814
+ { name = "numpy", version = "2.2.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.10.*'" },
1815
+ { name = "numpy", version = "2.4.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.11.*'" },
1816
+ { name = "numpy", version = "2.5.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.12'" },
1817
+ { name = "onnx", version = "1.19.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
1818
+ { name = "onnx", version = "1.22.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.10'" },
1819
+ { name = "onnx-ir" },
1820
+ { name = "packaging" },
1821
+ { name = "typing-extensions" },
1822
+ ]
1823
+ sdist = { url = "https://files.pythonhosted.org/packages/c4/3a/4d79bce3f460e0df7fed54a92ce80827f25da66511da368bb00783ad8d20/onnxscript-0.7.1.tar.gz", hash = "sha256:309fb86484b11fa4ded90dba580e0d63f1a0827588e521cecaf2eeddb46d6e86", size = 618160, upload-time = "2026-06-29T23:33:21.526Z" }
1824
+ wheels = [
1825
+ { url = "https://files.pythonhosted.org/packages/dd/bd/a0c8e737b6afda10e42a597787d53d5b66e00268df6f59184701eeae37d9/onnxscript-0.7.1-py3-none-any.whl", hash = "sha256:544763b7fdef49940cdd9412ff5135cbae96d59ac6bc1921457f21280f40f4b7", size = 721970, upload-time = "2026-06-29T23:33:23.298Z" },
1826
+ ]
1827
+
1828
  [[package]]
1829
  name = "packaging"
1830
  version = "26.3"