(self, input_size, output_size, bias=True,
input_is_parallel=False,
init_method=init.xavier_normal_, stride=1,
keep_master_weight_for_test=False)
| 276 | used for initialization. |
| 277 | """ |
| 278 | def __init__(self, input_size, output_size, bias=True, |
| 279 | input_is_parallel=False, |
| 280 | init_method=init.xavier_normal_, stride=1, |
| 281 | keep_master_weight_for_test=False): |
| 282 | super(RowParallelLinear, self).__init__() |
| 283 | |
| 284 | # Keep input parameters |
| 285 | self.input_size = input_size |
| 286 | self.output_size = output_size |
| 287 | self.input_is_parallel = input_is_parallel |
| 288 | # Divide the weight matrix along the last dimension. |
| 289 | world_size = get_model_parallel_world_size() |
| 290 | self.input_size_per_partition = divide(input_size, world_size) |
| 291 | |
| 292 | # Parameters. |
| 293 | # Note: torch.nn.functional.linear performs XA^T + b and as a result |
| 294 | # we allocate the transpose. |
| 295 | self.weight = Parameter(torch.Tensor(self.output_size, |
| 296 | self.input_size_per_partition)) |
| 297 | self.weight.model_parallel = True |
| 298 | if bias: |
| 299 | self.bias = Parameter(torch.Tensor(self.output_size)) |
| 300 | # Always initialize bias to zero. |
| 301 | with torch.no_grad(): |
| 302 | self.bias.zero_() |
| 303 | else: |
| 304 | self.register_parameter('bias', None) |
| 305 | |
| 306 | # Initialize weight. |
| 307 | self.master_weight = _initialize_affine_weight( |
| 308 | self.weight, self.output_size, self.input_size, |
| 309 | self.input_size_per_partition, 1, init_method, |
| 310 | stride=stride, return_master_weight=keep_master_weight_for_test) |
| 311 | |
| 312 | def forward(self, input_): |
| 313 | # Set up backprop all-reduce. |
nothing calls this directly
no test coverage detected