forked from mrq/DL-Art-School
Attempt to fix nan
This commit is contained in:
parent
eda796985b
commit
1c574c5bd1
|
@ -158,6 +158,7 @@ class DropoutNorm(SwitchNorm):
|
||||||
|
|
||||||
# Compute the dropout probabilities. This module is a no-op before the accumulator is initialized.
|
# Compute the dropout probabilities. This module is a no-op before the accumulator is initialized.
|
||||||
if self.accumulator_filled > 0:
|
if self.accumulator_filled > 0:
|
||||||
|
with torch.no_grad():
|
||||||
probs = torch.mean(self.accumulator, dim=0) * self.dropout_rate
|
probs = torch.mean(self.accumulator, dim=0) * self.dropout_rate
|
||||||
bs, br = x.shape[:2]
|
bs, br = x.shape[:2]
|
||||||
drop = torch.rand((bs, br), device=x.device) > probs.unsqueeze(0)
|
drop = torch.rand((bs, br), device=x.device) > probs.unsqueeze(0)
|
||||||
|
@ -172,7 +173,7 @@ class DropoutNorm(SwitchNorm):
|
||||||
class HardRoutingGate(nn.Module):
|
class HardRoutingGate(nn.Module):
|
||||||
def __init__(self, breadth, dropout_rate=.8):
|
def __init__(self, breadth, dropout_rate=.8):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.norm = DropoutNorm(breadth, dropout_rate, accumulator_size=2)
|
self.norm = DropoutNorm(breadth, dropout_rate, accumulator_size=128)
|
||||||
|
|
||||||
def forward(self, x):
|
def forward(self, x):
|
||||||
soft = self.norm(nn.functional.softmax(x, dim=1))
|
soft = self.norm(nn.functional.softmax(x, dim=1))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user