Implement Straight-Through Estimator for rounding operation.
(x: torch.Tensor)
| 8 | |
| 9 | |
| 10 | def round_ste(x: torch.Tensor): |
| 11 | """ |
| 12 | Implement Straight-Through Estimator for rounding operation. |
| 13 | """ |
| 14 | return (x.round() - x).detach() + x |
| 15 | |
| 16 | def clamp_ste(x: torch.Tensor, min, max): |
| 17 | return (x.clamp(min,max) - x).detach() + x |