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

Hyena wrapper: Weight decay override function #11203

Merged
merged 2 commits into from
Nov 11, 2024
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
9 changes: 9 additions & 0 deletions nemo/collections/llm/gpt/model/hyena.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from megatron.core import parallel_state
from megatron.core.models.hyena import HyenaModel as MCoreHyenaModel
from megatron.core.models.hyena.hyena_layer_specs import hyena_stack_spec
from megatron.core.ssm.hyena_utils import hyena_no_weight_decay_cond

HAVE_MEGATRON_CORE_OR_TE = True

Expand All @@ -39,6 +40,7 @@
from nemo.collections.llm.gpt.model.base import GPTModel, gpt_data_step
from nemo.lightning import get_vocab_size, io, teardown


def hyena_forward_step(model, batch) -> torch.Tensor:

forward_args = {
Expand Down Expand Up @@ -93,6 +95,11 @@ class HyenaConfig(TransformerConfig, io.IOMixin):
tokenizer_model_path: str = None
hyena_init_method: str = None
hyena_output_layer_init_method: str = None
hyena_filter_no_wd: bool = True

def __post_init__(self):
super().__post_init__()
self.hyena_no_weight_decay_cond_fn = hyena_no_weight_decay_cond if self.hyena_filter_no_wd else None

def configure_model(self, tokenizer) -> "MCoreHyenaModel":
model = MCoreHyenaModel(
Expand Down Expand Up @@ -498,6 +505,7 @@ class HyenaTestConfig(HyenaConfig):
recompute_num_layers: int = 2
hyena_init_method: str = 'small_init'
hyena_output_layer_init_method: str = 'wang_init'
hyena_filter_no_wd: bool = True


@dataclass
Expand Down Expand Up @@ -531,6 +539,7 @@ class Hyena7bConfig(HyenaConfig):
recompute_num_layers: int = 4
hyena_init_method: str = 'small_init'
hyena_output_layer_init_method: str = 'wang_init'
hyena_filter_no_wd: bool = True


__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion tests/collections/llm/gpt/model/test_hyena.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def get_args():
use_distributed_optimizer=True,
bf16=True,
)
opt = MegatronOptimizerModule(config=opt_config)
opt = MegatronOptimizerModule(config=opt_config, no_weight_decay_cond=hyena_config.hyena_no_weight_decay_cond_fn)

trainer = nl.Trainer(
devices=args.devices,
Expand Down
Loading