Skip to content

Commit 18eb6cd

Browse files
committed
Update on "redo of add quantized layer norm implementation"
Summary: This is a redo of #35329 with a better test. Adds a quantized implementation of LayerNorm for server. A future PR will add the Python wrapper. Test Plan: numerics match the floating point implementation benchmarks by input size: v1 (mean+var non-vectorized): https://gist.github.com/vkuzo/f6d72c04742608112f4c2e612c74bd13 v2 (mean+var vectorized in float): https://gist.github.com/vkuzo/4dd95657c5b5f3654e0965db00eff8d2 v3 (mean+var vectorized in int, current): https://gist.github.com/vkuzo/57a75f75629da9f23b64b38ca0e3d34b Differential Revision: [D21030268](https://our.internmc.facebook.com/intern/diff/D21030268) [ghstack-poisoned]
1 parent d90dfae commit 18eb6cd

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

test/quantization/test_quantized.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,11 @@ def test_qlayer_norm(self, shapes, torch_type, X_rand_scale, Y_scale, Y_zero_poi
356356
dqX = qX.dequantize()
357357

358358
# Enforce non-homogeneous inputs
359-
nonzero_var_in_each_layer = sum(
360-
1 if ((dqX[i] - dqX[i].min()) / (dqX[i].max() - dqX[i].min() + 1e-5)).std() > 1e-2 else 0
361-
for i in range(dqX.shape[0])
362-
) == dqX.shape[0]
363-
assume(nonzero_var_in_each_layer)
364359
enough_unique_vals_in_each_layer = sum(
365360
1 if (
366361
dqX[i].shape[0] < 5 or
367-
float(torch.unique(dqX[i]).shape[0]) / dqX[i].shape[0] > 0.01) else 0
362+
float(torch.unique(dqX[i]).shape[0]) / dqX[i].shape[0] > 0.01
363+
) else 0
368364
for i in range(dqX.shape[0])
369365
) == dqX.shape[0]
370366
assume(enough_unique_vals_in_each_layer)

0 commit comments

Comments
 (0)