nemo_export.utils.utils
#
Module Contents#
Functions#
Checks if the checkpoint is in NeMo 2.0 format. |
|
Prepares model_dir path for the TensorRTT-LLM / vLLM export. |
|
Checks if the path exists and points to packed NeMo 1 checkpoint. |
|
Mapping from PyTorch Lighthing (PTL) precision types to corresponding PyTorch parameter data type. |
|
Find the device type the model is assigned to and ensure consistency. |
|
Gets example data to feed to the model during ONNX export. |
|
Checks the network to ensure itβs compatible with fp8 precison. |
API#
- nemo_export.utils.utils.is_nemo2_checkpoint(checkpoint_path: str) bool [source]#
Checks if the checkpoint is in NeMo 2.0 format.
- Parameters:
checkpoint_path (str) β Path to a checkpoint.
- Returns:
True if the path points to a NeMo 2.0 checkpoint; otherwise false.
- Return type:
bool
- nemo_export.utils.utils.prepare_directory_for_export(
- model_dir: Union[str, pathlib.Path],
- delete_existing_files: bool,
- subdir: Optional[str] = None,
Prepares model_dir path for the TensorRTT-LLM / vLLM export.
Makes sure that the model_dir directory exists and is empty.
- Parameters:
model_dir (str) β Path to the target directory for the export.
delete_existing_files (bool) β Attempt to delete existing files if they exist.
subdir (Optional[str]) β Subdirectory to create inside the model_dir.
- Returns:
None
- nemo_export.utils.utils.is_nemo_tarfile(path: str) bool [source]#
Checks if the path exists and points to packed NeMo 1 checkpoint.
- Parameters:
path (str) β Path to possible checkpoint.
- Returns:
NeMo 1 checkpoint exists and is in β.nemoβ format.
- Return type:
bool
- nemo_export.utils.utils.torch_dtype_from_precision(
- precision: Union[int, str],
- megatron_amp_O2: bool = True,
Mapping from PyTorch Lighthing (PTL) precision types to corresponding PyTorch parameter data type.
- Parameters:
precision (Union[int, str]) β The PTL precision type used.
megatron_amp_O2 (bool) β A flag indicating if Megatron AMP O2 is enabled.
- Returns:
The corresponding PyTorch data type based on the provided precision.
- Return type:
torch.dtype
- nemo_export.utils.utils.get_model_device_type(module: torch.nn.Module) str [source]#
Find the device type the model is assigned to and ensure consistency.
- nemo_export.utils.utils.get_example_inputs(
- tokenizer: transformers.PreTrainedTokenizerBase,
- device: Optional[Union[str, torch.device]] = None,
Gets example data to feed to the model during ONNX export.
- Parameters:
tokenizer (PreTrainedTokenizerBase) β Tokenizer to use for generating example inputs.
device (Optional[Union[str, torch.device]]) β Device to which the example inputs should be moved.
- Returns:
Dictionary of tokenizer outputs.