Skip to content
Closed
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
17 changes: 5 additions & 12 deletions makani/models/networks/fourcastnet3.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ def _compute_cutoff_radius(nlat, kernel_shape, basis_type):
# commenting out torch.compile due to long intiial compile times
# @torch.compile
def _soft_clamp(x: torch.Tensor, offset: float = 0.0):
xtype = x.dtype
x = x + offset
y = torch.where(x > 0.0, x**2, 0.0)
y = torch.where(x >= 0.5, x - 0.25, y)
y = torch.where(x >= 0.5, x - 0.25, y).to(dtype=xtype)
return y


Expand Down Expand Up @@ -120,12 +121,8 @@ def __init__(
)

def forward(self, x):
dtype = x.dtype

with amp.autocast(device_type="cuda", enabled=False):
x = x.float()
x = self.conv(x)
x = x.to(dtype=dtype)
x = self.conv(x)

if hasattr(self, "act"):
x = self.act(x)
Expand Down Expand Up @@ -213,19 +210,15 @@ def __init__(
self.conv.bias.sharded_dims_mp = [None]

def forward(self, x):
dtype = x.dtype

if hasattr(self, "act"):
x = self.act(x)

if hasattr(self, "mlp"):
x = self.mlp(x)

with amp.autocast(device_type="cuda", enabled=False):
x = x.float()
x = self.upsample(x)
x = self.conv(x)
x = x.to(dtype=dtype)
x = self.upsample(x)
x = self.conv(x)

return x

Expand Down