Skip to content

Commit

Permalink
[NeMo-UX[ Move nemotron imports inline (NVIDIA#10255)
Browse files Browse the repository at this point in the history
* Move nemotron transformers + tokenizer imports inline to reduce number of required deps

Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>

* Apply isort and black reformatting

Signed-off-by: marcromeyn <marcromeyn@users.noreply.github.com>

---------

Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: marcromeyn <marcromeyn@users.noreply.github.com>
Co-authored-by: marcromeyn <marcromeyn@users.noreply.github.com>
  • Loading branch information
2 people authored and WoodieDudy committed Aug 26, 2024
1 parent e57a09a commit dc0ce24
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions nemo/collections/llm/gpt/model/nemotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

import torch
from torch import nn
from transformers import NemotronConfig as HFNemotronConfig
from transformers import NemotronForCausalLM

from nemo.collections.common.tokenizers.huggingface.auto_tokenizer import AutoTokenizer
from nemo.collections.llm.fn.activation import squared_relu
from nemo.collections.llm.gpt.model.base import GPTConfig, GPTModel
from nemo.collections.llm.utils import Config
from nemo.lightning import OptimizerModule, io, teardown

if TYPE_CHECKING:
from transformers import NemotronConfig as HFNemotronConfig
from transformers import NemotronForCausalLM

from nemo.collections.common.tokenizers.huggingface.auto_tokenizer import AutoTokenizer
from nemo.collections.common.tokenizers.tokenizer_spec import TokenizerSpec


Expand Down Expand Up @@ -123,6 +124,8 @@ def init(self) -> NemotronModel:
return NemotronModel(self.config, tokenizer=self.tokenizer)

def apply(self, output_path: Path) -> Path:
from transformers import NemotronForCausalLM

source = NemotronForCausalLM.from_pretrained(str(self))
target = self.init()
trainer = self.nemo_setup(target)
Expand Down Expand Up @@ -155,10 +158,14 @@ def convert_state(self, source, target):

@property
def tokenizer(self) -> "AutoTokenizer":
from nemo.collections.common.tokenizers.huggingface.auto_tokenizer import AutoTokenizer

return AutoTokenizer(str(self))

@property
def config(self) -> NemotronConfig:
from transformers import NemotronConfig as HFNemotronConfig

source = HFNemotronConfig.from_pretrained(str(self))

def make_vocab_size_divisible_by(vocab_size):
Expand Down Expand Up @@ -224,6 +231,8 @@ def tokenizer(self):

@property
def config(self) -> "HFNemotronConfig":
from transformers import NemotronConfig as HFNemotronConfig

source: NemotronConfig = io.load_context(str(self)).model.config

return HFNemotronConfig(
Expand Down

0 comments on commit dc0ce24

Please sign in to comment.