4.2.6.8. 模型编译¶
- horizon_plugin_pytorch.quantization.check_model(module, example_inputs, march=None, input_source='ddr', advice=None)¶
Check if nn.Module or jit.ScriptModule can be compiled by HBDK.
Dump advices for improving performance on BPU.
- 参数
module – nn.Module or jit.ScriptModule.
example_inputs (tuple) – Example inputs in torch.tensor format, for jit.trace and shape inference.
march (str) – Target BPU march. Valid options are bayes and bernoulli2. If not provided, use horizon plugin global march.
input_source (str or sequence) – Input feature sources (ddr / resizer / pyramid).
advice (int) – Print HBDK compiler advices for improving the utilization of the model on BPU if layers of the model become slow by more than the specified time (in microseconds).
- 返回
0 if pass, otherwise not.
- 返回类型
int
- horizon_plugin_pytorch.quantization.compile_model(module, example_inputs, hbm, march=None, name=None, input_source='ddr', input_layout=None, output_layout='NCHW', opt='O2', balance_factor=2, progressbar=True, jobs=16, debug=True, extra_args=None)¶
Compile the nn.Module or jit.ScriptModule.
- 参数
module – nn.Module or jit.ScriptModule.
example_inputs (tuple) – Example inputs in torch.tensor format.
hbm (str) – Output path of hbdk-cc.
march (str) – Target BPU march (bayes / bernoulli2).
name (str) – Name of the model, recorded in hbm.
input_source (str or sequence) – Input feature sources (ddr / resizer / pyramid).
input_layout (str) – NHWC, NCHW or BPU_RAW.
output_layout (str) – NHWC, NCHW or BPU_RAW.
opt (str or int) – O0, O1, O2, O3, ddr, fast, balance.
balance_factor (int) – Balance ratio when opt is ‘balance’.
progressbar (bool) – Show compilation progress.
jobs (int) – Compiler threads. 0 means all available hardware concurrency.
debug (bool) – Enable debugging info in hbm.
extra_args (list) – Extra args listed in
hbdk-cc -h.
- 返回
0 if pass, otherwise not.
- 返回类型
int
- horizon_plugin_pytorch.quantization.export_hbir(module, example_inputs, hbir, march=None)¶
Export the nn.Module or jit.ScriptModule to hbdk3.HBIR.
- 参数
module – nn.Module or jit.ScriptModule.
example_inputs (tuple) – Example inputs in torch.tensor format.
hbir (str) – Output path of hbir.
march (str) – Target march (bayes / bernoulli2).
- 返回
Input names and output names.
- 返回类型
tuple
- horizon_plugin_pytorch.quantization.perf_model(module, example_inputs, march=None, out_dir='.', name=None, hbm=None, input_source='ddr', input_layout=None, output_layout='NCHW', opt='O3', balance_factor=2, progressbar=True, jobs=16, layer_details=False, extra_args=None)¶
Estimate the performance of nn.Module or jit.ScriptModule.
- 参数
module – nn.Module or jit.ScriptModule.
example_inputs (tuple) – Example inputs in torch.tensor format.
march (str) – Target BPU march (bayes / bernoulli2).
out_dir (str) – Output directory for performance results.
name (str) – Name of the model, recorded in hbm.
hbm (str) – Output path of hbdk-cc.
input_source (str or sequence) – Input feature sources (ddr / resizer / pyramid).
input_layout (str) – NHWC, NCHW or BPU_RAW.
output_layout (str) – NHWC, NCHW or BPU_RAW.
opt (str or int) – O0, O1, O2, O3, ddr, fast, balance.
balance_factor (int) – Balance ratio when opt is ‘balance’.
progressbar (bool) – Show compilation progress.
jobs (int) – Compiler threads.
layer_details (bool) – Show layer performance details (dev use only).
extra_args (list) – Extra args listed in
hbdk-cc -h.
- 返回
Performance details in json dict, or error code when fail.
- 返回类型
dict or int
- horizon_plugin_pytorch.quantization.visualize_model(module, example_inputs, march=None, save_path=None, show=True)¶
Visualize nn.Module or jit.ScriptModule at the view of HBDK.
- 参数
module – nn.Module or jit.ScriptModule.
example_inputs (tuple) – Example inputs in torch.tensor format, for jit.trace and shape inference.
march (str) – Target BPU march. Valid options are bayes and bernoulli2. If not provided, use horizon plugin global march.
save_path (str) – Path to save the plot image.
show (bool) – Display the plotted image via display. Make sure X-server is correctly configured.