|
| 1 | +import datetime |
1 | 2 | import inspect |
2 | 3 | import os |
3 | 4 | from typing import Any, Dict, List, Optional, Tuple, Union |
@@ -139,6 +140,55 @@ def _make_folder_name( |
139 | 140 | return "-".join(els) |
140 | 141 |
|
141 | 142 |
|
| 143 | +def version_summary() -> Dict[str, Union[int, float, str]]: |
| 144 | + """ |
| 145 | + Example: |
| 146 | +
|
| 147 | + .. runpython:: |
| 148 | + :showcode: |
| 149 | +
|
| 150 | + import pprint |
| 151 | + from onnx_diagnostic.torch_models.test_helper import version_summary |
| 152 | +
|
| 153 | + pprint.pprint(version_summary()) |
| 154 | + """ |
| 155 | + import numpy |
| 156 | + |
| 157 | + summary: Dict[str, Union[int, float, str]] = { |
| 158 | + "version_torch": torch.__version__, |
| 159 | + "version_numpy": numpy.__version__, |
| 160 | + } |
| 161 | + try: |
| 162 | + import transformers |
| 163 | + |
| 164 | + summary["version_transformers"] = transformers.__version__ |
| 165 | + except ImportError: |
| 166 | + pass |
| 167 | + try: |
| 168 | + import onnx |
| 169 | + |
| 170 | + summary["version_onnx"] = onnx.__version__ |
| 171 | + except ImportError: |
| 172 | + pass |
| 173 | + try: |
| 174 | + import onnxscript |
| 175 | + |
| 176 | + summary["version_onnxscript"] = onnxscript.__version__ |
| 177 | + except ImportError: |
| 178 | + pass |
| 179 | + try: |
| 180 | + import onnxruntime |
| 181 | + |
| 182 | + summary["version_onnxruntime"] = onnxruntime.__version__ |
| 183 | + except ImportError: |
| 184 | + pass |
| 185 | + import onnx_diagnostic |
| 186 | + |
| 187 | + summary["version_onnx_diagnostic"] = onnx_diagnostic.__version__ |
| 188 | + summary["version_date"] = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S") |
| 189 | + return summary |
| 190 | + |
| 191 | + |
142 | 192 | def validate_model( |
143 | 193 | model_id: str, |
144 | 194 | task: Optional[str] = None, |
@@ -180,7 +230,7 @@ def validate_model( |
180 | 230 | another one with whatever the function produces |
181 | 231 | """ |
182 | 232 | assert not trained, f"trained={trained} not supported yet" |
183 | | - summary: Dict[str, Union[int, float, str]] = {} |
| 233 | + summary = version_summary() |
184 | 234 | if dump_folder: |
185 | 235 | folder_name = _make_folder_name( |
186 | 236 | model_id, exporter, optimization, dtype=dtype, device=device |
|
0 commit comments