getitune-exporting-a-model
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseExporting a model with getitune
使用getitune导出模型
After training, export a model to a deployable format with
(Python API) or (CLI). getitune exports to OpenVINO IR
(default) or ONNX, each at FP32 (default) or FP16 precision. Exported
artifacts load back for inference via the OpenVINO/ONNX path (see the
skill).
engine.export(...)getitune exportgetitune-running-inferenceRun everything from .
library/训练完成后,可通过(Python API)或(CLI)将模型导出为可部署格式。getitune支持导出为OpenVINO IR(默认格式)或ONNX格式,两种格式均可选择FP32(默认精度)或FP16精度。导出的产物可通过OpenVINO/ONNX路径加载回模型以进行推理(详见技能)。
engine.export(...)getitune exportgetitune-running-inference所有操作请在目录下执行。
library/Python API workflow
Python API 工作流
python
from getitune.engine import create_engine
from getitune.types import ExportFormat, Precision
engine = create_engine(
model="efficientnet_b0",
data="/path/to/dataset",
work_dir="./my_workspace",
)
engine.train(max_epochs=50)python
from getitune.engine import create_engine
from getitune.types import ExportFormat, Precision
engine = create_engine(
model="efficientnet_b0",
data="/path/to/dataset",
work_dir="./my_workspace",
)
engine.train(max_epochs=50)FP32 OpenVINO IR (default) -> returns the .xml path
FP32精度的OpenVINO IR(默认)-> 返回.xml文件路径
ov_ir_path = engine.export()
ov_ir_path = engine.export()
FP32 ONNX
FP32精度的ONNX
onnx_path = engine.export(export_format=ExportFormat.ONNX)
onnx_path = engine.export(export_format=ExportFormat.ONNX)
FP16 ONNX (same pattern works for OpenVINO IR)
FP16精度的ONNX(该模式同样适用于OpenVINO IR)
onnx_fp16 = engine.export(export_format=ExportFormat.ONNX, export_precision=Precision.FP16)
1. **Train or load a model** into the engine first (export operates on the
engine's current model).
- Done when: `engine.test()` produces sensible metrics before you export.
2. **Choose format and precision.** Default is FP32 OpenVINO IR. Use
`export_format=ExportFormat.ONNX` for ONNX; `export_precision=Precision.FP16`
to halve size for supported hardware. Both enums live in `getitune.types`.
- Done when: `engine.export(...)` returns a path to the written artifact.
3. **Confirm the artifact exists** under `work_dir` (`.xml` + `.bin` for
OpenVINO IR, `.onnx` for ONNX).
- Done when: the returned path exists on disk.
4. **Validate parity** by loading the exported model back and running
`engine.test()` — accuracy should closely match the trained model (small
FP16 drift is expected). See `getitune-running-inference`.
- Done when: exported-model metrics are within tolerance of the trained model.onnx_fp16 = engine.export(export_format=ExportFormat.ONNX, export_precision=Precision.FP16)
1. **先训练或加载模型到engine中**(导出操作针对engine当前的模型)。
- 完成标志:导出前`engine.test()`能生成合理的指标。
2. **选择格式和精度**。默认是FP32精度的OpenVINO IR。使用`export_format=ExportFormat.ONNX`指定ONNX格式;使用`export_precision=Precision.FP16`可在支持的硬件上将模型体积减半。这两个枚举类型都位于`getitune.types`中。
- 完成标志:`engine.export(...)`返回导出产物的文件路径。
3. **确认产物存在于`work_dir`目录下**(OpenVINO IR对应`.xml`+`.bin`文件,ONNX对应`.onnx`文件)。
- 完成标志:返回的路径在磁盘上真实存在。
4. **验证一致性**:将导出的模型加载回engine并运行`engine.test()`——其准确率应与训练后的模型高度匹配(FP16精度可能会出现微小偏差)。详见`getitune-running-inference`技能。
- 完成标志:导出模型的指标在训练模型指标的可接受误差范围内。CLI workflow
CLI 工作流
bash
undefinedbash
undefinedfrom library/
在library/目录下执行
getitune export --data_root /path/to/dataset --model efficientnet_b0
getitune export --data_root /path/to/dataset --model efficientnet_b0
use --help -v for export-format / precision flags
使用--help -v查看导出格式/精度相关的参数
undefinedundefinedExport/load contract
导出/加载约定
- Each model implements under
forward_for_tracing(...); that is what defines the exported graph. If you change model I/O, keep this method in sync or export parity breaks.library/src/getitune/backend/lightning/models/<task>/ - Exported OpenVINO IR / ONNX models are loaded for inference through the
OpenVINO backend () using ModelAPI.
OVEngine - Each task also ships an recipe for loading a pre-exported IR model directly.
openvino_model.yaml
- 每个模型在目录下实现了
library/src/getitune/backend/lightning/models/<task>/方法;该方法定义了导出的计算图。如果修改了模型的输入输出,请同步更新此方法,否则会破坏导出一致性。forward_for_tracing(...) - 导出的OpenVINO IR/ONNX模型会通过OpenVINO后端(),借助ModelAPI加载以进行推理。
OVEngine - 每个任务还附带一个配置文件,用于直接加载预导出的IR模型。
openvino_model.yaml
Verify
验证
bash
undefinedbash
undefinedfrom library/
在library/目录下执行
just lint
just test-unit -- -k export # when you touched export/tracing code
undefinedjust lint
just test-unit -- -k export # 当修改了导出/追踪代码时执行
undefinedRelated skills
相关技能
- — produce the checkpoint to export.
getitune-training-a-model - — load and validate the exported model.
getitune-running-inference - — quantize an exported OpenVINO model to INT8.
getitune-optimizing-a-model
- —— 生成可供导出的模型 checkpoint。
getitune-training-a-model - —— 加载并验证导出的模型。
getitune-running-inference - —— 将导出的OpenVINO模型量化为INT8精度。
getitune-optimizing-a-model