MCPcopy Create free account
hub / github.com/zai-org/CodeGeeX / __init__

Method __init__

codegeex/megatron/mpu/layers.py:264–349  ·  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,
        skip_bias_add=False,
        params_dtype=None,
        skip_init=False,
        device=None,
    )

Source from the content-addressed store, hash-verified

262 """
263
264 def __init__(
265 self,
266 input_size,
267 output_size,
268 bias=True,
269 gather_output=True,
270 init_method=init.xavier_normal_,
271 stride=1,
272 keep_master_weight_for_test=False,
273 skip_bias_add=False,
274 params_dtype=None,
275 skip_init=False,
276 device=None,
277 ):
278 super(ColumnParallelLinear, self).__init__()
279
280 # Keep input parameters
281 self.input_size = input_size
282 self.output_size = output_size
283 self.gather_output = gather_output
284 # Divide the weight matrix along the last dimension.
285 world_size = get_tensor_model_parallel_world_size()
286 self.output_size_per_partition = divide(output_size, world_size)
287 self.skip_bias_add = skip_bias_add
288 self.params_dtype = params_dtype
289 self.device = device
290
291 # Parameters.
292 # Note: torch.nn.functional.linear performs XA^T + b and as a result
293 # we allocate the transpose.
294 # Initialize weight.
295 args = get_args()
296 if not skip_init:
297 if args.use_cpu_initialization:
298 self.weight = Parameter(
299 torch.empty(
300 self.output_size_per_partition,
301 self.input_size,
302 dtype=self.params_dtype if self.params_dtype is not None else args.params_dtype,
303 )
304 )
305 self.master_weight = _initialize_affine_weight_cpu(
306 self.weight,
307 self.output_size,
308 self.input_size,
309 self.output_size_per_partition,
310 0,
311 init_method,
312 stride=stride,
313 return_master_weight=keep_master_weight_for_test,
314 )
315 else:
316 self.weight = Parameter(
317 torch.empty(
318 self.output_size_per_partition,
319 self.input_size,
320 device=self.device if self.device is not None else torch.cuda.current_device(),
321 dtype=self.params_dtype if self.params_dtype is not None else args.params_dtype,

Callers

nothing calls this directly

Calls 7

get_argsFunction · 0.90
divideFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected