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

_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>
#include <cstdint>

__device__ __forceinline__ float block_sum(float value) {
    __shared__ float partial[8];
    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)
        partial[warp] = value;
    __syncthreads();

    if (warp == 0) {
        value = lane < 8 ? partial[lane] : 0.0f;
        #pragma unroll
        for (int offset = 16; offset > 0; offset >>= 1)
            value += __shfl_down_sync(0xffffffff, value, offset);
        if (lane == 0)
            partial[0] = value;
    }
    __syncthreads();
    const float result = partial[0];
    __syncthreads();
    return result;
}

__device__ __forceinline__ float finish(
    float centered, float inv_std, float residual
) {
    return __fmul_rn(
        __fadd_rn(__fmul_rn(centered, inv_std), residual),
        residual);
}

template<int ITEMS>
__global__ void norm_residual_vectorized(
    const float4* __restrict__ input,
    const float4* __restrict__ residual,
    float4* __restrict__ output,
    int vectors,
    float epsilon
) {
    const int64_t base = int64_t(blockIdx.x) * vectors;
    float4 values[ITEMS];
    float sum = 0.0f;

    #pragma unroll
    for (int i = 0; i < ITEMS; ++i) {
        const int col = threadIdx.x + i * 256;
        const float4 v = col < vectors
            ? input[base + col]
            : make_float4(0.0f, 0.0f, 0.0f, 0.0f);
        values[i] = v;
        sum += (v.x + v.y) + (v.z + v.w);
    }

    const float mean = block_sum(sum) / float(vectors * 4);
    float squared_sum = 0.0f;

    #pragma unroll
    for (int i = 0; i < ITEMS; ++i) {
        const int col = threadIdx.x + i * 256;
        if (col < vectors) {
            float4 v = values[i];
            v.x -= mean;
            v.y -= mean;
            v.z -= mean;
            v.w -= mean;
            values[i] = v;
            squared_sum = fmaf(v.x, v.x, squared_sum);
            squared_sum = fmaf(v.y, v.y, squared_sum);
            squared_sum = fmaf(v.z, v.z, squared_sum);
            squared_sum = fmaf(v.w, v.w, squared_sum);
        }
    }

    const float inv_std = rsqrtf(
        block_sum(squared_sum) / float(vectors * 4) + epsilon);

    #pragma unroll
    for (int i = 0; i < ITEMS; ++i) {
        const int col = threadIdx.x + i * 256;
        if (col < vectors) {
            const float4 v = values[i];
            const float4 y = residual[base + col];
            output[base + col] = make_float4(
                finish(v.x, inv_std, y.x),
                finish(v.y, inv_std, y.y),
                finish(v.z, inv_std, y.z),
                finish(v.w, inv_std, y.w));
        }
    }
}

__global__ void norm_residual_scalar(
    const float* __restrict__ input,
    const float* __restrict__ residual,
    float* __restrict__ output,
    int columns,
    float epsilon
) {
    const int64_t base = int64_t(blockIdx.x) * columns;
    float values[32];
    float sum = 0.0f;

    #pragma unroll
    for (int i = 0; i < 32; ++i) {
        const int col = threadIdx.x + i * 256;
        const float value = col < columns ? input[base + col] : 0.0f;
        values[i] = value;
        sum += value;
    }

    const float mean = block_sum(sum) / float(columns);
    float squared_sum = 0.0f;

    #pragma unroll
    for (int i = 0; i < 32; ++i) {
        const int col = threadIdx.x + i * 256;
        if (col < columns) {
            values[i] -= mean;
            squared_sum = fmaf(values[i], values[i], squared_sum);
        }
    }

    const float inv_std = rsqrtf(
        block_sum(squared_sum) / float(columns) + epsilon);

    #pragma unroll
    for (int i = 0; i < 32; ++i) {
        const int col = threadIdx.x + i * 256;
        if (col < columns)
            output[base + col] = finish(
                values[i], inv_std, residual[base + col]);
    }
}

torch::Tensor fused_norm_residual(
    torch::Tensor input,
    torch::Tensor residual,
    double epsilon
) {
    TORCH_CHECK(input.is_cuda() && residual.is_cuda(),
                "Expected CUDA tensors");
    TORCH_CHECK(input.device() == residual.device(),
                "Devices must match");
    TORCH_CHECK(input.scalar_type() == at::kFloat &&
                residual.scalar_type() == at::kFloat,
                "Expected float32 tensors");
    TORCH_CHECK(input.dim() == 2 && input.sizes() == residual.sizes(),
                "Expected matching matrices");
    TORCH_CHECK(input.is_contiguous() && residual.is_contiguous(),
                "Expected contiguous tensors");
    TORCH_CHECK(input.size(1) > 1 && input.size(1) <= 8192,
                "Unsupported row width");

    const c10::cuda::CUDAGuard guard(input.device());
    auto output = torch::empty_like(input);
    if (input.size(0) == 0)
        return output;

    const int rows = static_cast<int>(input.size(0));
    const int columns = static_cast<int>(input.size(1));
    const auto stream = at::cuda::getCurrentCUDAStream();

    const float* x = input.data_ptr<float>();
    const float* y = residual.data_ptr<float>();
    float* out = output.data_ptr<float>();

    const bool aligned =
        ((reinterpret_cast<uintptr_t>(x) |
          reinterpret_cast<uintptr_t>(y) |
          reinterpret_cast<uintptr_t>(out)) & 15) == 0;

    if (columns % 4 == 0 && aligned) {
        const int vectors = columns / 4;
        const float4* xv = reinterpret_cast<const float4*>(x);
        const float4* yv = reinterpret_cast<const float4*>(y);
        float4* ov = reinterpret_cast<float4*>(out);

        if (vectors <= 256) {
            norm_residual_vectorized<1><<<rows, 256, 0, stream>>>(
                xv, yv, ov, vectors, float(epsilon));
        } else if (vectors <= 512) {
            norm_residual_vectorized<2><<<rows, 256, 0, stream>>>(
                xv, yv, ov, vectors, float(epsilon));
        } else if (vectors <= 1024) {
            norm_residual_vectorized<4><<<rows, 256, 0, stream>>>(
                xv, yv, ov, vectors, float(epsilon));
        } else {
            norm_residual_vectorized<8><<<rows, 256, 0, stream>>>(
                xv, yv, ov, vectors, float(epsilon));
        }
    } else {
        norm_residual_scalar<<<rows, 256, 0, stream>>>(
            x, y, out, columns, float(epsilon));
    }

    C10_CUDA_KERNEL_LAUNCH_CHECK();
    return output;
}
"""

_ops = load_inline(
    name="linear_fused_instance_residual_v4",
    cpp_sources=r"""
torch::Tensor fused_norm_residual(
    torch::Tensor input,
    torch::Tensor residual,
    double epsilon);
""",
    cuda_sources=_cuda_source,
    functions=["fused_norm_residual"],
    extra_cflags=["-O3"],
    extra_cuda_cflags=["-O3"],
    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):
        z = self.bmm(x)

        if (
            z.is_cuda
            and y.is_cuda
            and z.device == y.device
            and z.dtype == y.dtype == torch.float32
            and z.ndim == 2
            and y.shape == z.shape
            and 1 < z.shape[1] <= 8192
            and z.shape[0] <= 2147483647
        ):
            return _ops.fused_norm_residual(
                z.contiguous(), y.contiguous(), self.instance_norm.eps
            )

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