Skip to content

Commit 7315e3a

Browse files
fix!: cond layer norm (#658)
Fix name of config param and doc string <!-- readthedocs-preview anemoi-training start --> ---- πŸ“š Documentation preview πŸ“š: https://anemoi-training--658.org.readthedocs.build/en/658/ <!-- readthedocs-preview anemoi-training end --> <!-- readthedocs-preview anemoi-graphs start --> ---- πŸ“š Documentation preview πŸ“š: https://anemoi-graphs--658.org.readthedocs.build/en/658/ <!-- readthedocs-preview anemoi-graphs end --> <!-- readthedocs-preview anemoi-models start --> ---- πŸ“š Documentation preview πŸ“š: https://anemoi-models--658.org.readthedocs.build/en/658/ <!-- readthedocs-preview anemoi-models end --> --------- Co-authored-by: Ana Prieto Nemesio <[email protected]>
1 parent 66b40e0 commit 7315e3a

File tree

9 files changed

+31
-16
lines changed

9 files changed

+31
-16
lines changed

β€Žmodels/src/anemoi/models/layers/normalization.pyβ€Ž

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,31 @@ def __init__(
4242
self,
4343
normalized_shape: Union[int, list, Size],
4444
condition_shape: int = 16,
45-
w_one_bias_zero_init: bool = True,
45+
zero_init: bool = True,
4646
autocast: bool = True,
47-
):
47+
) -> None:
48+
"""Initialize Conditional Layer Normalization.
49+
50+
Parameters
51+
----------
52+
normalized_shape : Union[int, list, Size]
53+
Shape or dimension(s) over which to normalize.
54+
condition_shape : int, optional
55+
Dimension of the conditioning vector, by default 16.
56+
zero_init : bool, optional
57+
If True, initializes the scale and bias transformation weights to zeros.
58+
This means the conditional normalization behaves like standard layer
59+
normalization initially, by default True.
60+
autocast : bool, optional
61+
If True, automatically cast output to match input dtype, by default True.
62+
"""
4863
super().__init__()
4964
self.norm = nn.LayerNorm(normalized_shape, elementwise_affine=False) # no learnable parameters
5065
self.scale = nn.Linear(condition_shape, normalized_shape) # , bias=False)
5166
self.bias = nn.Linear(condition_shape, normalized_shape) # , bias=False)
5267
self.autocast = autocast
5368

54-
if w_one_bias_zero_init:
69+
if zero_init:
5570
nn.init.zeros_(self.scale.weight)
5671
nn.init.zeros_(self.scale.bias)
5772
nn.init.zeros_(self.bias.weight)
@@ -62,15 +77,15 @@ def forward(self, x: Tensor, cond: Tensor) -> Tensor:
6277
6378
Parameters
6479
----------
65-
input : List[Tensor, Tensor]
66-
A list of two tensors (x, cond),
67-
the first is the input tensor and
68-
the second is the condition tensor.
80+
x : Tensor
81+
Input tensor to be normalized.
82+
cond : Tensor
83+
Conditioning tensor used to modulate the normalization.
6984
7085
Returns
7186
-------
7287
Tensor
73-
The output tensor.
88+
Output tensor.
7489
"""
7590
scale = self.scale(cond)
7691
bias = self.bias(cond)

β€Žtraining/docs/user-guide/diffusion-set-up.rstβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The diffusion configuration includes:
8787
_target_: anemoi.models.layers.normalization.ConditionalLayerNorm
8888
normalized_shape: ${model.num_channels}
8989
condition_shape: 16
90-
w_one_bias_zero_init: True
90+
zero_init: True
9191
autocast: false
9292
9393
The diffusion model uses conditional layer normalization to condition

β€Žtraining/docs/user-guide/kcrps-set-up.rstβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ conditional layer norm.
113113
_target_: anemoi.models.layers.normalization.ConditionalLayerNorm
114114
normalized_shape: ${model.num_channels}
115115
condition_shape: ${model.noise_injector.noise_channels_dim}
116-
w_one_bias_zero_init: True
116+
zero_init: True
117117
autocast: false
118118
...
119119

β€Žtraining/src/anemoi/training/config/model/graphtransformer_diffusion.yamlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ layer_kernels:
3737
_target_: anemoi.models.layers.normalization.ConditionalLayerNorm
3838
normalized_shape: ${model.num_channels}
3939
condition_shape: 16
40-
w_one_bias_zero_init: True
40+
zero_init: True
4141
autocast: false
4242
Linear:
4343
_target_: torch.nn.Linear

β€Žtraining/src/anemoi/training/config/model/graphtransformer_diffusiontend.yamlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ layer_kernels:
3737
_target_: anemoi.models.layers.normalization.ConditionalLayerNorm
3838
normalized_shape: ${model.num_channels}
3939
condition_shape: 16
40-
w_one_bias_zero_init: True
40+
zero_init: True
4141
autocast: false
4242
Linear:
4343
_target_: torch.nn.Linear

β€Žtraining/src/anemoi/training/config/model/graphtransformer_ens.yamlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ processor:
4848
_target_: anemoi.models.layers.normalization.ConditionalLayerNorm
4949
normalized_shape: ${model.num_channels}
5050
condition_shape: ${model.noise_injector.noise_channels_dim}
51-
w_one_bias_zero_init: True
51+
zero_init: True
5252
autocast: false
5353
#Any arguments to your chosen function go here
5454
Linear:

β€Žtraining/src/anemoi/training/config/model/transformer_diffusion.yamlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ layer_kernels:
3737
_target_: anemoi.models.layers.normalization.ConditionalLayerNorm
3838
normalized_shape: ${model.num_channels}
3939
condition_shape: 16
40-
w_one_bias_zero_init: True
40+
zero_init: True
4141
autocast: false
4242
Linear:
4343
_target_: torch.nn.Linear

β€Žtraining/src/anemoi/training/config/model/transformer_diffusiontend.yamlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ layer_kernels:
3737
_target_: anemoi.models.layers.normalization.ConditionalLayerNorm
3838
normalized_shape: ${model.num_channels}
3939
condition_shape: 16
40-
w_one_bias_zero_init: True
40+
zero_init: True
4141
autocast: false
4242
Linear:
4343
_target_: torch.nn.Linear

β€Žtraining/src/anemoi/training/config/model/transformer_ens.yamlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ processor:
5050
_target_: anemoi.models.layers.normalization.ConditionalLayerNorm
5151
normalized_shape: ${model.num_channels}
5252
condition_shape: ${model.noise_injector.noise_channels_dim}
53-
w_one_bias_zero_init: True
53+
zero_init: True
5454
autocast: false
5555
#Any arguments to your chosen function go here
5656
Linear:

0 commit comments

Comments
Β (0)