Skip to content

Commit 63b5219

Browse files
committed
f
Signed-off-by: oliver könig <okoenig@nvidia.com>
1 parent b545006 commit 63b5219

7 files changed

Lines changed: 56 additions & 24 deletions

File tree

nemo_export/onnx_llm_exporter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from typing import Any, Callable, Dict, List, Optional, Union
1919

2020
import numpy as np
21-
import tensorrt as trt
2221
import torch
2322
import wrapt
2423
from nemo.collections.llm.modelopt.quantization.quant_cfg_choices import (
@@ -36,6 +35,11 @@
3635
)
3736
from nemo_export_deploy_common.import_utils import UnavailableError
3837

38+
try:
39+
import tensorrt as trt
40+
except (ImportError, ModuleNotFoundError):
41+
raise UnavailableError("tensorrt is not installed. Please install it with `pip install nvidia-tensorrt`.")
42+
3943
try:
4044
import modelopt.torch.quantization as mtq
4145
except (ImportError, ModuleNotFoundError):

nemo_export/quantize/quantizer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
import torch.distributed as dist
2222
from megatron.core import parallel_state
2323
from megatron.core.transformer.module import Float16Module
24-
from nemo.collections.nlp.models.language_modeling.megatron_gpt_model import (
25-
MegatronGPTModel,
26-
)
2724

2825
from nemo_export_deploy_common.import_utils import UnavailableError
2926

3027
try:
28+
from nemo.collections.nlp.models.language_modeling.megatron_gpt_model import MegatronGPTModel
3129
from nemo.collections.nlp.parts.utils_funcs import torch_dtype_from_precision
3230
from nemo.utils import logging
3331
from nemo.utils.distributed import temporary_directory

nemo_export/tensorrt_lazy_compiler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222
from typing import Any, Dict, List, Sequence, Tuple, Union
2323

2424
import torch
25-
from nemo.utils.export_utils import add_casts_around_norms, replace_for_export
26-
from nemo.utils.import_utils import safe_import
25+
26+
from nemo_export_deploy_common.import_utils import UnavailableError
27+
28+
try:
29+
from nemo.utils.export_utils import add_casts_around_norms, replace_for_export
30+
from nemo.utils.import_utils import safe_import
31+
except (ImportError, ModuleNotFoundError):
32+
raise UnavailableError("nemo is not installed. Please install it with `pip install nemo`.")
2733

2834
polygraphy, polygraphy_imported = safe_import("polygraphy")
2935
if polygraphy_imported:

nemo_export/tensorrt_mm_exporter.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,26 @@
2121

2222
import numpy as np
2323
import wrapt
24-
from tensorrt_llm.runtime import MultimodalModelRunner as TRTLLMRunner
25-
26-
from nemo_deploy import ITritonDeployable
27-
from nemo_export.multimodal.build import (
28-
build_mllama_engine,
29-
build_trtllm_engine,
30-
build_visual_engine,
31-
extract_lora_ckpt,
32-
)
33-
from nemo_export.multimodal.run import MultimodalModelRunner
34-
from nemo_export.tarutils import unpack_tarball
24+
25+
from nemo_export_deploy_common.import_utils import UnavailableError
26+
27+
try:
28+
from tensorrt_llm.runtime import MultimodalModelRunner as TRTLLMRunner
29+
except (ImportError, ModuleNotFoundError):
30+
raise UnavailableError("tensorrt_llm is not installed. Please install it with `pip install tensorrt-llm`.")
31+
32+
try:
33+
from nemo_deploy import ITritonDeployable
34+
from nemo_export.multimodal.build import (
35+
build_mllama_engine,
36+
build_trtllm_engine,
37+
build_visual_engine,
38+
extract_lora_ckpt,
39+
)
40+
from nemo_export.multimodal.run import MultimodalModelRunner
41+
from nemo_export.tarutils import unpack_tarball
42+
except (ImportError, ModuleNotFoundError):
43+
raise UnavailableError("nemo is not installed. Please install it with `pip install nemo`.")
3544

3645
use_deploy = True
3746
try:

nemo_export/trt_llm/converter/model_converter.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,22 @@
1818
import numpy as np
1919
import tensorrt_llm
2020
import torch
21-
from tensorrt_llm._utils import pad_vocab_size
22-
from tensorrt_llm.functional import non_gated_version
23-
from tensorrt_llm.layers import MoeConfig
24-
from tensorrt_llm.models.modeling_utils import PretrainedConfig
2521

2622
from nemo_export.trt_llm.converter.model_to_trt_llm_ckpt import (
2723
convert_model_to_trt_llm_ckpt,
2824
dist_model_to_trt_llm_ckpt,
2925
)
3026
from nemo_export.trt_llm.converter.utils import DECODER_MODEL_TYPE, split
27+
from nemo_export_deploy_common.import_utils import UnavailableError
28+
29+
try:
30+
from tensorrt_llm._utils import pad_vocab_size
31+
from tensorrt_llm.functional import non_gated_version
32+
from tensorrt_llm.layers import MoeConfig
33+
from tensorrt_llm.models.modeling_utils import PretrainedConfig
34+
except (ImportError, ModuleNotFoundError):
35+
raise UnavailableError("tensorrt_llm is not installed. Please install it with `pip install tensorrt-llm`.")
36+
3137

3238
LOGGER = logging.getLogger("NeMo")
3339

nemo_export/trt_llm/converter/model_to_trt_llm_ckpt.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from pathlib import Path
2020

2121
import torch
22-
from tensorrt_llm._utils import pad_vocab_size, str_dtype_to_torch
2322
from tqdm import tqdm
2423

2524
from nemo_export.trt_llm.converter.utils import (
@@ -29,6 +28,12 @@
2928
weights_dict,
3029
)
3130
from nemo_export.utils import torch_dtype_from_precision
31+
from nemo_export_deploy_common.import_utils import UnavailableError
32+
33+
try:
34+
from tensorrt_llm._utils import pad_vocab_size, str_dtype_to_torch
35+
except (ImportError, ModuleNotFoundError):
36+
raise UnavailableError("tensorrt_llm is not installed. Please install it with `pip install tensorrt-llm`.")
3237

3338
LOGGER = logging.getLogger("NeMo")
3439

nemo_export/trt_llm/qnemo/qnemo_to_tensorrt_llm.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
import warnings
2020
from typing import List, Optional
2121

22-
from tensorrt_llm.models import PretrainedConfig
23-
2422
from nemo_export.trt_llm.qnemo.utils import CONFIG_NAME, WEIGHTS_NAME
23+
from nemo_export_deploy_common.import_utils import UnavailableError
24+
25+
try:
26+
from tensorrt_llm.models import PretrainedConfig
27+
except (ImportError, ModuleNotFoundError):
28+
raise UnavailableError("tensorrt_llm is not installed. Please install it with `pip install tensorrt-llm`.")
2529

2630

2731
def qnemo_to_tensorrt_llm(

0 commit comments

Comments
 (0)