Skip to content
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
21 changes: 11 additions & 10 deletions nemo/collections/llm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,16 +894,17 @@ def _validate_config(
) -> None:

## Model validation
assert getattr(model.config, "seq_length", 1) > 0
assert getattr(model.config, "max_position_embeddings", 1) > 0
assert model.config.num_layers > 0
assert model.config.hidden_size > 0
assert model.config.num_attention_heads > 0
assert model.config.ffn_hidden_size > 0

if hasattr(model.config, "seq_length"):
if getattr(model.config, "max_position_embeddings", None) is not None:
assert model.config.seq_length <= model.config.max_position_embeddings
if hasattr(model, "config"):
assert getattr(model.config, "seq_length", 1) > 0
assert getattr(model.config, "max_position_embeddings", 1) > 0
assert model.config.num_layers > 0
assert model.config.hidden_size > 0
assert model.config.num_attention_heads > 0
assert model.config.ffn_hidden_size > 0

if hasattr(model.config, "seq_length"):
if getattr(model.config, "max_position_embeddings", None) is not None:
assert model.config.seq_length <= model.config.max_position_embeddings

## Data validation
assert data.micro_batch_size > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,17 @@ def forward(
q_pos_emb, k_pos_emb = rotary_pos_emb

if packed_seq_params is not None:
cu_seqlens_q = packed_seq_params.cu_seqlens_q
cu_seqlens_kv = packed_seq_params.cu_seqlens_kv
if packed_seq_params.cu_seqlens_q_padded is not None:
cu_seqlens_q = packed_seq_params.cu_seqlens_q_padded
else:
cu_seqlens_q = packed_seq_params.cu_seqlens_q
if packed_seq_params.cu_seqlens_kv_padded is not None:
cu_seqlens_kv = packed_seq_params.cu_seqlens_kv_padded
else:
cu_seqlens_kv = packed_seq_params.cu_seqlens_kv
else:
cu_seqlens_q = cu_seqlens_kv = None

query = apply_rotary_pos_emb(query, q_pos_emb, config=self.config, cu_seqlens=cu_seqlens_q)
key = apply_rotary_pos_emb(key, k_pos_emb, config=self.config, cu_seqlens=cu_seqlens_kv)
# TODO, can apply positional embedding to value_layer so it has
Expand Down
3 changes: 3 additions & 0 deletions tests/collections/llm/gpt_finetuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
from dataclasses import dataclass

import torch
from megatron.core.optimizer import OptimizerConfig

from nemo import lightning as nl
Expand Down Expand Up @@ -55,6 +56,8 @@ def get_args():
strategy = nl.MegatronStrategy(
tensor_model_parallel_size=args.tp_size,
pipeline_model_parallel_size=args.pp_size,
# Pipeline dtype is coupled with the bf16 mixed precision plugin
pipeline_dtype=torch.bfloat16,
Comment on lines +59 to +60
Copy link
Collaborator Author

@ananthsub ananthsub Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi @hemildesai @BoxiangW for the parallelism setting refactor. this requirement is coming after #10954 which validates that the pipeline dtype is now set here.

there are multiple paths to set this:

  • either on the megatron strategy directly
  • via the precision plugin

setting it in multiple places feels wrong, especially since users have to make 2 hops in the codebase to figure this out:

  1. https://github.com/NVIDIA/NeMo/blob/bde672e75f1ac45ead08e2b977920a28eb81448e/nemo/lightning/pytorch/strategies/megatron_strategy.py#L288-L290
  2. https://github.com/NVIDIA/NeMo/blob/bde672e75f1ac45ead08e2b977920a28eb81448e/nemo/lightning/pytorch/plugins/mixed_precision.py#L107-L113C46

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better way than hardcoding pipeline_dtype is to make it a function attribute and set it's value if it's used https://github.com/NVIDIA/NeMo/pull/11504/files#diff-78f81f4094cfea056c177e87c0d527b9ce27cee11813138e5a2a69370b922c19R282

)

trainer = nl.Trainer(
Expand Down