2727from nemo_deploy import ITritonDeployable
2828from nemo_deploy .llm .inference .inference_base import create_mcore_engine
2929from nemo_deploy .utils import (
30- NEMO2 ,
3130 broadcast_list ,
3231 cast_output ,
33- nemo_checkpoint_version ,
3432 str_ndarray2list ,
3533)
3634from nemo_export_deploy_common .import_utils import MISSING_TRITON_MSG , UnavailableError , null_decorator
5452LOGGER = logging .getLogger ("NeMo" )
5553
5654
57- class MegatronLLMDeploy :
58- """A factory class for creating deployable instances of Megatron LLM models.
59-
60- This class provides a method to get the appropriate deployable instance
61- based on the version of the NeMo checkpoint model used.
62- """
63-
64- @staticmethod
65- def get_deployable (
66- nemo_checkpoint_filepath : str ,
67- num_devices : int = None ,
68- num_nodes : int = None ,
69- tensor_model_parallel_size : int = 1 ,
70- pipeline_model_parallel_size : int = 1 ,
71- expert_model_parallel_size : int = 1 ,
72- context_parallel_size : int = 1 ,
73- max_batch_size : int = 32 ,
74- random_seed : Optional [int ] = None ,
75- enable_flash_decode : bool = False ,
76- enable_cuda_graphs : bool = False ,
77- legacy_ckpt : bool = False ,
78- ):
79- """Returns the appropriate deployable instance for the given NeMo checkpoint.
80-
81- Args:
82- nemo_checkpoint_filepath (str): Path to the .nemo checkpoint file.
83- num_devices (int): Number of devices to use for deployment.
84- num_nodes (int): Number of nodes to use for deployment.
85- tensor_model_parallel_size (int): Size of the tensor model parallelism.
86- pipeline_model_parallel_size (int): Size of the pipeline model parallelism.
87- context_parallel_size (int): Size of the context parallelism.
88- enable_flash_decode (bool): Whether to enable flash decode for inference.
89- enable_cuda_graphs (bool): Whether to enable CUDA graphs for inference.
90- legacy_ckpt (bool): Whether to use legacy checkpoint format. Defaults to False.
91-
92- Returns:
93- ITritonDeployable: An instance of a deployable class compatible with Triton inference server.
94- """
95- if nemo_checkpoint_version (nemo_checkpoint_filepath ) == NEMO2 :
96- return MegatronLLMDeployableNemo2 (
97- num_devices = num_devices ,
98- num_nodes = num_nodes ,
99- nemo_checkpoint_filepath = nemo_checkpoint_filepath ,
100- tensor_model_parallel_size = tensor_model_parallel_size ,
101- pipeline_model_parallel_size = pipeline_model_parallel_size ,
102- context_parallel_size = context_parallel_size ,
103- expert_model_parallel_size = expert_model_parallel_size ,
104- max_batch_size = max_batch_size ,
105- random_seed = random_seed ,
106- enable_flash_decode = enable_flash_decode ,
107- enable_cuda_graphs = enable_cuda_graphs ,
108- legacy_ckpt = legacy_ckpt ,
109- )
110- else :
111- raise Exception ("Only NeMo 2.0 checkpoint is supported." )
112-
113-
11455def dict_to_str (messages ):
11556 """Serializes dict to str."""
11657 return json .dumps (messages )
11758
11859
119- class MegatronLLMDeployableNemo2 (ITritonDeployable ):
120- """Triton inference server compatible deploy class for a .nemo model file .
60+ class MegatronLLMDeployable (ITritonDeployable ):
61+ """Triton inference server compatible deploy class for a Megatron model checkpoint .
12162
12263 Args:
123- nemo_checkpoint_filepath (str): path for the nemo checkpoint.
64+ megatron_checkpoint_filepath (str): path for the megatron checkpoint.
12465 num_devices (int): number of GPUs.
12566 num_nodes (int): number of nodes.
12667 tensor_model_parallel_size (int): tensor parallelism.
@@ -136,17 +77,15 @@ class MegatronLLMDeployableNemo2(ITritonDeployable):
13677 enable_flash_decode (bool): enable flash decode for inference. Defaults to False.
13778 enable_cuda_graphs (bool): enable CUDA graphs for inference. Defaults to False.`
13879 legacy_ckpt (bool): use legacy checkpoint format. Defaults to False.
139- megatron_checkpoint_filepath (str): path for the megatron checkpoint.
140- model_type (str): type of model to load. Defaults to "gpt".(Only for Megatron models)
141- model_format (str): format of model to load. Defaults to "nemo".
142- micro_batch_size (Optional[int]): micro batch size for model execution. Defaults to None.(Only for Megatron models)
80+ model_type (str): type of model to load. Defaults to "gpt".
81+ micro_batch_size (Optional[int]): micro batch size for model execution. Defaults to None.
14382 """
14483
14584 def __init__ (
14685 self ,
86+ megatron_checkpoint_filepath : str ,
14787 num_devices : int = None ,
14888 num_nodes : int = None ,
149- nemo_checkpoint_filepath : str = None ,
15089 tensor_model_parallel_size : int = 1 ,
15190 pipeline_model_parallel_size : int = 1 ,
15291 context_parallel_size : int = 1 ,
@@ -159,28 +98,20 @@ def __init__(
15998 max_batch_size : int = 8 ,
16099 random_seed : Optional [int ] = None ,
161100 legacy_ckpt : bool = False ,
162- megatron_checkpoint_filepath : str = None ,
163101 model_type : str = "gpt" ,
164- model_format : str = "nemo" ,
165102 micro_batch_size : Optional [int ] = None ,
166103 ** model_config_kwargs ,
167104 ):
168105 if not HAVE_TRITON :
169106 raise UnavailableError (MISSING_TRITON_MSG )
170107
171- if model_format == "nemo" :
172- checkpoint_filepath = nemo_checkpoint_filepath
173- elif model_format == "megatron" :
174- if model_type not in ["gpt" , "mamba" ]:
175- raise ValueError (f"Model type { model_type } not supported for Megatron models." )
176- checkpoint_filepath = megatron_checkpoint_filepath
177- else :
178- raise ValueError (f"Model format { model_format } not supported." )
108+ if model_type not in ["gpt" , "mamba" ]:
109+ raise ValueError (f"Model type { model_type } not supported for Megatron models." )
179110
180111 self .mcore_engine , self .inference_wrapped_model , self .mcore_tokenizer = create_mcore_engine (
181112 num_devices = num_devices ,
182113 num_nodes = num_nodes ,
183- path = Path (checkpoint_filepath ),
114+ path = Path (megatron_checkpoint_filepath ),
184115 params_dtype = params_dtype ,
185116 inference_batch_times_seqlen_threshold = inference_batch_times_seqlen_threshold ,
186117 inference_max_seq_length = inference_max_seq_length ,
@@ -194,7 +125,7 @@ def __init__(
194125 enable_cuda_graphs = enable_cuda_graphs ,
195126 legacy_ckpt = legacy_ckpt ,
196127 model_type = model_type ,
197- model_format = model_format ,
128+ model_format = "megatron" ,
198129 micro_batch_size = micro_batch_size ,
199130 ** model_config_kwargs ,
200131 )
0 commit comments