"""Reproduce ImageToolbox Vision packages with the pinned source weights.""" import argparse import json import subprocess import sys from pathlib import Path from huggingface_hub import snapshot_download SOURCES = { 'vision_lite': ('Qwen/Qwen3.5-0.8B', '2fc06364715b967f1860aea9cf38778875588b17'), 'vision_advanced': ('Qwen/Qwen3.5-2B', '15852e8c16360a2fea060d615a32b45270f8a8fc'), } root=Path(__file__).resolve().parent parser=argparse.ArgumentParser() parser.add_argument('variants',nargs='*',choices=list(SOURCES),default=list(SOURCES)) args=parser.parse_args() for variant in args.variants: repository,revision=SOURCES[variant] snapshot_download(repository,revision=revision,local_dir=root/'sources'/variant, allow_patterns=['*.json','*.safetensors','*.jinja','LICENSE']) subprocess.run([sys.executable,str(root/'prepare_export.py')],check=True) for variant in args.variants: subprocess.run([ sys.executable,'-m','onnxruntime_genai.models.builder', '-i',str(root/'sources'/variant),'-o',str(root/'packages/assistant/v1'/variant), '-p','int8','-e','cpu','-c',str(root/'export-cache'/variant), '--extra_options','filename=text.onnx','exclude_embeds=true','exclude_mtp=true', 'shared_embeddings=false','prune_lm_head=true','block_size=32','accuracy_level=4', ],check=True) for component in ('embedding','vision'): subprocess.run([sys.executable,'-c', 'from olive import run; run('+repr(str(root/'recipes'/variant/(component+'.json')))+')'], check=True,cwd=root) subprocess.run([sys.executable,str(root/'configure_package.py'),variant],check=True) subprocess.run([sys.executable,str(root/'trim_rope.py'),variant],check=True)