MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / forward

Method forward

deepspeed/compression/basic_layer.py:364–401  ·  view source on GitHub ↗
(self, input, skip_bias_add=False)

Source from the content-addressed store, hash-verified

362 return (w.t().reshape(self.num_heads, -1) * mask.view(-1, 1)).reshape(shape[1], shape[0]).t()
363
364 def forward(self, input, skip_bias_add=False):
365
366 if self.weight_quantization_enabled_in_forward and self.weight_quantization_enabled:
367 weight = self.weight_quantizer(self.weight, self.weight.target_bits, None, None,
368 self.weight_quantize_num_groups)
369 bias = self.bias
370 else:
371 weight = self.weight
372 bias = self.bias
373
374 if self.sparse_pruning_enabled and self.sparse_pruning_method:
375 mask = self.get_mask(pruning_type='sparse')
376 weight = weight * mask.view(self.weight.size())
377
378 if self.row_pruning_enabled and self.row_pruning_method:
379 mask = self.get_mask(pruning_type='row')
380 weight = weight * mask.view(-1, 1)
381 if bias is not None:
382 bias = bias * mask.view(-1)
383
384 if self.head_pruning_enabled and self.head_pruning_method:
385 mask = self.get_mask(pruning_type='head')
386 weight = self.head_pruning_reshape(weight, mask)
387
388 if self.activation_quantization_enabled:
389 if 'dynamic' in self.activation_quantization_method:
390 num_groups = input.numel() // input.size(-1)
391 else:
392 num_groups = 1
393 input = self.activation_quantizer(input, self.activation_quantization_bits, None, None, num_groups)
394
395 if skip_bias_add:
396 # used for mpu linear layers
397 output = nn.functional.linear(input, weight, None)
398 return output, bias
399 else:
400 output = nn.functional.linear(input, weight, bias)
401 return output
402
403
404class Conv2dLayer_Compress(nn.Conv2d):

Callers

nothing calls this directly

Calls 4

get_maskMethod · 0.95
head_pruning_reshapeMethod · 0.95
numelMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected