getitune-optimizing-a-model
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOptimizing (quantizing) a model with getitune
使用getitune优化(量化)模型
getitune.xmlRun everything from .
library/所有操作请在目录下执行。
library/Workflow
工作流程
python
from getitune.engine import create_enginepython
from getitune.engine import create_engineLoad an exported OpenVINO model, then quantize it
加载导出的OpenVINO模型,然后对其进行量化
ov_engine = create_engine(
model="/path/to/exported_model.xml",
data="/path/to/dataset",
)
ov_engine.optimize() # INT8 post-training quantization via NNCF
int8_metrics = ov_engine.test() # validate the quantized model
predictions = ov_engine.predict() # run inference with the quantized model
1. **Start from an exported OpenVINO model** (`.xml`). If you only have a
checkpoint, export it first with the `getitune-exporting-a-model` skill.
- Done when: `create_engine(model="....xml", data=...)` builds an `OVEngine`.
2. **Provide a calibration dataset.** Calibration images are taken automatically
from the training subset; 200-500 images is the recommended calibration size.
- Done when: `optimize()` runs without a "not enough calibration data" issue.
3. **Run `optimize()`.** This replaces the engine's model in place with the INT8
version.
- Done when: the call completes and subsequent `test()`/`predict()` use INT8.
4. **Re-validate accuracy** with `test()` and compare against the FP32/FP16
baseline; a small accuracy drop is expected in exchange for size/latency.
- Done when: the INT8 metric is within your acceptable tolerance of baseline.ov_engine = create_engine(
model="/path/to/exported_model.xml",
data="/path/to/dataset",
)
ov_engine.optimize() # 通过NNCF执行INT8后训练量化
int8_metrics = ov_engine.test() # 验证量化后的模型
predictions = ov_engine.predict() # 使用量化模型运行推理
1. **从导出的OpenVINO模型(`.xml`)开始**。如果只有模型 checkpoint,请先使用`getitune-exporting-a-model`技能导出模型。
- 完成标志:`create_engine(model="....xml", data=...)`成功构建`OVEngine`。
2. **提供校准数据集**。校准图像会自动从训练子集中选取;推荐校准集大小为200-500张图像。
- 完成标志:`optimize()`运行时未出现“校准数据不足”的问题。
3. **运行`optimize()`**。该操作会将引擎中的模型替换为INT8版本。
- 完成标志:调用完成后,后续的`test()`/`predict()`使用的是INT8模型。
4. **使用`test()`重新验证精度**,并与FP32/FP16基线模型对比;通常会以微小的精度下降换取模型体积和延迟的优化。
- 完成标志:INT8模型的指标在可接受的基线误差范围内。Comparing against the original model
与原始模型对比
After the engine holds the INT8 model. To re-check the original
FP32/FP16 model, either pass the original path directly to /
, or create the engine again from the original .
optimize().xml.test().predict().xml执行后,引擎中保存的是INT8模型。如需重新检查原始FP32/FP16模型,可直接将原始路径传入 / ,或重新从原始创建引擎。
optimize().xml.test().predict().xmlNotes
注意事项
- Quantization is OpenVINO/NNCF-based and applies to exported IR models — it is not a training-time step.
- Only OpenVINO IR () is supported. An ONNX model must be converted to OpenVINO IR first before it can be optimized.
.xml - In the Geti application this is exposed as the job (
quantize); libraryapplication/backend/app/execution/quantization/is the same capability without the job/queue wrapper.optimize()
- 量化基于OpenVINO/NNCF实现,针对导出的IR模型进行——这不是训练阶段的操作。
- 仅支持OpenVINO IR()。ONNX模型必须先转换为OpenVINO IR才能进行优化。
.xml - 在Geti应用中,该功能以任务的形式提供(路径:
quantize);库中的application/backend/app/execution/quantization/具备相同功能,只是没有任务/队列封装。optimize()
Verify
验证
bash
undefinedbash
undefinedfrom library/
在library/目录下执行
just lint
just test-unit -- -k optimize # when you touched optimization code
undefinedjust lint
just test-unit -- -k optimize # 当修改了优化相关代码时执行
undefinedRelated skills
相关技能
- — produce the OpenVINO
getitune-exporting-a-modelto quantize..xml - — run inference with the quantized model.
getitune-running-inference
- — 生成待量化的OpenVINO
getitune-exporting-a-model模型。.xml - — 使用量化模型运行推理。
getitune-running-inference