def test_ane_layer_norm(self, with_affine, constexpr_beta):
        """
        Detect layer norm pattern, found in models based on ml-ane-transformers.

        ``y = (x - mean(x)) * rsqrt(mean((x - mean(x))^2) + eps)``
        ``y = [(x - mean(x)) * rsqrt(mean((x - mean(x))^2) + eps) + beta] * gamma``

        Note that beta and gamma in these equations are applied in
        opposite order compared to the MIL.

        Only applies when mean and variance are computed along axes [1]
        """
        shape = (3, 5, 1, 6)

        @mb.program(input_specs=[mb.TensorSpec(shape=shape)], opset_version=ct.target.iOS16)
        def prog(x):
            x1 = mb.reduce_mean(x=x, axes=[1], keep_dims=True) # mean
            x2 = mb.sub(x=x, y=x1) # x - mean
            x3 = mb.mul(x=x2, y=x2) # (x - mean)^2
            x4 = mb.reduce_mean(x=x3, axes=[1], keep_dims=True) # variance
            x5 = mb.add(x=x4, y=1e-5) # variance + eps
            x6 = mb.rsqrt(x=x5) # rsqrt(variance + eps)
            y = mb.mul(x=x2, y=x6) # (x - mean) * rsqrt(variance + eps)

            if with_affine:
                beta = np.random.rand(1, shape[1], 1, 1)
                if constexpr_beta:
                    beta = mb.constexpr_lut_to_dense(
                        lut=np.arange(2, dtype=np.float32),
                        indices=np.ones((int(np.ceil(np.prod(beta.shape) / 8)),), dtype=np.uint8),
                        shape=np.array(beta.shape, dtype=np.uint32),
                    )
                y = mb.add(x=y, y=beta)
                y = mb.mul(x=y, y=np.random.rand(1, shape[1], 1, 1))

            return y

        prev_prog, prev_block, block = apply_pass_and_basic_check(
            prog, "common::fuse_layernorm_or_instancenorm"
        )
        prev_expected_ops = [
            "reduce_mean",
            "sub",
            "mul",
            "reduce_mean",
            "add",
            "rsqrt",
            "mul",
        ]
        if with_affine:
            if constexpr_beta:
                prev_expected_ops.append("constexpr_lut_to_dense")
            prev_expected_ops += ["add", "mul"]

        assert get_op_types_in_program(prev_prog) == prev_expected_ops
        if with_affine and constexpr_beta:
            assert get_op_types_in_program(prog) == get_op_types_in_program(prev_prog)
        else:
            assert get_op_types_in_program(prog) == ["layer_norm"]
        assert_model_is_valid(
            prog,
            {"x": shape},
            expected_output_shapes={block.outputs[0].name: shape},
            minimum_deployment_target=ct.target.iOS16,
        )

        Detect layer norm pattern, found in models based on ml-ane-transformers.

        ``y = (x - mean(x)) * rsqrt(mean((x - mean(x))^2) + eps)``
        ``y = [(x - mean(x)) * rsqrt(mean((x - mean(x))^2) + eps) + beta] * gamma``

        Note that beta and gamma in these equations are applied in
        opposite order compared to the MIL.

        Only applies when mean and variance are computed along axes [1]
        
coremltools/converters/mil/mil/passes/tests/test_passes.py