(self, input)
| 54 | self._tmp_running_var = self.running_var.clone() * self._running_iter |
| 55 | |
| 56 | def forward(self, input): |
| 57 | # If it is not parallel computation or is in evaluation mode, use PyTorch's implementation. |
| 58 | if not (self._is_parallel and self.training): |
| 59 | return F.batch_norm( |
| 60 | input, self.running_mean, self.running_var, self.weight, self.bias, |
| 61 | self.training, self.momentum, self.eps) |
| 62 | |
| 63 | # Resize the input to (B, C, -1). |
| 64 | input_shape = input.size() |
| 65 | input = input.view(input.size(0), self.num_features, -1) |
| 66 | |
| 67 | # Compute the sum and square-sum. |
| 68 | sum_size = input.size(0) * input.size(2) |
| 69 | input_sum = _sum_ft(input) |
| 70 | input_ssum = _sum_ft(input ** 2) |
| 71 | |
| 72 | # Reduce-and-broadcast the statistics. |
| 73 | if self._parallel_id == 0: |
| 74 | mean, inv_std = self._sync_master.run_master(_ChildMessage(input_sum, input_ssum, sum_size)) |
| 75 | else: |
| 76 | mean, inv_std = self._slave_pipe.run_slave(_ChildMessage(input_sum, input_ssum, sum_size)) |
| 77 | |
| 78 | # Compute the output. |
| 79 | if self.affine: |
| 80 | # MJY:: Fuse the multiplication for speed. |
| 81 | output = (input - _unsqueeze_ft(mean)) * _unsqueeze_ft(inv_std * self.weight) + _unsqueeze_ft(self.bias) |
| 82 | else: |
| 83 | output = (input - _unsqueeze_ft(mean)) * _unsqueeze_ft(inv_std) |
| 84 | |
| 85 | # Reshape it. |
| 86 | return output.view(input_shape) |
| 87 | |
| 88 | def __data_parallel_replicate__(self, ctx, copy_id): |
| 89 | self._is_parallel = True |
nothing calls this directly
no test coverage detected