MCPcopy Create free account
hub / github.com/apache/singa / initialize

Method initialize

python/singa/layer.py:1597–1616  ·  view source on GitHub ↗
(self, x, hx=None, cx=None, seq_lengths=None)

Source from the content-addressed store, hash-verified

1595 self.cudnn_rnn_mode = 3
1596
1597 def initialize(self, x, hx=None, cx=None, seq_lengths=None):
1598 if self.batch_first:
1599 x = x.transpose((1, 0, 2))
1600 self.input_size = x.shape[1]
1601
1602 # GPU handle
1603 self.handle = singa.CudnnRNNHandle(x.data,
1604 self.hidden_size,
1605 mode=self.cudnn_rnn_mode,
1606 num_layers=self.num_layers,
1607 dropout=self.dropout,
1608 bidirectional=self.bidirectional)
1609
1610 self.W = Tensor(shape=(self.handle.weights_size,),
1611 requires_grad=True,
1612 stores_grad=True,
1613 device=x.device)
1614
1615 k = 1 / self.hidden_size
1616 self.W.uniform(-math.sqrt(k), math.sqrt(k))
1617
1618 def forward(self, x, hx=None, cx=None, seq_lengths=None):
1619

Callers

nothing calls this directly

Calls 4

CudnnRNNHandleMethod · 0.80
TensorClass · 0.70
transposeMethod · 0.45
uniformMethod · 0.45

Tested by

no test coverage detected