| 24 | |
| 25 | |
| 26 | def _layer_norm(x, normalized_shape, weight=None, bias=None, eps=1e-6): |
| 27 | begin_norm_axis = len(x.shape) - len(normalized_shape) |
| 28 | begin_params_axis = len(x.shape) - len(normalized_shape) |
| 29 | |
| 30 | if weight is not None and bias is not None: |
| 31 | return flow._C.layer_norm_affine( |
| 32 | x, |
| 33 | weight, |
| 34 | bias, |
| 35 | begin_norm_axis=begin_norm_axis, |
| 36 | begin_params_axis=begin_params_axis, |
| 37 | epsilon=eps, |
| 38 | ) |
| 39 | else: |
| 40 | return flow._C.layer_norm( |
| 41 | x, |
| 42 | begin_norm_axis=begin_norm_axis, |
| 43 | begin_params_axis=begin_params_axis, |
| 44 | epsilon=eps, |
| 45 | ) |
| 46 | |
| 47 | |
| 48 | def _test_layer_norm( |