ViuAI commited on
Commit
a30bdca
·
verified ·
1 Parent(s): 1ad4183

Fix CUDA OOM on T4: cast model to amp_dtype directly, batch_size=2, safe RMSNorm

Browse files
Files changed (1) hide show
  1. model/scripts/viu_moe.py +3 -3
model/scripts/viu_moe.py CHANGED
@@ -316,9 +316,9 @@ class NextGenMoELayer(nn.Module):
316
  rows, cols = torch.where(flat_top_i == ei)
317
  if rows.numel() == 0:
318
  continue
319
- w = flat_top_p[rows, cols].unsqueeze(-1)
320
  y_sel = expert(flat_x[rows])
321
- flat_out.index_add_(0, rows, w * y_sel)
322
 
323
  out = flat_out.view(B, T, D)
324
  out = self.drop(out)
@@ -346,7 +346,7 @@ class ManifoldHyperConnection(nn.Module):
346
  self.gate = nn.Parameter(torch.zeros(2))
347
 
348
  def forward(self, x, fx):
349
- w = F.softmax(self.gate, dim=0) * 2.0
350
  return w[0] * x + w[1] * fx
351
 
352
 
 
316
  rows, cols = torch.where(flat_top_i == ei)
317
  if rows.numel() == 0:
318
  continue
319
+ w = flat_top_p[rows, cols].unsqueeze(-1).to(flat_x.dtype)
320
  y_sel = expert(flat_x[rows])
321
+ flat_out.index_add_(0, rows, (w * y_sel).to(flat_out.dtype))
322
 
323
  out = flat_out.view(B, T, D)
324
  out = self.drop(out)
 
346
  self.gate = nn.Parameter(torch.zeros(2))
347
 
348
  def forward(self, x, fx):
349
+ w = (F.softmax(self.gate, dim=0) * 2.0).to(x.dtype)
350
  return w[0] * x + w[1] * fx
351
 
352