(tensor: Tensor, min, max)
| 30 | |
| 31 | |
| 32 | def 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 | |
| 40 | def tensor_round(tensor: Tensor) -> Tensor: |