(self, input_size, output_size, bias=True, gather_output=True,
init_method=unscaled_init_method(0.02), stride=1,
keep_master_weight_for_test=False, params_dtype=torch.float, module=None, name=None, skip_init=False, device=torch.device('cpu'))
| 188 | used for initialization. |
| 189 | """ |
| 190 | def __init__(self, input_size, output_size, bias=True, gather_output=True, |
| 191 | init_method=unscaled_init_method(0.02), stride=1, |
| 192 | keep_master_weight_for_test=False, params_dtype=torch.float, module=None, name=None, skip_init=False, device=torch.device('cpu')): |
| 193 | super(ColumnParallelLinear, self).__init__() |
| 194 | |
| 195 | # Keep input parameters |
| 196 | self.stride = stride |
| 197 | self.input_size = input_size |
| 198 | self.output_size = output_size |
| 199 | self.gather_output = gather_output |
| 200 | # Divide the weight matrix along the last dimension. |
| 201 | world_size = get_model_parallel_world_size() |
| 202 | self.output_size_per_partition = divide(output_size, world_size) |
| 203 | |
| 204 | # Parameters. |
| 205 | # Note: torch.nn.functional.linear performs XA^T + b and as a result |
| 206 | # we allocate the transpose. |
| 207 | self.weight = Parameter(torch.empty(self.output_size_per_partition, |
| 208 | self.input_size, dtype=params_dtype, |
| 209 | device=device)) |
| 210 | self.weight.model_parallel = True |
| 211 | if bias: |
| 212 | self.bias = Parameter(torch.empty(self.output_size_per_partition,dtype=params_dtype, device=device)) |
| 213 | self.bias.model_parallel = True |
| 214 | # Always initialize bias to zero. |
| 215 | with torch.no_grad(): |
| 216 | self.bias.zero_() |
| 217 | else: |
| 218 | self.register_parameter('bias', None) |
| 219 | |
| 220 | # Initialize weight. |
| 221 | if not skip_init: |
| 222 | self.master_weight = _initialize_affine_weight( |
| 223 | self.weight, self.output_size, self.input_size, |
| 224 | self.output_size_per_partition, 0, init_method, |
| 225 | stride=self.stride, return_master_weight=keep_master_weight_for_test, module=module, name=name, self=self) |
| 226 | |
| 227 | def forward(self, input_): |
| 228 | # Set up backprop all-reduce, and don't change the input. |
nothing calls this directly
no test coverage detected