feat: add axis-aware μP tagger #2
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
to_width,from_width,neutral)megatron_namefor each parameterTesting
python -m py_compile user_hooks/mup_axis_tagger.pyimport torch
from torch import nn
from user_hooks.mup_axis_tagger import tag_axis_aware
class DummyModel(nn.Module):
def init(self, h):
super().init()
self.layernorm = nn.LayerNorm(h)
self.linear_qkv = nn.Linear(h, 3h, bias=False)
self.linear_proj = nn.Linear(3h, h, bias=False)
self.bias = nn.Parameter(torch.zeros(h))
self.embed = nn.Embedding(10, h)
self.out_head = nn.Linear(h, 20, bias=False)
class DummyIO(nn.Module):
def init(self, din, dout):
super().init()
self.weight = nn.Parameter(torch.randn(din, dout))
self.input_size = din
self.output_size = dout
class Wrapper(nn.Module):
def init(self, h):
super().init()
self.model = DummyModel(h)
self.conflict = DummyIO(20, h)
self.linear_proj_conflict = self.conflict # alias to give name pattern
h = 16
model = Wrapper(h)
tag_axis_aware(model, hidden_size=h, base_hidden=h)
for n,p in model.named_parameters():
assert hasattr(p,'mup_role')
assert hasattr(p,'mup_lr_mult')
assert hasattr(p,'mup_init_scale')
assert hasattr(p,'megatron_name')
assert p.megatron_name == n
assert model.model.layernorm.weight.mup_role == 'neutral'
assert model.model.layernorm.bias.mup_role == 'neutral'
assert model.model.bias.mup_role == 'neutral'
assert model.model.embed.weight.mup_role == 'from_width'
assert model.model.linear_qkv.weight.mup_role == 'to_width'
assert model.model.linear_proj.weight.mup_role == 'from_width'
assert model.model.out_head.weight.mup_role == 'from_width'
Axis classification overrides name hint "linear_proj_conflict" -> to_width
assert model.linear_proj_conflict.weight.mup_role == 'to_width'
print('ok')
PY`
https://chatgpt.com/codex/tasks/task_e_689d69cd0c0c8325bf5b5969d1147323