nn.Linear but with normalized fan-in init
(*args, scale=1.0, dtype=th.float32, **kwargs)
| 5 | |
| 6 | |
| 7 | def NormedLinear(*args, scale=1.0, dtype=th.float32, **kwargs): |
| 8 | """ |
| 9 | nn.Linear but with normalized fan-in init |
| 10 | """ |
| 11 | out = nn.Linear(*args, **kwargs) |
| 12 | out.weight.data *= scale / out.weight.norm(dim=1, p=2, keepdim=True) |
| 13 | if kwargs.get("bias", True): |
| 14 | out.bias.data *= 0 |
| 15 | return out |
| 16 | |
| 17 | |
| 18 | def NormedConv2d(*args, scale=1, **kwargs): |