Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gemma2 in Nemo2 with Recipes #11037

Merged
merged 16 commits into from
Oct 30, 2024
10 changes: 10 additions & 0 deletions nemo/collections/llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
CodeLlamaConfig13B,
CodeLlamaConfig34B,
CodeLlamaConfig70B,
Gemma2Config,
Gemma2Config2B,
Gemma2Config9B,
Gemma2Config27B,
Gemma2Model,
GemmaConfig,
GemmaConfig2B,
GemmaConfig7B,
Expand Down Expand Up @@ -165,6 +170,11 @@
"CodeGemmaConfig2B",
"CodeGemmaConfig7B",
"GemmaModel",
"Gemma2Model",
"Gemma2Config9B",
"Gemma2Config",
"Gemma2Config27B",
"Gemma2Config2B",
"Baichuan2Config",
"Baichuan2Config7B",
"Baichuan2Model",
Expand Down
12 changes: 12 additions & 0 deletions nemo/collections/llm/gpt/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
GemmaConfig7B,
GemmaModel,
)
from nemo.collections.llm.gpt.model.gemma2 import (
Gemma2Config,
Gemma2Config2B,
Gemma2Config9B,
Gemma2Config27B,
Gemma2Model,
)
from nemo.collections.llm.gpt.model.hf_auto_model_for_causal_lm import HfAutoModelForCausalLM
from nemo.collections.llm.gpt.model.llama import (
CodeLlamaConfig7B,
Expand Down Expand Up @@ -142,6 +149,11 @@
"CodeGemmaConfig2B",
"CodeGemmaConfig7B",
"GemmaModel",
"Gemma2Config",
"Gemma2Config27B",
"Gemma2Config2B",
"Gemma2Config9B",
"Gemma2Model",
"LlamaModel",
"Baichuan2Config",
"Baichuan2Config7B",
Expand Down
6 changes: 4 additions & 2 deletions nemo/collections/llm/gpt/model/gemma.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from typing import TYPE_CHECKING, Annotated, Callable, Optional

import torch
from megatron.core import parallel_state
from torch import nn

from nemo.collections.llm.fn.activation import openai_gelu
Expand Down Expand Up @@ -95,7 +96,8 @@ def configure_model(self):
from nemo.collections.nlp.models.language_modeling.megatron_gpt_model import EmbeddingScalingMixin

super().configure_model()
extend_instance(self.module.embedding, EmbeddingScalingMixin)
if parallel_state.is_pipeline_first_stage():
extend_instance(self.module.embedding, EmbeddingScalingMixin)


@io.model_importer(GemmaModel, "hf")
Expand Down Expand Up @@ -160,7 +162,7 @@ def make_vocab_size_divisible_by(vocab_size):
rotary_base=source.rope_theta,
gated_linear_unit=True,
make_vocab_size_divisible_by=make_vocab_size_divisible_by(source.vocab_size),
share_embeddings_and_output_weights=False,
share_embeddings_and_output_weights=True,
fp16=(dtype_from_hf(source) == torch.float16),
bf16=(dtype_from_hf(source) == torch.bfloat16),
params_dtype=dtype_from_hf(source),
Expand Down
Loading
Loading