Skip to content

Commit 3b7fa41

Browse files
Remove nemo from in-framework deployment
Signed-off-by: Onur Yilmaz <oyilmaz@nvidia.com>
1 parent ddb1a42 commit 3b7fa41

31 files changed

Lines changed: 79 additions & 3457 deletions

.github/labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TensorRT-LLM:
3333
- nemo_export/trt_llm/**/*
3434
- nemo_export/tensorrt_llm*.py
3535
- tests/functional_tests/tests_trtllm/**/*
36-
- scripts/export/export_to_trt_llm.py
36+
- scripts/export/export_hf_to_nemo2.py
3737
- docs/llm/**/optimized/**/*
3838
- docs/mm/**/optimized/**/*
3939

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,13 @@ In order to run examples with NeMo models, a NeMo checkpoint is required. Please
242242
huggingface-cli login
243243
```
244244

245-
4. Run the following Python code to generate the NeMo 2.0 checkpoint:
245+
4. Run the following Python code to generate the NeMo checkpoint:
246246

247-
```shell
248-
python scripts/export/export_hf_to_nemo2.py \
249-
--hf_model meta-llama/Llama-3.2-1B \
250-
--output_path /opt/checkpoints/hf_llama32_1B_nemo2 \
251-
--config Llama32Config1B
247+
```python
248+
from nemo.collections import llm
249+
250+
# Example: Converting Hugging Face model to NeMo format
251+
# See NeMo documentation for detailed instructions
252252
```
253253

254254
## 🚀 Export and Deploy Examples
@@ -297,9 +297,9 @@ from nemo_export.tensorrt_llm import TensorRTLLM
297297
from nemo_deploy import DeployPyTriton
298298

299299
# Export model to TensorRT-LLM
300-
exporter = TensorRTLLM(model_dir="/tmp/hf_llama32_1B_nemo2")
300+
exporter = TensorRTLLM(model_dir="/tmp/llama32_1B_nemo")
301301
exporter.export(
302-
nemo_checkpoint_path="/opt/checkpoints/hf_llama32_1B_nemo2",
302+
nemo_checkpoint_path="/opt/checkpoints/llama32_1B_nemo",
303303
tensor_parallelism_size=1,
304304
)
305305

@@ -328,8 +328,8 @@ from nemo_deploy import DeployPyTriton
328328
# Export model to vLLM
329329
exporter = vLLMExporter()
330330
exporter.export(
331-
nemo_checkpoint="/opt/checkpoints/hf_llama32_1B_nemo2",
332-
model_dir="/tmp/hf_llama32_1B_nemo2",
331+
nemo_checkpoint="/opt/checkpoints/llama32_1B_nemo",
332+
model_dir="/tmp/llama32_1B_nemo",
333333
tensor_parallel_size=1,
334334
)
335335

@@ -355,10 +355,10 @@ You can also deploy NeMo and Hugging Face models directly using Triton Inference
355355

356356
```python
357357
from nemo_deploy import DeployPyTriton
358-
from nemo_deploy.nlp.megatronllm_deployable import MegatronLLMDeployableNemo2
358+
from nemo_deploy.llm.megatronllm_deployable import MegatronLLMDeployable
359359

360-
model = MegatronLLMDeployableNemo2(
361-
nemo_checkpoint_filepath="/opt/checkpoints/hf_llama32_1B_nemo2",
360+
model = MegatronLLMDeployable(
361+
nemo_checkpoint_filepath="/opt/checkpoints/llama32_1B_nemo",
362362
num_devices=1,
363363
num_nodes=1,
364364
)

nemo_deploy/llm/megatronllm_deployable.py

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
from nemo_deploy import ITritonDeployable
2828
from nemo_deploy.llm.inference.inference_base import create_mcore_engine
2929
from nemo_deploy.utils import (
30-
NEMO2,
3130
broadcast_list,
3231
cast_output,
33-
nemo_checkpoint_version,
3432
str_ndarray2list,
3533
)
3634
from nemo_export_deploy_common.import_utils import MISSING_TRITON_MSG, UnavailableError, null_decorator
@@ -54,73 +52,16 @@
5452
LOGGER = 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-
11455
def 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
)

nemo_deploy/llm/megatronllm_deployable_ray.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from ray.util.scheduling_strategies import NodeAffinitySchedulingStrategy
2929

3030
from ..ray_utils import find_available_port
31-
from .megatronllm_deployable import MegatronLLMDeployableNemo2
31+
from .megatronllm_deployable import MegatronLLMDeployable
3232

3333
LOGGER = logging.getLogger("NeMo")
3434

@@ -44,7 +44,7 @@ class ModelWorker:
4444

4545
def __init__(
4646
self,
47-
nemo_checkpoint_filepath: str,
47+
megatron_checkpoint_filepath: str,
4848
rank: int,
4949
world_size: int,
5050
tensor_model_parallel_size: int,
@@ -59,9 +59,7 @@ def __init__(
5959
legacy_ckpt: bool = False,
6060
max_batch_size: int = 32,
6161
random_seed: Optional[int] = None,
62-
megatron_checkpoint_filepath: str = None,
6362
model_type: str = "gpt",
64-
model_format: str = "nemo",
6563
micro_batch_size: Optional[int] = None,
6664
**model_config_kwargs,
6765
):
@@ -83,8 +81,8 @@ def __init__(
8381
LOGGER.info(f"Replica {replica_id} - MASTER_ADDR: {os.environ['MASTER_ADDR']}")
8482

8583
try:
86-
self.model = MegatronLLMDeployableNemo2(
87-
nemo_checkpoint_filepath=nemo_checkpoint_filepath,
84+
self.model = MegatronLLMDeployable(
85+
megatron_checkpoint_filepath=megatron_checkpoint_filepath,
8886
num_devices=world_size,
8987
num_nodes=world_size // torch.cuda.device_count(),
9088
tensor_model_parallel_size=tensor_model_parallel_size,
@@ -96,9 +94,7 @@ def __init__(
9694
legacy_ckpt=legacy_ckpt,
9795
max_batch_size=max_batch_size,
9896
random_seed=random_seed,
99-
megatron_checkpoint_filepath=megatron_checkpoint_filepath,
10097
model_type=model_type,
101-
model_format=model_format,
10298
micro_batch_size=micro_batch_size,
10399
**model_config_kwargs,
104100
)
@@ -128,28 +124,26 @@ class MegatronRayDeployable:
128124

129125
def __init__(
130126
self,
131-
nemo_checkpoint_filepath: str,
127+
megatron_checkpoint_filepath: str,
132128
num_gpus: int = 1,
133129
tensor_model_parallel_size: int = 1,
134130
pipeline_model_parallel_size: int = 1,
135131
context_parallel_size: int = 1,
136132
expert_model_parallel_size: int = 1,
137-
model_id: str = "nemo-model",
133+
model_id: str = "megatron-model",
138134
enable_cuda_graphs: bool = False,
139135
enable_flash_decode: bool = False,
140136
legacy_ckpt: bool = False,
141137
max_batch_size: int = 32,
142138
random_seed: Optional[int] = None,
143-
megatron_checkpoint_filepath: str = None,
144139
model_type: str = "gpt",
145-
model_format: str = "nemo",
146140
micro_batch_size: Optional[int] = None,
147141
**model_config_kwargs,
148142
):
149143
"""Initialize the distributed Megatron LLM model deployment.
150144
151145
Args:
152-
nemo_checkpoint_filepath (str): Path to the .nemo checkpoint file.
146+
megatron_checkpoint_filepath (str): Path to the Megatron checkpoint directory.
153147
num_gpus (int): Number of GPUs to use for the deployment
154148
tensor_model_parallel_size (int): Size of tensor model parallelism.
155149
pipeline_model_parallel_size (int): Size of pipeline model parallelism.
@@ -194,7 +188,7 @@ def __init__(
194188

195189
# Common arguments for rank 0 worker
196190
rank_0_kwargs = dict(
197-
nemo_checkpoint_filepath=nemo_checkpoint_filepath,
191+
megatron_checkpoint_filepath=megatron_checkpoint_filepath,
198192
rank=0,
199193
world_size=num_gpus,
200194
tensor_model_parallel_size=tensor_model_parallel_size,
@@ -209,9 +203,7 @@ def __init__(
209203
legacy_ckpt=legacy_ckpt,
210204
max_batch_size=max_batch_size,
211205
random_seed=random_seed,
212-
megatron_checkpoint_filepath=megatron_checkpoint_filepath,
213206
model_type=model_type,
214-
model_format=model_format,
215207
micro_batch_size=micro_batch_size,
216208
**model_config_kwargs,
217209
)
@@ -233,7 +225,7 @@ def __init__(
233225
# Create remaining workers in parallel
234226
for rank in range(1, num_gpus):
235227
worker = ModelWorker.remote(
236-
nemo_checkpoint_filepath=nemo_checkpoint_filepath,
228+
megatron_checkpoint_filepath=megatron_checkpoint_filepath,
237229
rank=rank,
238230
world_size=num_gpus,
239231
tensor_model_parallel_size=tensor_model_parallel_size,
@@ -247,9 +239,7 @@ def __init__(
247239
enable_flash_decode=enable_flash_decode,
248240
max_batch_size=max_batch_size,
249241
random_seed=random_seed,
250-
megatron_checkpoint_filepath=megatron_checkpoint_filepath,
251242
model_type=model_type,
252-
model_format=model_format,
253243
micro_batch_size=micro_batch_size,
254244
**model_config_kwargs,
255245
)

nemo_deploy/utils.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import os
1615
import typing
17-
from pathlib import Path
1816

1917
import numpy as np
2018
import torch
2119

22-
from nemo_export.tarutils import TarPath
2320
from nemo_export_deploy_common.import_utils import MISSING_PIL_MSG, MISSING_TRITON_MSG, UnavailableError
2421

2522
try:
@@ -42,10 +39,6 @@
4239
HAVE_TRITON = False
4340

4441

45-
NEMO2 = "NEMO 2.0"
46-
NEMO1 = "NEMO 1.0"
47-
48-
4942
def typedict2tensor(
5043
typedict_class,
5144
overwrite_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None,
@@ -98,29 +91,6 @@ def _get_tensor_params(type_):
9891
)
9992

10093

101-
def nemo_checkpoint_version(path: str) -> str:
102-
"""Determines the version of a NeMo checkpoint from its file structure.
103-
104-
Examines the provided checkpoint path to determine if it follows the NeMo 2.0
105-
or NeMo 1.0 format based on the presence of 'context' and 'weights' directories.
106-
107-
Args:
108-
path (str): Path to the NeMo checkpoint file or directory
109-
110-
Returns:
111-
str: Version string - either NEMO2 or NEMO1 constant indicating the checkpoint version
112-
"""
113-
if os.path.isdir(path):
114-
path = Path(path)
115-
else:
116-
path = TarPath(path)
117-
118-
if (path / "context").exists() and (path / "weights").exists():
119-
return NEMO2
120-
else:
121-
return NEMO1
122-
123-
12494
def str_list2numpy(str_list: typing.List[str]) -> np.ndarray:
12595
"""Converts a list of strings to a numpy array of UTF-8 encoded bytes.
12696

0 commit comments

Comments
 (0)