MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / as_onnx_model

Method as_onnx_model

demo/HuggingFace/NNDF/models.py:299–322  ·  view source on GitHub ↗

Converts the torch model into an onnx model. Args: output_fpath (str): File location of the generated ONNX file. converter (ModelFileConverter): Class to convert current model instance into another. force_overwrite (bool): If the file already exi

(
        self,
        output_fpath: str,
        converter: ModelFileConverter = None,
        force_overwrite: bool = False,
    )

Source from the content-addressed store, hash-verified

297 return load(self.fpath)
298
299 def as_onnx_model(
300 self,
301 output_fpath: str,
302 converter: ModelFileConverter = None,
303 force_overwrite: bool = False,
304 ):
305 """
306 Converts the torch model into an onnx model.
307
308 Args:
309 output_fpath (str): File location of the generated ONNX file.
310 converter (ModelFileConverter): Class to convert current model instance into another.
311 force_overwrite (bool): If the file already exists, tell whether or not to overwrite.
312 Since torch models folders, can potentially erase entire folders.
313 Return:
314 (converter.onnx_class): Returns a converted instance of ONNXModelFile.
315 """
316 converter = self.default_converter if converter is None else converter()
317 if not force_overwrite and os.path.exists(output_fpath):
318 return converter.onnx_class(output_fpath, self.network_metadata)
319
320 return converter.torch_to_onnx(
321 output_fpath, self.load_model(), self.network_metadata
322 )
323
324 def as_torch_model(
325 self,

Callers

nothing calls this directly

Calls 2

load_modelMethod · 0.95
torch_to_onnxMethod · 0.45

Tested by

no test coverage detected