nemo_deploy.llm.inference.nemo_utils#
NeMo utility code copied from the NeMo project.
All utilities here are copied directly from NeMo and have no static dependency on the nemo package. When a NeMo checkpoint is loaded at runtime, NeMo classes are imported transitively through pydoc.locate inside nemo_io.load_context — NeMo must therefore still be installed to read NeMo checkpoints.
Sources:
MCoreTokenizerWrappper : nemo/collections/llm/inference/base.py
ckpt_to_dir, idempotent_path_append, ckpt_to_context_subdir : nemo/lightning/ckpt_utils.py
ckpt_to_weights_subdir : nemo/lightning/io/pl.py
constants : nemo/lightning/ckpt_utils.py
set_modelopt_spec_* : nemo/collections/llm/modelopt/model_utils.py
load_context, io : nemo_io.py (copied from nemo/lightning/io/)
Module Contents#
Classes#
Thin wrapper that adapts a NeMo tokenizer to the MCore generate API. |
Functions#
Return the checkpoint directory path for a given filepath. |
|
Append suffix to base_dir only when it is not already the last component. |
|
Return the |
|
Return the |
|
Set model.config.transformer_layer_spec to a modelopt spec if the
checkpoint contains a |
Data#
API#
- nemo_deploy.llm.inference.nemo_utils._logger = 'getLogger(...)'#
- nemo_deploy.llm.inference.nemo_utils.io = 'SimpleNamespace(...)'#
- nemo_deploy.llm.inference.nemo_utils.GPTConfig = None#
- nemo_deploy.llm.inference.nemo_utils.T5Config = None#
- nemo_deploy.llm.inference.nemo_utils.WEIGHTS_PATH: str = 'weights'#
- nemo_deploy.llm.inference.nemo_utils.CONTEXT_PATH: str = 'context'#
- nemo_deploy.llm.inference.nemo_utils.ADAPTER_META_FILENAME: str = 'adapter_metadata.json'#
- nemo_deploy.llm.inference.nemo_utils.ckpt_to_dir(filepath: Union[str, pathlib.Path]) pathlib.Path#
Return the checkpoint directory path for a given filepath.
PTL treats checkpoints as
.ckptfiles. This helper strips the extension (appending it first when absent) and returns a :class:Pathsuitable for use as a distributed-checkpoint directory.Copied from
nemo.lightning.ckpt_utils.ckpt_to_dirwith theAdapterPathandMultiStorageClientbranches removed.
- nemo_deploy.llm.inference.nemo_utils.idempotent_path_append(
- base_dir: Union[str, pathlib.Path],
- suffix: str,
Append suffix to base_dir only when it is not already the last component.
Copied from
nemo.lightning.ckpt_utils.idempotent_path_appendwith theAdapterPathandMultiStorageClientbranches removed.
- nemo_deploy.llm.inference.nemo_utils.ckpt_to_context_subdir(
- filepath: Union[str, pathlib.Path],
Return the
contextsub-directory of a NeMo-2 checkpoint.Copied from
nemo.lightning.ckpt_utils.ckpt_to_context_subdir.
- nemo_deploy.llm.inference.nemo_utils.ckpt_to_weights_subdir(
- filepath: Union[str, pathlib.Path],
- is_saving: bool,
Return the
weightssub-directory of a NeMo-2 checkpoint.Copied from
nemo.lightning.io.pl.ckpt_to_weights_subdirwith theAdapterPathbranch removed.
- class nemo_deploy.llm.inference.nemo_utils.MCoreTokenizerWrappper(tokenizer, vocab_size=None)#
Thin wrapper that adapts a NeMo tokenizer to the MCore generate API.
MCore’s generate pipeline expects
tokenizer.detokenize,tokenizer.tokenize,tokenizer.bos, andtokenizer.pad– this wrapper maps those calls to the corresponding NeMo tokenizer methods/properties.Copied verbatim from
nemo.collections.llm.inference.base.MCoreTokenizerWrappper.Initialization
- detokenize(tokens, remove_special_tokens=False)#
Detokenize tokens into a string.
- tokenize(prompt)#
Tokenize prompt into a list of token IDs.
- property additional_special_tokens_ids#
IDs of additional special tokens.
- property bos#
Beginning-of-sequence token ID.
- property pad#
Padding token ID.
- nemo_deploy.llm.inference.nemo_utils.set_modelopt_spec_if_exists_in_ckpt(model, path: str) None#
Set model.config.transformer_layer_spec to a modelopt spec if the checkpoint contains a
modelopt_statedirectory.Copied from
nemo.collections.llm.modelopt.model_utils.set_modelopt_spec_if_exists_in_ckptwith NeMo isinstance checks replaced by class-name comparisons.