-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinitialization_utils.py
More file actions
38 lines (25 loc) · 855 Bytes
/
Copy pathinitialization_utils.py
File metadata and controls
38 lines (25 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import math
import torch
def uniform(size, tensor):
if tensor is not None:
bound = 1.0 / math.sqrt(size)
tensor.data.uniform_(-bound, bound)
def kaiming_uniform(tensor, fan, a):
if tensor is not None:
bound = math.sqrt(6 / ((1 + a**2) * fan))
tensor.data.uniform_(-bound, bound)
def glorot(tensor):
if tensor is not None:
stdv = math.sqrt(6.0 / (tensor.size(-2) + tensor.size(-1)))
tensor.data.uniform_(-stdv, stdv)
def glorot_orthogonal(tensor, scale):
if tensor is not None:
torch.nn.init.orthogonal_(tensor.data)
scale /= ((tensor.size(-2) + tensor.size(-1)) * tensor.var())
tensor.data *= scale.sqrt()
def zeros(tensor):
if tensor is not None:
tensor.data.fill_(0)
def ones(tensor):
if tensor is not None:
tensor.data.fill_(1)