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

Function tensor_clamp

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

Source from the content-addressed store, hash-verified

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

Callers 1

_quantize_int8Method · 0.85

Calls 1

toMethod · 0.45

Tested by

no test coverage detected