MCPcopy Create free account
hub / github.com/THUDM/GLM / __init__

Method __init__

mpu/layers.py:199–231  ·  view source on GitHub ↗
(self, input_size, output_size, bias=True, gather_output=True,
                 init_method=init.xavier_normal_, stride=1,
                 keep_master_weight_for_test=False)

Source from the content-addressed store, hash-verified

197 used for initialization.
198 """
199 def __init__(self, input_size, output_size, bias=True, gather_output=True,
200 init_method=init.xavier_normal_, stride=1,
201 keep_master_weight_for_test=False):
202 super(ColumnParallelLinear, self).__init__()
203
204 # Keep input parameters
205 self.input_size = input_size
206 self.output_size = output_size
207 self.gather_output = gather_output
208 # Divide the weight matrix along the last dimension.
209 world_size = get_model_parallel_world_size()
210 self.output_size_per_partition = divide(output_size, world_size)
211
212 # Parameters.
213 # Note: torch.nn.functional.linear performs XA^T + b and as a result
214 # we allocate the transpose.
215 self.weight = Parameter(torch.Tensor(self.output_size_per_partition,
216 self.input_size))
217 self.weight.model_parallel = True
218 if bias:
219 self.bias = Parameter(torch.Tensor(self.output_size_per_partition))
220 self.bias.model_parallel = True
221 # Always initialize bias to zero.
222 with torch.no_grad():
223 self.bias.zero_()
224 else:
225 self.register_parameter('bias', None)
226
227 # Initialize weight.
228 self.master_weight = _initialize_affine_weight(
229 self.weight, self.output_size, self.input_size,
230 self.output_size_per_partition, 0, init_method,
231 stride=stride, return_master_weight=keep_master_weight_for_test)
232
233 def forward(self, input_):
234 # Set up backprop all-reduce.

Callers

nothing calls this directly

Calls 4

divideFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected