-
Notifications
You must be signed in to change notification settings - Fork 29
Add mish dsilu and activation yaml sweep #789
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # all_activations_default_inf.yaml | ||
| # Based on explorations/default_inf.yaml, but sweeps MLP activation variants. | ||
| --- | ||
|
|
||
| named_static_groups: | ||
| # QK Norm | ||
| - named_group: "qk_norm" | ||
| use_qk_norm: [true] | ||
| use_qk_norm_scale: [true] | ||
|
|
||
| # Norm Type | ||
| - named_group: "peri_ln" | ||
| use_pre_ln: [true] | ||
| use_peri_ln: [true] | ||
| use_post_ln: [false] | ||
|
|
||
| # Position Embeddings | ||
| - named_group: "rotary" | ||
| use_rotary_embeddings: [true] | ||
| use_abs_pos_embeddings: [false] | ||
|
|
||
| # Attention Softmax | ||
| - named_group: "softmax" | ||
| softmax_variant_attn: ["softmax"] | ||
|
|
||
| # Infinite Attention | ||
| - named_group: "infinite" | ||
| attention_variant: ["infinite"] | ||
| use_concat_heads: [true] | ||
|
|
||
| # MQA | ||
| - named_group: "mqa" | ||
| n_kv_group: [1] | ||
|
|
||
| # Head Dimension | ||
| - named_group: "hd_100" | ||
| n_qk_head_dim: [100] | ||
| n_v_head_dim: [100] | ||
|
|
||
| common_group: | ||
| dataset: ["minipile"] | ||
| eval_interval: [2500] | ||
| max_iters: [10000] | ||
| never_save_checkpoint: [true] | ||
| compile: [true] | ||
| log_rankme: [true] | ||
| log_areq: [true] | ||
|
|
||
| # Parameters needed by activation implementations that read config fields directly. | ||
| relu_power: [2.0] | ||
| shifted_gelu_learnable_shift: [true] | ||
| shifted_gelu_initial_shift: [0.0] | ||
| softshrink_lambda: [0.5] | ||
| pla_num_points: [7] | ||
| pla_left_bound: [-2.0] | ||
| pla_right_bound: [2.0] | ||
| pfla_num_points: [50] | ||
| pfla_left_bound: [-10.0] | ||
| pfla_right_bound: [10.0] | ||
| lsa_num_knots: [30] | ||
|
|
||
| parameter_groups: | ||
| - named_group_static: | ||
| - "qk_norm" | ||
| - "peri_ln" | ||
| - "rotary" | ||
| - "softmax" | ||
| - "infinite" | ||
| - "mqa" | ||
| - "hd_100" | ||
| activation_variant: | ||
| - "celu" | ||
| - "elu" | ||
| - "gelu" | ||
| - "gelu_shifted" | ||
| - "glu" | ||
| - "leaky_relu" | ||
| - "learned_spline" | ||
| - "mish" | ||
| - "mish_custom" | ||
| - "piecewise" | ||
| - "pfla" | ||
| - "pfla_le" | ||
| - "prelu" | ||
| - "relu" | ||
| - "relu_power" | ||
| - "relu6" | ||
| - "rrelu" | ||
| - "disco" | ||
| - "selu" | ||
| - "sigmoid" | ||
| - "silu" | ||
| - "dsilu" | ||
| - "softplus" | ||
| - "softsign" | ||
| - "softshrink" | ||
| - "squared_relu" | ||
| - "squared_gelu" | ||
| - "tanh" | ||
| - "identity" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,29 @@ def forward(self, x): | |
| # Apply the shifted GELU activation | ||
| return self.gelu(x - self.shift) | ||
|
|
||
| class dSiLU(nn.Module): | ||
| """ | ||
| Derivative of SiLU: | ||
| d/dx[x * sigmoid(x)] = sigmoid(x) * (1 + x * (1 - sigmoid(x))) | ||
| """ | ||
| def __init__(self, config): | ||
| super().__init__() | ||
|
|
||
| def forward(self, x): | ||
| sig = torch.sigmoid(x) | ||
| return sig * (1 + x * (1 - sig)) | ||
|
|
||
|
|
||
| class Mish(nn.Module): | ||
| """ | ||
| Mish activation: x * tanh(softplus(x)). | ||
| """ | ||
| def __init__(self, config): | ||
| super().__init__() | ||
|
|
||
| def forward(self, x): | ||
| return x * torch.tanh(torch.nn.functional.softplus(x)) | ||
|
Comment on lines
+67
to
+75
|
||
|
|
||
|
|
||
| class PiecewiseLearnableActivation(nn.Module): | ||
| def __init__(self, config): | ||
|
|
@@ -349,6 +372,7 @@ def __init__(self, config=None): | |
| "glu": GLU_Config, | ||
| "leaky_relu": LeakyReLU_Config, | ||
| "mish": Mish_Config, | ||
| "mish_custom": Mish, | ||
| "piecewise": PiecewiseLearnableActivation, | ||
| "pfla": PiecewiseFullyLearnableActivation, | ||
| "pfla_le": PiecewiseFullyLearnableActivationLearnedEnds, | ||
|
|
@@ -361,6 +385,7 @@ def __init__(self, config=None): | |
| "selu": SELU_Config, | ||
| "sigmoid": Sigmoid_Config, | ||
| "silu": SiLU_Config, | ||
| "dsilu": dSiLU, | ||
| "softplus": Softplus_Config, | ||
|
Comment on lines
372
to
389
|
||
| "softsign": Softsign_Config, | ||
| "softshrink": Softshrink_Config, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class name
dSiLUstarts with a lowercase letter, which is inconsistent with the other activation modules in this file (e.g.,SquaredReLU,GELUShifted) and with typical CapWords class naming. Renaming toDSiLUwould improve readability and consistency (the registry key can remain"dsilu").