| 79 | |
| 80 | |
| 81 | class TruncateFunction(torch.autograd.Function): |
| 82 | @staticmethod |
| 83 | def forward(ctx, input, threshold): |
| 84 | truncated_tensor = input.clone() |
| 85 | truncated_tensor[truncated_tensor.abs() < threshold] = truncated_tensor[truncated_tensor.abs() < threshold].sign() * threshold |
| 86 | return truncated_tensor |
| 87 | |
| 88 | |
| 89 | @staticmethod |
| 90 | def backward(ctx, grad_output): |
| 91 | grad_input = grad_output.clone() |
| 92 | return grad_input, None |
| 93 | |
| 94 | |
| 95 | def truncate_number(number, threshold=1e-2): |
nothing calls this directly
no outgoing calls
no test coverage detected