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

Method __init__

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

Source from the content-addressed store, hash-verified

270 used for initialization.
271 """
272 def __init__(self, input_size, output_size, bias=True,
273 input_is_parallel=False,
274 init_method=init.xavier_normal_, stride=1,
275 keep_master_weight_for_test=False):
276 super(RowParallelLinear, self).__init__()
277
278 # Keep input parameters
279 self.input_size = input_size
280 self.output_size = output_size
281 self.input_is_parallel = input_is_parallel
282 # Divide the weight matrix along the last dimension.
283 world_size = get_model_parallel_world_size()
284 self.input_size_per_partition = divide(input_size, world_size)
285
286 # Parameters.
287 # Note: torch.nn.functional.linear performs XA^T + b and as a result
288 # we allocate the transpose.
289 self.weight = Parameter(torch.Tensor(self.output_size,
290 self.input_size_per_partition))
291 self.weight.model_parallel = True
292 if bias:
293 self.bias = Parameter(torch.Tensor(self.output_size))
294 # Always initialize bias to zero.
295 with torch.no_grad():
296 self.bias.zero_()
297 else:
298 self.register_parameter('bias', None)
299
300 # Initialize weight.
301 self.master_weight = _initialize_affine_weight(
302 self.weight, self.output_size, self.input_size,
303 self.input_size_per_partition, 1, init_method,
304 stride=stride, return_master_weight=keep_master_weight_for_test)
305
306 def forward(self, input_):
307 # 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