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

        Cover cases where the input to the layer norm is used as input to an
        op that occurs after the layer norm.

        ``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)])
        def prog(x):
            x1 = mb.add(x=x, y=np.random.rand(*shape))
            x2 = mb.reduce_mean(x=x1, axes=[1], keep_dims=True) # mean
            x3 = mb.sub(x=x1, y=x2) # x - mean
            x4 = mb.mul(x=x3, y=x3) # (x - mean)^2
            x5 = mb.reduce_mean(x=x4, axes=[1], keep_dims=True) # variance
            x6 = mb.add(x=x5, y=1e-5) # variance + eps
            x7 = mb.rsqrt(x=x6) # rsqrt(variance + eps)
            y = mb.mul(x=x3, y=x7) # (x - mean) * rsqrt(variance + eps)

            if with_affine:
                y = mb.add(x=y, y=np.random.rand(1, shape[1], 1, 1))
                y = mb.mul(x=y, y=np.random.rand(1, shape[1], 1, 1))

            y = mb.sub(x=x, y=y) # use x for something after the norm
            return y

        prev_prog, prev_block, block = apply_pass_and_basic_check(
            prog, "common::fuse_layernorm_or_instancenorm"
        )
        assert get_op_types_in_program(prev_prog) == [
            "add",
            "reduce_mean",
            "sub",
            "mul",
            "reduce_mean",
            "add",
            "rsqrt",
            "mul",
        ] + (["add", "mul"] if with_affine else []) + ["sub"]
        assert get_op_types_in_program(prog) == ["add", "layer_norm", "sub"]
        assert_model_is_valid(
            prog, {"x": shape}, expected_output_shapes={block.outputs[0].name: shape}
        )

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

        Cover cases where the input to the layer norm is used as input to an
        op that occurs after the layer norm.

        ``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