forward of Dropout Args: x (CTensor): input tensor. Returns: the output CTensor.
(self, x)
| 3954 | self.init_seed = False |
| 3955 | |
| 3956 | def forward(self, x): |
| 3957 | """ |
| 3958 | forward of Dropout |
| 3959 | Args: |
| 3960 | x (CTensor): input tensor. |
| 3961 | Returns: |
| 3962 | the output CTensor. |
| 3963 | """ |
| 3964 | if not self.init_seed: |
| 3965 | x.device().SetRandSeed(self.seed) |
| 3966 | self.init_seed = True |
| 3967 | if training: |
| 3968 | self.scale = 1 / 1 - self.ratio |
| 3969 | self.mask = singa.Tensor(list(x.shape()), x.device()) |
| 3970 | singa.Bernoulli(1 - self.ratio, self.mask) |
| 3971 | x = singa.MultFloat(singa.__mul__(self.mask, x), self.scale) |
| 3972 | return x |
| 3973 | |
| 3974 | def backward(self, dy): |
| 3975 | """ |
nothing calls this directly
no test coverage detected