4.2.6.6. TorchScript 模型保存和加载

horizon_plugin_pytorch.jit.load(f, map_location=None, _extra_files=None)

Load ScriptModule previously saved with horizon.jit.save.

In addition to loaded plugin version comparison with current plugin version, this function is same as torch.jit.load.

参数
  • f – A file-like object or a string containing a file name.

  • map_location (str or torch.device) – Dynamically remap storages to an alternative set of devices.

  • _extra_files (dict) – Extra filenames given in the map would be loaded.

返回

A ScriptModule object.

返回类型

ScriptModule

horizon_plugin_pytorch.jit.save(m, f, _extra_files=None)

Save ScriptModule.

In addition to plugin version saved, this function is same as torch.jit.save.

参数
  • m – A ScriptModule to save.

  • f – A file-like object (has to implement write and flush) or a string containing a file name.

  • _extra_files – Map from filename to contents which will be stored as part of f.