Skip to contents

y = s clip(round(x/s)); the straight-through estimator passes the gradient in range and kills it where clipped.

Usage

morie_geron_quantization_aware_training(x, s, bits = 8, upstream_grad = NULL)

Arguments

x

Numeric object.

s

Positive step size.

bits

Width in [2, 32].

upstream_grad

Optional gradient of the same shape.

Value

List with y, q, ste_mask, grad_x, clipped_fraction.

Examples

morie_geron_quantization_aware_training(x = c(1, 2, 3, 4, 5, 6, 7, 8), s = 5L)
#> $y
#> [1]  0  0  5  5  5  5  5 10
#> 
#> $q
#> [1] 0 0 1 1 1 1 1 2
#> 
#> $ste_mask
#> [1] 1 1 1 1 1 1 1 1
#> 
#> $grad_x
#> [1] 1 1 1 1 1 1 1 1
#> 
#> $clipped_fraction
#> [1] 0
#> 
#> $estimate
#> [1]  0  0  5  5  5  5  5 10
#> 
#> $n
#> [1] 8
#>