Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
duplicate line and positions as buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
sahahner committed Dec 5, 2024
1 parent bbba4f6 commit 89e88b4
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/anemoi/models/layers/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ def __init__(

self.layer_norm1 = nn.LayerNorm(num_channels)

self.grid_lat_coslon_sinlon = grid_lat_coslon_sinlon
self.register_buffer("grid_lat_coslon_sinlon", grid_lat_coslon_sinlon)
if self.grid_lat_coslon_sinlon is not None:
self.grid_lat_coslon_sinlon = self.grid_lat_coslon_sinlon
self.pos_embedder = nn.Linear(3, num_channels) # assuming that we have 3 position features, lat and cos / sin of lon

self.attention = MultiHeadSelfAttention(
Expand All @@ -106,7 +105,7 @@ def forward(
self, x: Tensor, shapes: list, batch_size: int, model_comm_group: Optional[ProcessGroup] = None
) -> Tensor:
if self.grid_lat_coslon_sinlon is not None:
pos_embedding = self.pos_embedder(self.grid_lat_coslon_sinlon.to(x.device))
pos_embedding = self.pos_embedder(self.grid_lat_coslon_sinlon)
pos_embedding = pos_embedding.repeat(batch_size, 1)
x = x + pos_embedding

Expand Down

0 comments on commit 89e88b4

Please sign in to comment.