Skip to content

Commit

Permalink
Merge branch 'main' into format_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tbartley94 authored Jul 26, 2024
2 parents 18899ac + 67aee7f commit 920c963
Show file tree
Hide file tree
Showing 19 changed files with 325 additions and 186 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.github/ @pablo-garay @ko3n1g
Dockerfile.ci @pablo-garay @ko3n1g
24 changes: 18 additions & 6 deletions Dockerfile.speech
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,28 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*

WORKDIR /workspace/

ARG TE_TAG=7d576ed25266a17a7b651f2c12e8498f67e0baea
ARG MCORE_TAG=338af51452a53982d202e8386db6233adad1ce86
ARG APEX_TAG=810ffae374a2b9cb4b5c5e28eaeca7d7998fca0c
# Install megatron core, this can be removed once 0.3 pip package is released
# We leave it here in case we need to work off of a specific commit in main
RUN git clone https://github.com/NVIDIA/Megatron-LM.git && \
cd Megatron-LM && \
git checkout c7a1f82d761577e6ca0338d3521eac82f2aa0904 && \
git checkout ${MCORE_TAG} && \
pip install .

# Performance optimizations for distributed optimizer: https://github.com/NVIDIA/apex/pull/1771
RUN git clone https://github.com/NVIDIA/apex.git && \
cd apex && \
git checkout f058162b215791b15507bb542f22ccfde49c872d && \
pip install -v --no-build-isolation --disable-pip-version-check --no-cache-dir --config-settings "--build-option=--cpp_ext --cuda_ext --fast_layer_norm --distributed_adam --deprecated_fused_adam" ./
git checkout ${APEX_TAG} && \
pip install -v --no-build-isolation --disable-pip-version-check --no-cache-dir \
--config-settings "--build-option=--cpp_ext --cuda_ext --fast_layer_norm --distributed_adam --deprecated_fused_adam" ./

# Transformer Engine 1.2.0
RUN git clone https://github.com/NVIDIA/TransformerEngine.git && \
cd TransformerEngine && \
git fetch origin da30634a6c9ccdbb6c587b6c93b1860e4b038204 && \
git fetch origin ${TE_TAG} && \
git checkout FETCH_HEAD && \
git submodule init && git submodule update && \
NVTE_FRAMEWORK=pytorch NVTE_WITH_USERBUFFERS=1 MPI_HOME=/usr/local/mpi pip install .
Expand Down Expand Up @@ -126,7 +131,9 @@ RUN INSTALL_MSG=$(/bin/bash /tmp/nemo/scripts/installers/install_k2.sh); INSTALL
WORKDIR /tmp/nemo
ENV LHOTSE_REQUIRE_TORCHAUDIO=0
COPY requirements .
RUN for f in $(ls requirements*.txt); do pip3 install --disable-pip-version-check --no-cache-dir -r $f; done
# exclude requirements_vllm.txt, since `vllm==0.5.x` breaks the container due to hardcoded requirements `torch==2.3.0`
RUN for f in $(ls requirements*.txt | grep -v 'requirements_vllm.txt'); do \
pip3 install --disable-pip-version-check --no-cache-dir -r $f; done

# install flash attention
RUN pip install flash-attn
Expand All @@ -151,7 +158,12 @@ RUN /usr/bin/test -n "$NEMO_VERSION" && \
RUN --mount=from=nemo-src,target=/tmp/nemo,rw cd /tmp/nemo && pip install ".[all]"

# Check install
RUN python -c "import nemo.collections.nlp as nemo_nlp" && \
# NB: adjusting LD_LIBRARY_PATH (only here, should not be persistent!) is a temporary hack
# to avoid failure if CUDA is unavailable (`docker build` does not expose GPUs)
# The error is raised in NeMo Core, and the main reason is reinstalled Transformer-Engine;
RUN export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${CUDA_HOME}/compat/lib.real && \
python -c "import nemo.collections.asr as nemo_asr" && \
python -c "import nemo.collections.nlp as nemo_nlp" && \
python -c "import nemo.collections.tts as nemo_tts" && \
python -c "import nemo_text_processing.text_normalization as text_normalization"

Expand Down
29 changes: 28 additions & 1 deletion nemo/collections/common/tokenizers/text_to_speech/ipa_lexicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

# fmt: off

SUPPORTED_LOCALES = ["en-US", "de-DE", "es-ES", "it-IT", "fr-FR"]

SUPPORTED_LOCALES = ["en-US", "de-DE", "es-ES", "it-IT", "fr-FR", "vi-VN"]


DEFAULT_PUNCTUATION = (
',', '.', '!', '?', '-',
Expand Down Expand Up @@ -48,6 +50,19 @@
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', 'Ä', 'Ö', 'Ü', 'ẞ',
),
# ref: https://en.wikipedia.org/wiki/Vietnamese_alphabet
"vi-VN": (
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', 'Đ', 'Á', 'À', 'Ã',
'Ả', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẵ', 'Ẳ', 'Ặ', 'Â', 'Ấ',
'Ầ', 'Ẫ', 'Ẩ', 'Ậ', 'Ó', 'Ò', 'Õ', 'Ỏ', 'Ọ', 'Ô',
'Ố', 'Ồ', 'Ỗ', 'Ổ', 'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ỡ', 'Ở',
'Ợ', 'É', 'È', 'Ẽ', 'Ẻ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ễ',
'Ể', 'Ệ', 'Ú', 'Ù', 'Ũ', 'Ủ', 'Ụ', 'Ư', 'Ứ', 'Ừ',
'Ữ', 'Ử', 'Ự', 'Í', 'Ì', 'Ĩ', 'Ỉ', 'Ị', 'Ý', 'Ỳ',
'Ỹ', 'Ỷ', 'Ỵ',
),
"fr-FR": (
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
Expand Down Expand Up @@ -104,6 +119,18 @@
'ɽ','ʂ','ʈ','ʧ','ʉ','ʋ','ⱱ','ɤ','ʍ','χ','ʏ','ʑ','ʐ',
'ʔ','ʡ','ʕ','ʢ','ǀ','ǁ','ǂ','ᵻ', 'ʃ','ː',
),
"vi-VN": (
'a', 'ə', 'ɛ', 'e', 'i', 'o', 'ɔ', 'u', 'ɨ',
'b', 'c', 'z', 'j', 'd', 'g', 'h', 'x', 'l',
'm', 'n', 'ŋ', 'ɲ', 'p', 'f', 'w', 'r', 's',
'ʃ', 't', 'ʈ', 'ʂ', 'v', 'ʔ', 'ɓ', 'ɗ', 'ɣ',
'k', 'ʰ', 'ʷ', 'ɕ', 'ʑ', 'ʝ', '̚', '̟', 't͡',
'˧', 'ː', 'ɯ', '̀', '̄', '̌', '̂', 'ˀ', '͡', '˥',
'˩', '̤', '˨', 'ɹ', 'ʲ', '̯', 'ă', 'ə̆', 'ǐ',
'˦', 'æ', 'ɐ',
'ɜ', 'ɡ', 'ɪ', 'ɬ' 'ɾ', 'ʊ', 'ʌ', 'ʒ', '̃',
'̩', 'θ', 'ᵻ',
),
}

GRAPHEME_CHARACTER_CASES = ["upper", "lower", "mixed"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"english_text_preprocessing",
"any_locale_text_preprocessing",
"spanish_text_preprocessing",
"vietnamese_text_preprocessing",
"italian_text_preprocessing",
"any_locale_word_tokenize",
"english_word_tokenize",
Expand Down Expand Up @@ -201,3 +202,7 @@ def chinese_text_preprocessing(text: str) -> str:

def french_text_preprocessing(text: str) -> str:
return text.lower()


def vietnamese_text_preprocessing(text: str) -> str:
return text.lower()
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
french_text_preprocessing,
italian_text_preprocessing,
spanish_text_preprocessing,
vietnamese_text_preprocessing,
)
from nemo.utils import logging
from nemo.utils.decorators import experimental
Expand Down Expand Up @@ -202,6 +203,43 @@ def __init__(
)


class VietnameseCharsTokenizer(BaseCharsTokenizer):

_LOCALE = "vi-VN"
_CHARSET_STR = get_grapheme_character_set(locale=_LOCALE, case="mixed")

def __init__(
self,
chars=_CHARSET_STR,
punct=True,
apostrophe=True,
add_blank_at=None,
pad_with_space=False,
non_default_punct_list=None,
text_preprocessing_func=vietnamese_text_preprocessing,
):
"""Vietnamese grapheme tokenizer.
Args:
punct: Whether to reserve grapheme for basic punctuation or not.
apostrophe: Whether to use apostrophe or not.
add_blank_at: Add blank to labels in the specified order ("last") or after tokens (any non None),
if None then no blank in labels.
pad_with_space: Whether to pad text with spaces at the beginning and at the end or not.
non_default_punct_list: List of punctuation marks which will be used instead default.
text_preprocessing_func: Text preprocessing function for correct execution of the tokenizer. By default, it
would keep any word lowercase.
"""
super().__init__(
chars=chars,
punct=punct,
apostrophe=apostrophe,
add_blank_at=add_blank_at,
pad_with_space=pad_with_space,
non_default_punct_list=non_default_punct_list,
text_preprocessing_func=vietnamese_text_preprocessing,
)


class GermanCharsTokenizer(BaseCharsTokenizer):

_LOCALE = "de-DE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,11 @@ def _enable_nvidia_optimizations(self):
# NVIDIA container version check
nvidia_torch_version = os.getenv('NVIDIA_PYTORCH_VERSION', None)

# Support DLFW master container
if nvidia_torch_version == 'master':
def is_official_release_version(nvidia_torch_version):
return re.fullmatch("[0-9][0-9]\.[0-9][0-9].*", nvidia_torch_version) # "YY.MM.*"

# Support DLFW dev container
if not is_official_release_version(nvidia_torch_version):
nvidia_torch_version = datetime.now().strftime('%y.%m')

if nvidia_torch_version is not None:
Expand All @@ -389,7 +392,7 @@ def _enable_nvidia_optimizations(self):
except Exception:
NVIDIA_TORCH_MAJOR = 0
try:
NVIDIA_TORCH_MINOR = int(nvidia_torch_version.split('.')[1])
NVIDIA_TORCH_MINOR = int(nvidia_torch_version.split('.')[1][:2])
except Exception:
NVIDIA_TORCH_MINOR = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,9 @@ def training_step(self, dataloader_iter):
ignore_virtual=True
):
if (
self.cfg.get('defer_embedding_wgrad_compute', False) and self.mcore_gpt
self.cfg.get('defer_embedding_wgrad_compute', False)
and self.mcore_gpt
and not self.use_mcore_dist_optim
): # Silently ignore the optimization if MCORE is not used
module_list = self.get_model_module_list()
if len(module_list) > 1:
Expand All @@ -839,7 +841,9 @@ def training_step(self, dataloader_iter):
ignore_virtual=True
):
if (
self.cfg.get('defer_embedding_wgrad_compute', False) and self.mcore_gpt
self.cfg.get('defer_embedding_wgrad_compute', False)
and self.mcore_gpt
and not self.use_mcore_dist_optim
): # Silently ignore the optimization if MCORE is not used
module_list = self.get_model_module_list()
if len(module_list) > 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def __init__(

te_version = packaging.version.Version(version("transformer-engine"))
if te_version >= packaging.version.Version("1.5.0dev") and (
not self.input_is_parallel and model_parallel_config.tp_comm_disable_qkv
not self.input_is_parallel and getattr(model_parallel_config, "tp_comm_overlap_disable_qkv", False)
):
# TE 1.5 introduces the option `return_layernorm_output_gathered`, so the all gather
# in the forward method is not needed, so set self._sequence_parallel to False
Expand Down
51 changes: 44 additions & 7 deletions nemo/export/tensorrt_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,24 @@
is_nemo_file,
load_nemo_model,
)
from nemo.export.trt_llm.qnemo import qnemo_to_tensorrt_llm
from nemo.export.trt_llm.qnemo.tokenizer_utils import get_nmt_tokenizer
from nemo.export.trt_llm.qnemo.utils import is_qnemo_checkpoint
from nemo.export.trt_llm.tensorrt_llm_build import build_and_save_engine
from nemo.export.trt_llm.tensorrt_llm_run import generate, generate_streaming, load, load_distributed, refit

LOGGER = logging.getLogger("NeMo")

use_model_opt = True
try:
from nemo.export.trt_llm.qnemo import qnemo_to_tensorrt_llm
from nemo.export.trt_llm.qnemo.tokenizer_utils import get_nmt_tokenizer
from nemo.export.trt_llm.qnemo.utils import is_qnemo_checkpoint
except Exception as e:
LOGGER.warning(f"Cannot import the Model Optimizer, it will not be available. {type(e).__name__}: {e}")
use_model_opt = False

use_deploy = True
try:
from nemo.deploy.utils import cast_output, str_ndarray2list
except Exception:
except Exception as e:
use_deploy = False


Expand All @@ -67,8 +75,6 @@ def wrapper(*args, **kwargs):
except Exception:
use_pytriton = False

LOGGER = logging.getLogger("NeMo")


class TensorRTLLM(ITritonDeployable):
"""
Expand All @@ -95,6 +101,8 @@ def __init__(
lora_ckpt_list: List[str] = None,
load_model: bool = True,
use_python_runtime: bool = True,
enable_chunked_context: bool = None,
max_tokens_in_paged_kv_cache: int = None,
):
"""
Args:
Expand All @@ -104,9 +112,19 @@ def __init__(
use_python_runtime (bool): whether to use python or c++ runtime.
"""

if use_python_runtime:
if enable_chunked_context is not None or max_tokens_in_paged_kv_cache is not None:
raise Exception(
"enable_chunked_context and max_tokens_in_paged_kv_cache options "
"work only with the TensorRT-LLM C++ runtime. Please set "
"use_python_runtime=False to use these options."
)

self.model_dir = model_dir
self.lora_ckpt_list = lora_ckpt_list
self.use_python_runtime = use_python_runtime
self.enable_chunked_context = enable_chunked_context if enable_chunked_context is not None else False
self.max_tokens_in_paged_kv_cache = max_tokens_in_paged_kv_cache
self.model = None
self.tokenizer = None
self.n_gpus = None
Expand Down Expand Up @@ -148,6 +166,10 @@ def export(
max_lora_rank: int = 64,
max_num_tokens: int = None,
opt_num_tokens: int = None,
max_seq_len: int = None,
multiple_profiles: bool = False,
gpt_attention_plugin: str = "auto",
gemm_plugin: str = "auto",
):
"""
Exports nemo checkpoints to TensorRT-LLM.
Expand Down Expand Up @@ -179,6 +201,10 @@ def export(
max_lora_rank (int): maximum lora rank.
max_num_tokens (int):
opt_num_tokens (int):
max_seq_len (int):
multiple_profiles: (bool): enables multiple profiles feature of TRT-LLM. Default = False
gpt_attention_plugin (str): enable the gpt attention plugin. Default = "auto"
gemm_plugin (str): enable the gpt plugin. Default = "auto"
"""

if n_gpus is not None:
Expand Down Expand Up @@ -233,7 +259,12 @@ def export(
tmp_dir = tempfile.TemporaryDirectory()
nemo_export_dir = Path(tmp_dir.name)

if is_qnemo_checkpoint(nemo_checkpoint_path):
is_qnemo_ckpt = False
if use_model_opt:
if is_qnemo_checkpoint(nemo_checkpoint_path):
is_qnemo_ckpt = True

if is_qnemo_ckpt:
if os.path.isdir(nemo_checkpoint_path):
nemo_export_dir = nemo_checkpoint_path
else:
Expand Down Expand Up @@ -310,6 +341,10 @@ def export(
paged_context_fmha=paged_context_fmha,
max_num_tokens=max_num_tokens,
opt_num_tokens=opt_num_tokens,
max_seq_len=max_seq_len,
multiple_profiles=multiple_profiles,
gpt_attention_plugin=gpt_attention_plugin,
gemm_plugin=gemm_plugin,
)

tokenizer_path = os.path.join(nemo_export_dir, "tokenizer.model")
Expand Down Expand Up @@ -838,6 +873,8 @@ def _load(self):
engine_dir=self.model_dir,
lora_ckpt_list=self.lora_ckpt_list,
use_python_runtime=self.use_python_runtime,
enable_chunked_context=self.enable_chunked_context,
max_tokens_in_paged_kv_cache=self.max_tokens_in_paged_kv_cache,
)
self._load_prompt_tables()
except Exception as error:
Expand Down
Loading

0 comments on commit 920c963

Please sign in to comment.