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

Function tensor_clamp

deepspeed/inference/quantization/utils.py:32–37  ·  view source on GitHub ↗
(tensor: Tensor, min, max)

Source from the content-addressed store, hash-verified

30
31
32def tensor_clamp(tensor: Tensor, min, max) -> Tensor:
33 if tensor.device.type == 'cpu' and tensor.dtype == torch.float16:
34 # CPU does not support FP16 clamp
35 return tensor.to(dtype=torch.float32).clamp_(min, max).to(dtype=torch.float16)
36 else:
37 return tensor.clamp_(min, max)
38
39
40def tensor_round(tensor: Tensor) -> Tensor:

Callers 1

_quantize_int8Method · 0.85

Calls 1

toMethod · 0.45

Tested by

no test coverage detected