Download assistant/vision-export/v2/prepare_export.py from T8RIN/imagetoolbox-models: direct link, hf CLI and curl.
- Browser
- Download file 2.56 kB
-
https://huggingface.co/T8RIN/imagetoolbox-models/resolve/main/assistant/vision-export/v2/prepare_export.py
- Command line
-
hf download hf://T8RIN/imagetoolbox-models/assistant/vision-export/v2/prepare_export.py
-
curl -L -o prepare_export.py https://huggingface.co/T8RIN/imagetoolbox-models/resolve/main/assistant/vision-export/v2/prepare_export.py
2.56 kB
| import json | |
| from pathlib import Path | |
| root = Path(__file__).resolve().parent | |
| for variant in ('vision_max',): | |
| source = root / 'sources' / variant | |
| output = root / 'packages' / 'assistant' / 'v1' / variant | |
| folder = root / 'recipes' / variant | |
| folder.mkdir(parents=True, exist_ok=True) | |
| output.mkdir(parents=True, exist_ok=True) | |
| model = { | |
| 'type': 'PyTorchModel', | |
| 'model_path': str(source), | |
| 'model_script': str(root / 'user_script.py'), | |
| } | |
| common = { | |
| 'cast': { | |
| 'type': 'OnnxPeepholeOptimizer', 'onnxscript_optimize': False, | |
| 'onnxoptimizer_optimize': False, 'fuse_reshape_operations': False, | |
| 'fix_com_microsoft_opset': True, 'cast_chain_elimination': True, | |
| }, | |
| 'gemm': {'type': 'GraphSurgeries', 'surgeries': [{'surgeon': 'GemmToMatMulAdd'}]}, | |
| } | |
| vision = { | |
| 'input_model': dict(model, model_loader='get_vision_model', io_config='get_vision_io_config', dummy_inputs_func='get_vision_dummy_inputs'), | |
| 'passes': { | |
| 'convert': {'type': 'OnnxConversion', 'use_dynamo_exporter': True}, | |
| 'packed': {'type': 'GraphSurgeries', 'surgeries': [{'surgeon': 'PackedAttentionToLoopMHA'}, {'surgeon': 'RenameOutputDims', 'output_idx': 0, 'dim_idx': 0, 'dim_name': 'num_logical_patches'}]}, | |
| **common, | |
| 'quantize': {'type': 'OnnxBlockWiseRtnQuantization', 'bits': 8, 'block_size': 32, 'is_symmetric': True, 'accuracy_level': 1, 'save_as_external_data': True, 'external_data_name': 'vision.onnx.data'}, | |
| }, | |
| 'no_artifacts': True, | |
| 'cache_dir': str(root / 'olive-cache' / variant / 'vision'), | |
| 'output_dir': str(output / 'vision.onnx'), | |
| } | |
| embedding = { | |
| 'input_model': dict(model, model_loader='get_embedding_model', io_config='get_embedding_io_config', dummy_inputs_func='get_embedding_dummy_inputs'), | |
| 'passes': { | |
| 'convert': {'type': 'OnnxConversion', 'use_dynamo_exporter': False}, | |
| **common, | |
| 'quantize': {'type': 'OnnxBlockWiseRtnQuantization', 'bits': 4, 'block_size': 32, 'is_symmetric': True, 'accuracy_level': 1, 'axis': 1, 'save_as_external_data': True, 'external_data_name': 'embedding.onnx.data'}, | |
| }, | |
| 'no_artifacts': True, | |
| 'cache_dir': str(root / 'olive-cache' / variant / 'embedding'), | |
| 'output_dir': str(output / 'embedding.onnx'), | |
| } | |
| for name, data in [('vision', vision), ('embedding', embedding)]: | |
| (folder / f'{name}.json').write_text(json.dumps(data, indent=2)) | |