Skip to content

Commit 2a22a76

Browse files
Remove more nemo2 and unused code. (#584)
Signed-off-by: Onur Yilmaz <oyilmaz@nvidia.com>
1 parent eff2d3c commit 2a22a76

File tree

8 files changed

+5
-303
lines changed

8 files changed

+5
-303
lines changed

.github/labeler.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export:
22
- nemo_export/**/*
3-
- scripts/export/**/*
43
- tests/functional_tests/tests_trtllm/test_export.py
54
- tests/functional_tests/tests_onnx_trt/test_export.py
65
- tests/unit_tests/export/**/*
@@ -32,7 +31,6 @@ TensorRT-LLM:
3231
- nemo_export/trt_llm/**/*
3332
- nemo_export/tensorrt_llm*.py
3433
- tests/functional_tests/tests_trtllm/**/*
35-
- scripts/export/export_hf_to_nemo2.py
3634
- docs/llm/**/optimized/**/*
3735
- docs/mm/**/optimized/**/*
3836

nemo_export/onnx_llm_exporter.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from nemo_export.utils import (
2727
get_example_inputs,
2828
get_model_device_type,
29-
is_nemo2_checkpoint,
3029
validate_fp8_network,
3130
)
3231
from nemo_export_deploy_common.import_utils import (
@@ -157,10 +156,9 @@ def __init__(
157156
raise ValueError("A model was also passed but it will be overridden.")
158157

159158
if Path(self.model_name_or_path).is_dir():
160-
if is_nemo2_checkpoint(self.model_name_or_path):
161-
raise NotImplementedError("NeMo 2.0 checkpoint will be supported later.")
162-
else:
163-
self._load_hf_model()
159+
self._load_hf_model()
160+
else:
161+
raise ValueError("The model_name_or_path is not a valid directory.")
164162

165163
self.model.to(self.device)
166164

nemo_export/tensorrt_llm.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@
4949
unload_engine,
5050
)
5151
from nemo_export.trt_llm.utils import determine_quantization_settings, is_rank
52-
from nemo_export.utils import (
53-
is_nemo2_checkpoint,
54-
prepare_directory_for_export,
55-
)
52+
from nemo_export.utils import prepare_directory_for_export
5653
from nemo_export.utils.constants import TRTLLM_ENGINE_DIR
5754
from nemo_export_deploy_common.import_utils import (
5855
MISSING_TENSORRT_LLM_MSG,
@@ -704,7 +701,7 @@ def export(
704701
)
705702

706703
# Check if it's a NeMo2 checkpoint
707-
if not (Path(nemo_checkpoint_path).exists() and is_nemo2_checkpoint(nemo_checkpoint_path)):
704+
if not (Path(nemo_checkpoint_path).exists() and (Path(nemo_checkpoint_path) / "context").is_dir()):
708705
raise Exception(
709706
f"Standard NeMo export failed and checkpoint is not a NeMo2 checkpoint. "
710707
f"HF fallback only works with NeMo2 checkpoints. "

nemo_export/utils/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
from nemo_export.utils.utils import (
2323
get_example_inputs,
2424
get_model_device_type,
25-
is_nemo2_checkpoint,
26-
is_nemo_tarfile,
2725
prepare_directory_for_export,
2826
torch_dtype_from_precision,
2927
validate_fp8_network,
@@ -35,8 +33,6 @@
3533
"load_sharded_metadata_torch_dist",
3634
"load_sharded_metadata_zarr",
3735
"nemo_to_path",
38-
"is_nemo2_checkpoint",
39-
"is_nemo_tarfile",
4036
"prepare_directory_for_export",
4137
"torch_dtype_from_precision",
4238
"get_model_device_type",

nemo_export/utils/utils.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,6 @@
2121
from transformers import PreTrainedTokenizerBase
2222

2323

24-
def is_nemo2_checkpoint(checkpoint_path: str) -> bool:
25-
"""Checks if the checkpoint is in NeMo 2.0 format.
26-
27-
Args:
28-
checkpoint_path (str): Path to a checkpoint.
29-
30-
Returns:
31-
bool: True if the path points to a NeMo 2.0 checkpoint; otherwise false.
32-
"""
33-
ckpt_path = Path(checkpoint_path)
34-
return (ckpt_path / "context").is_dir()
35-
36-
3724
def prepare_directory_for_export(
3825
model_dir: Union[str, Path],
3926
delete_existing_files: bool,
@@ -64,19 +51,6 @@ def prepare_directory_for_export(
6451
model_path.mkdir(parents=True, exist_ok=True)
6552

6653

67-
def is_nemo_tarfile(path: str) -> bool:
68-
"""Checks if the path exists and points to packed NeMo 1 checkpoint.
69-
70-
Args:
71-
path (str): Path to possible checkpoint.
72-
73-
Returns:
74-
bool: NeMo 1 checkpoint exists and is in '.nemo' format.
75-
"""
76-
checkpoint_path = Path(path)
77-
return checkpoint_path.exists() and checkpoint_path.suffix == ".nemo"
78-
79-
8054
# Copied from nemo.collections.nlp.parts.utils_funcs to avoid introducing extra NeMo dependencies:
8155
def torch_dtype_from_precision(precision: Union[int, str], megatron_amp_O2: bool = True) -> torch.dtype:
8256
"""Mapping from PyTorch Lighthing (PTL) precision types to corresponding PyTorch parameter data type.

scripts/export/export_hf_to_nemo2.py

Lines changed: 0 additions & 79 deletions
This file was deleted.

scripts/export/export_mm_to_trtllm.py

Lines changed: 0 additions & 148 deletions
This file was deleted.

tests/unit_tests/export/utils/test_exp_utils.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,6 @@ def temp_dir(self):
3131
# Cleanup after test
3232
shutil.rmtree(temp_dir)
3333

34-
@pytest.mark.run_only_on("GPU")
35-
def test_is_nemo2_checkpoint(self, temp_dir):
36-
from nemo_export.utils.utils import is_nemo2_checkpoint
37-
38-
# Test with non-existent path
39-
assert not is_nemo2_checkpoint("/non/existent/path")
40-
41-
# Test with directory without context folder
42-
os.makedirs(os.path.join(temp_dir, "no_context"))
43-
assert not is_nemo2_checkpoint(os.path.join(temp_dir, "no_context"))
44-
45-
# Test with valid NeMo 2.0 checkpoint
46-
os.makedirs(os.path.join(temp_dir, "valid_ckpt", "context"))
47-
assert is_nemo2_checkpoint(os.path.join(temp_dir, "valid_ckpt"))
48-
4934
@pytest.mark.run_only_on("GPU")
5035
def test_prepare_directory_for_export(self, temp_dir):
5136
from nemo_export.utils.utils import prepare_directory_for_export
@@ -76,25 +61,6 @@ def test_prepare_directory_for_export(self, temp_dir):
7661
prepare_directory_for_export(model_dir, delete_existing_files=False, subdir="subdir")
7762
assert os.path.exists(os.path.join(model_dir, "subdir"))
7863

79-
@pytest.mark.run_only_on("GPU")
80-
def test_is_nemo_tarfile(self, temp_dir):
81-
from nemo_export.utils.utils import is_nemo_tarfile
82-
83-
# Test with non-existent file
84-
assert not is_nemo_tarfile("/non/existent/file.nemo")
85-
86-
# Test with non-nemo file
87-
test_file = os.path.join(temp_dir, "test.txt")
88-
with open(test_file, "w") as f:
89-
f.write("test")
90-
assert not is_nemo_tarfile(test_file)
91-
92-
# Test with .nemo file
93-
nemo_file = os.path.join(temp_dir, "test.nemo")
94-
with open(nemo_file, "w") as f:
95-
f.write("test")
96-
assert is_nemo_tarfile(nemo_file)
97-
9864
@pytest.mark.run_only_on("GPU")
9965
def test_torch_dtype_from_precision(self):
10066
from nemo_export.utils.utils import torch_dtype_from_precision

0 commit comments

Comments
 (0)