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

Add rope scaling configs for NeMo 1 #11807

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions nemo/collections/common/parts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,9 @@ def extend_instance(obj, mixin):
) # mixin needs to go first for our forward() logic to work


def apply_rope_scaling(freqs):
def apply_rope_scaling(freqs, scale_factor=8, low_freq_factor=1, high_freq_factor=4, old_context_len=8192):
# Apply scaling for RoPE frequencies
logger.info("apply rope scaling ...")
# Values obtained from grid search
scale_factor = 8
low_freq_factor = 1
high_freq_factor = 4
old_context_len = 8192 # original llama3 length

low_freq_wavelen = old_context_len / low_freq_factor
high_freq_wavelen = old_context_len / high_freq_factor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,13 @@ def mcore_model_customize(cfg, model):
if cfg.get("apply_embedding_scaling", False) and parallel_state.is_pipeline_first_stage():
extend_instance(model.embedding, EmbeddingScalingMixin)
if cfg.get("scale_positional_embedding", False):
model.rotary_pos_emb.inv_freq = apply_rope_scaling(model.rotary_pos_emb.inv_freq)
model.rotary_pos_emb.inv_freq = apply_rope_scaling(
model.rotary_pos_emb.inv_freq,
scale_factor=cfg.get('scale_factor', 8),
low_freq_factor=cfg.get('low_freq_factor', 1),
high_freq_factor=cfg.get('high_freq_factor', 4),
old_context_len=cfg.get('old_context_len', 8192),
)
if cfg.get("mcore_customization_config", {}).get("final_logit_softcapping", 0):
from nemo.collections.nlp.models.language_modeling.megatron.gemma2.gemma2_modules import Gemma2OutputLayer

Expand Down
Loading