(x, k)
| 10 | Return the three quantization functions fw, fa, fg, for weights, activations and gradients respectively |
| 11 | """ |
| 12 | def quantize(x, k): |
| 13 | n = float(2 ** k - 1) |
| 14 | |
| 15 | @tf.custom_gradient |
| 16 | def _quantize(x): |
| 17 | return tf.round(x * n) / n, lambda dy: dy |
| 18 | |
| 19 | return _quantize(x) |
| 20 | |
| 21 | def fw(x): |
| 22 | if bitW == 32: |