MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / __new__

Method __new__

deepspeed/linear/quantization.py:37–56  ·  view source on GitHub ↗
(
        cls,
        data: Optional[torch.Tensor] = None,
        requires_grad: bool = False,  # quantized weights must be frozen
        quantization_config: QuantizationConfig = None,
        quantizer: Quantizer = None,
    )

Source from the content-addressed store, hash-verified

35 """
36
37 def __new__(
38 cls,
39 data: Optional[torch.Tensor] = None,
40 requires_grad: bool = False, # quantized weights must be frozen
41 quantization_config: QuantizationConfig = None,
42 quantizer: Quantizer = None,
43 ):
44 if requires_grad:
45 raise ValueError("requires_grad=True is not supported with QuantizedParameter")
46 if data is None:
47 data = torch.empty(0)
48 self = torch.Tensor._make_subclass(cls, data, requires_grad)
49 self.quantization_config = QuantizationConfig() if quantization_config is None else quantization_config
50 if quantizer is not None:
51 self.quantizer = quantizer
52 else:
53 # if FPQuantizerBuilder is not compatible in this env this init will fail
54 self.quantizer = FP_Quantize(quantization_config=self.quantization_config)
55 self._ensure_quantized(self)
56 return self
57
58 def _ensure_quantized(self, tensor: torch.Tensor):
59 # If the tensor is on the accelerator and is not quantized, then quantize it in-place.

Callers 2

__deepcopy__Method · 0.45
__copy__Method · 0.45

Calls 3

_ensure_quantizedMethod · 0.95
FP_QuantizeClass · 0.90
QuantizationConfigClass · 0.70

Tested by

no test coverage detected