```python
import torch
import torch.nn as nn
from torch.utils.cpp_extension import load_inline


_cpp_source = r"""
#include <torch/extension.h>

torch::Tensor norm_residual_mul_cuda(
    torch::Tensor x, torch::Tensor y, double eps);
"""

_cuda_source = r"""
#include <torch/extension.h>
#include <ATen/cuda/CUDAContext.h>
#include <c10/cuda/CUDAGuard.h>
#include <c10/cuda/CUDAException.h>
#include <cuda_runtime.h>

__device__ __forceinline__ float block_sum(float value, float* shared) {
    const int lane = threadIdx.x & 31;
    const int warp = threadIdx.x >> 5;

    #pragma unroll
    for (int offset = 16; offset > 0; offset >>= 1)
        value += __shfl_down_sync(0xffffffff, value, offset);

    if (lane == 0)
        shared[warp] = value;

    __syncthreads();

    if (warp == 0) {
        value = lane < 8 ? shared[lane] : 0.0f;
        #pragma unroll
        for (int offset = 16; offset > 0; offset >>= 1)
            value += __shfl_down_sync(0xffffffff, value, offset);

        if (lane == 0)
            shared[0] = value;
    }

    __syncthreads();
    return shared[0];
}

__global__ void fused_8192(
    const float* __restrict__ x,
    const float* __restrict__ y,
    float* __restrict__ output,
    float eps
) {
    __shared__ float mean_shared[8];
    __shared__ float variance_shared[8];

    const int tid = threadIdx.x;
    const int64_t base = static_cast<int64_t>(blockIdx.x) * 8192;

    const float4* row_x = reinterpret_cast<const float4*>(x + base);
    const float4* row_y = reinterpret_cast<const float4*>(y + base);
    float4* row_out = reinterpret_cast<float4*>(output + base);

    float4 values[8];
    float sum = 0.0f;

    #pragma unroll
    for (int i = 0; i < 8; ++i) {
        const float4 v = row_x[tid + i * 256];
        values[i] = v;
        sum += (v.x + v.y) + (v.z + v.w);
    }

    const float mean = block_sum(sum, mean_shared) * (1.0f / 8192.0f);
    float variance_sum = 0.0f;

    #pragma unroll
    for (int i = 0; i < 8; ++i) {
        float4 v = values[i];
        v.x -= mean;
        v.y -= mean;
        v.z -= mean;
        v.w -= mean;
        values[i] = v;
        variance_sum +=
            (v.x * v.x + v.y * v.y) + (v.z * v.z + v.w * v.w);
    }

    const float inv_std = rsqrtf(
        block_sum(variance_sum, variance_shared) *
        (1.0f / 8192.0f) + eps);

    #pragma unroll
    for (int i = 0; i < 8; ++i) {
        const int index = tid + i * 256;
        const float4 residual = row_y[index];
        const float4 v = values[i];

        row_out[index] = make_float4(
            (v.x * inv_std + residual.x) * residual.x,
            (v.y * inv_std + residual.y) * residual.y,
            (v.z * inv_std + residual.z) * residual.z,
            (v.w * inv_std + residual.w) * residual.w
        );
    }
}

__global__ void fused_generic(
    const float* __restrict__ x,
    const float* __restrict__ y,
    float* __restrict__ output,
    int64_t width,
    float eps
) {
    __shared__ float mean_shared[8];
    __shared__ float variance_shared[8];

    const int64_t base = static_cast<int64_t>(blockIdx.x) * width;
    float sum = 0.0f;

    for (int64_t i = threadIdx.x; i < width; i += blockDim.x)
        sum += x[base + i];

    const float mean = block_sum(sum, mean_shared) / float(width);
    float variance_sum = 0.0f;

    for (int64_t i = threadIdx.x; i < width; i += blockDim.x) {
        const float centered = x[base + i] - mean;
        variance_sum += centered * centered;
    }

    const float inv_std = rsqrtf(
        block_sum(variance_sum, variance_shared) / float(width) + eps);

    for (int64_t i = threadIdx.x; i < width; i += blockDim.x) {
        const float residual = y[base + i];
        output[base + i] =
            ((x[base + i] - mean) * inv_std + residual) * residual;
    }
}

torch::Tensor norm_residual_mul_cuda(
    torch::Tensor x, torch::Tensor y, double eps
) {
    TORCH_CHECK(x.is_cuda() && y.is_cuda(), "Inputs must be CUDA tensors");
    TORCH_CHECK(x.device() == y.device(), "Inputs must use the same device");
    TORCH_CHECK(
        x.scalar_type() == at::kFloat && y.scalar_type() == at::kFloat,
        "Inputs must have float32 dtype");
    TORCH_CHECK(x.is_contiguous() && y.is_contiguous(),
                "Inputs must be contiguous");
    TORCH_CHECK(x.dim() == 2 && x.sizes() == y.sizes(),
                "Inputs must have matching two-dimensional shapes");
    TORCH_CHECK(x.size(1) > 1, "Normalization requires more than one element");

    const c10::cuda::CUDAGuard guard(x.device());
    auto output = torch::empty_like(x);

    if (x.size(0) == 0)
        return output;

    const auto stream = at::cuda::getCurrentCUDAStream();
    const dim3 grid(static_cast<unsigned int>(x.size(0)));

    const bool aligned =
        (reinterpret_cast<uintptr_t>(x.data_ptr<float>()) % 16 == 0) &&
        (reinterpret_cast<uintptr_t>(y.data_ptr<float>()) % 16 == 0);

    if (x.size(1) == 8192 && aligned) {
        fused_8192<<<grid, 256, 0, stream>>>(
            x.data_ptr<float>(), y.data_ptr<float>(),
            output.data_ptr<float>(), static_cast<float>(eps));
    } else {
        fused_generic<<<grid, 256, 0, stream>>>(
            x.data_ptr<float>(), y.data_ptr<float>(),
            output.data_ptr<float>(), x.size(1), static_cast<float>(eps));
    }

    C10_CUDA_KERNEL_LAUNCH_CHECK();
    return output;
}
"""

_fused_ops = load_inline(
    name="instance_norm_residual_mul_fused",
    cpp_sources=_cpp_source,
    cuda_sources=_cuda_source,
    functions=["norm_residual_mul_cuda"],
    extra_cflags=["-O3"],
    extra_cuda_cflags=["-O3", "--fmad=false"],
    verbose=False,
)


class ModelNew(nn.Module):
    def __init__(self, in_features, out_features, eps=1e-5, momentum=0.1):
        super().__init__()
        self.bmm = nn.Linear(in_features, out_features)
        self.instance_norm = nn.InstanceNorm2d(
            out_features, eps=eps, momentum=momentum
        )

    def forward(self, x, y):
        x = self.bmm(x)

        if (
            x.is_cuda
            and y.is_cuda
            and x.dtype == torch.float32
            and y.dtype == torch.float32
            and x.ndim == 2
            and x.shape == y.shape
            and not (
                torch.is_grad_enabled() and (x.requires_grad or y.requires_grad)
            )
        ):
            return _fused_ops.norm_residual_mul_cuda(
                x.contiguous(), y.contiguous(), self.instance_norm.eps
            )

        x = self.instance_norm(
            x.unsqueeze(1).unsqueeze(1)
        ).squeeze(1).squeeze(1)
        return (x + y) * y
```