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

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

std::vector<torch::Tensor> scaled_bn_forward(
    torch::Tensor x,
    torch::Tensor scale,
    torch::Tensor weight,
    torch::Tensor bias,
    torch::Tensor running_mean,
    torch::Tensor running_var,
    double eps,
    double momentum,
    bool training);
"""

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

constexpr int ROWS_PER_PART = 256;

__global__ void partial_stats_kernel(
    const float* __restrict__ x,
    const float* __restrict__ scale,
    float* __restrict__ partial_mean,
    float* __restrict__ partial_m2,
    int rows,
    int cols)
{
    __shared__ float means[256];
    __shared__ float m2s[256];
    __shared__ int counts[256];

    const int tid = threadIdx.x;
    const int lane = tid & 31;
    const int group = tid >> 5;
    const int col = blockIdx.x * 32 + lane;
    const int start = blockIdx.y * ROWS_PER_PART;

    float mean = 0.0f;
    float m2 = 0.0f;
    int count = 0;
    const float s = col < cols ? scale[col] : 0.0f;

    #pragma unroll
    for (int i = 0; i < 32; ++i) {
        const int row = start + group + i * 8;
        if (row < rows && col < cols) {
            const float value = x[(int64_t)row * cols + col] * s;
            ++count;
            const float delta = value - mean;
            mean += delta / float(count);
            m2 += delta * (value - mean);
        }
    }

    means[tid] = mean;
    m2s[tid] = m2;
    counts[tid] = count;
    __syncthreads();

    if (group == 0 && col < cols) {
        float merged_mean = means[lane];
        float merged_m2 = m2s[lane];
        int merged_count = counts[lane];

        #pragma unroll
        for (int g = 1; g < 8; ++g) {
            const int index = g * 32 + lane;
            const int n = counts[index];
            if (n != 0) {
                const int total = merged_count + n;
                const float delta = means[index] - merged_mean;
                merged_m2 += m2s[index] +
                    delta * delta *
                    (float(merged_count) * float(n) / float(total));
                merged_mean += delta * (float(n) / float(total));
                merged_count = total;
            }
        }

        const int64_t index = (int64_t)blockIdx.y * cols + col;
        partial_mean[index] = merged_mean;
        partial_m2[index] = merged_m2;
    }
}

__global__ void finish_stats_kernel(
    const float* __restrict__ partial_mean,
    const float* __restrict__ partial_m2,
    float* __restrict__ running_mean,
    float* __restrict__ running_var,
    float* __restrict__ mean_out,
    float* __restrict__ invstd_out,
    int rows,
    int cols,
    int parts,
    float eps,
    float momentum,
    bool training)
{
    const int col = blockIdx.x * blockDim.x + threadIdx.x;
    if (col >= cols) return;

    if (!training) {
        mean_out[col] = running_mean[col];
        invstd_out[col] = rsqrtf(running_var[col] + eps);
        return;
    }

    float mean = 0.0f;
    float m2 = 0.0f;
    int count = 0;

    for (int p = 0; p < parts; ++p) {
        const int n = min(ROWS_PER_PART, rows - p * ROWS_PER_PART);
        const int total = count + n;
        const int64_t index = (int64_t)p * cols + col;
        const float delta = partial_mean[index] - mean;

        m2 += partial_m2[index] +
              delta * delta * (float(count) * float(n) / float(total));
        mean += delta * (float(n) / float(total));
        count = total;
    }

    m2 = fmaxf(m2, 0.0f);
    mean_out[col] = mean;
    invstd_out[col] = rsqrtf(m2 / float(rows) + eps);

    running_mean[col] =
        (1.0f - momentum) * running_mean[col] + momentum * mean;
    running_var[col] =
        (1.0f - momentum) * running_var[col] +
        momentum * (m2 / float(rows - 1));
}

__global__ void normalize_kernel(
    const float* __restrict__ x,
    const float* __restrict__ scale,
    const float* __restrict__ weight,
    const float* __restrict__ bias,
    const float* __restrict__ mean,
    const float* __restrict__ invstd,
    float* __restrict__ output,
    int64_t elements,
    int cols)
{
    for (int64_t index = (int64_t)blockIdx.x * blockDim.x + threadIdx.x;
         index < elements;
         index += (int64_t)blockDim.x * gridDim.x) {
        const int col = index % cols;
        const float value = x[index] * scale[col];
        const float normalized = (value - mean[col]) * invstd[col];
        output[index] = normalized * weight[col] + bias[col];
    }
}

std::vector<torch::Tensor> scaled_bn_forward(
    torch::Tensor x,
    torch::Tensor scale,
    torch::Tensor weight,
    torch::Tensor bias,
    torch::Tensor running_mean,
    torch::Tensor running_var,
    double eps,
    double momentum,
    bool training)
{
    const c10::cuda::CUDAGuard guard(x.device());
    const cudaStream_t stream = at::cuda::getCurrentCUDAStream();

    const int rows = static_cast<int>(x.size(0));
    const int cols = static_cast<int>(x.size(1));
    const int parts = (rows + ROWS_PER_PART - 1) / ROWS_PER_PART;

    auto output = torch::empty_like(x);
    auto mean = torch::empty({cols}, x.options());
    auto invstd = torch::empty({cols}, x.options());

    torch::Tensor partial_mean;
    torch::Tensor partial_m2;
    const float* partial_mean_ptr = nullptr;
    const float* partial_m2_ptr = nullptr;

    if (training) {
        partial_mean = torch::empty({parts, cols}, x.options());
        partial_m2 = torch::empty({parts, cols}, x.options());
        partial_mean_ptr = partial_mean.data_ptr<float>();
        partial_m2_ptr = partial_m2.data_ptr<float>();

        const dim3 grid((cols + 31) / 32, parts);
        partial_stats_kernel<<<grid, 256, 0, stream>>>(
            x.data_ptr<float>(),
            scale.data_ptr<float>(),
            partial_mean.data_ptr<float>(),
            partial_m2.data_ptr<float>(),
            rows, cols);
        C10_CUDA_KERNEL_LAUNCH_CHECK();
    }

    finish_stats_kernel<<<(cols + 255) / 256, 256, 0, stream>>>(
        partial_mean_ptr,
        partial_m2_ptr,
        running_mean.data_ptr<float>(),
        running_var.data_ptr<float>(),
        mean.data_ptr<float>(),
        invstd.data_ptr<float>(),
        rows, cols, parts,
        static_cast<float>(eps),
        static_cast<float>(momentum),
        training);
    C10_CUDA_KERNEL_LAUNCH_CHECK();

    const int64_t needed_blocks = (x.numel() + 255) / 256;
    const int blocks =
        static_cast<int>(needed_blocks < 65535 ? needed_blocks : 65535);

    normalize_kernel<<<blocks, 256, 0, stream>>>(
        x.data_ptr<float>(),
        scale.data_ptr<float>(),
        weight.data_ptr<float>(),
        bias.data_ptr<float>(),
        mean.data_ptr<float>(),
        invstd.data_ptr<float>(),
        output.data_ptr<float>(),
        x.numel(), cols);
    C10_CUDA_KERNEL_LAUNCH_CHECK();

    return {output, mean, invstd};
}
"""

_scaled_bn = load_inline(
    name="fused_linear_scale_bn_welford_v1",
    cpp_sources=_cpp_source,
    cuda_sources=_cuda_source,
    functions=["scaled_bn_forward"],
    extra_cflags=["-O3"],
    extra_cuda_cflags=["-O3"],
    verbose=False,
)


class _ScaledBatchNorm(torch.autograd.Function):
    @staticmethod
    def forward(
        ctx, x, scale, weight, bias,
        running_mean, running_var, eps, momentum, training
    ):
        output, mean, invstd = _scaled_bn.scaled_bn_forward(
            x, scale, weight, bias,
            running_mean, running_var, eps, momentum, training
        )
        ctx.training = training
        ctx.save_for_backward(x, scale, weight, mean, invstd)
        return output

    @staticmethod
    def backward(ctx, grad_output):
        x, scale, weight, mean, invstd = ctx.saved_tensors
        normalized = (x * scale - mean) * invstd

        grad_weight = (
            (grad_output * normalized).sum(dim=0)
            if ctx.needs_input_grad[2] else None
        )
        grad_bias = (
            grad_output.sum(dim=0)
            if ctx.needs_input_grad[3] else None
        )

        grad_x = None
        grad_scale = None
        if ctx.needs_input_grad[0] or ctx.needs_input_grad[1]:
            grad_normalized = grad_output * weight
            if ctx.training:
                grad_scaled = (
                    grad_normalized
                    - grad_normalized.mean(dim=0)
                    - normalized
                    * (grad_normalized * normalized).mean(dim=0)
                ) * invstd
            else:
                grad_scaled = grad_normalized * invstd

            if ctx.needs_input_grad[0]:
                grad_x = grad_scaled * scale
            if ctx.needs_input_grad[1]:
                grad_scale = (grad_scaled * x).sum(dim=0)

        return (
            grad_x, grad_scale, grad_weight, grad_bias,
            None, None, None, None, None,
        )


class ModelNew(nn.Module):
    def __init__(
        self, in_features, out_features, scale_shape,
        eps=1e-5, momentum=0.1
    ):
        super().__init__()
        self.gemm = nn.Linear(in_features, out_features)
        self.scale = nn.Parameter(torch.randn(scale_shape))
        self.bn = nn.BatchNorm1d(
            out_features, eps=eps, momentum=momentum
        )

    def forward(self, x):
        x = self.gemm(x)
        bn = self.bn

        use_custom = (
            x.is_cuda
            and x.dtype == torch.float32
            and x.ndim == 2
            and x.is_contiguous()
            and 1 < x.shape[0] <= 256 * 65535
            and x.shape[1] > 0
            and self.scale.ndim == 1
            and self.scale.numel() == x.shape[1]
            and bn.affine
            and bn.track_running_stats
        )
        if use_custom:
            use_custom = all(
                tensor.dtype == torch.float32
                and tensor.device == x.device
                and tensor.is_contiguous()
                for tensor in (
                    self.scale, bn.weight, bn.bias,
                    bn.running_mean, bn.running_var,
                )
            )

        if not use_custom:
            return bn(x * self.scale)

        momentum = bn.momentum
        if bn.training:
            bn.num_batches_tracked.add_(1)
            if momentum is None:
                momentum = 1.0 / bn.num_batches_tracked.item()
        if momentum is None:
            momentum = 0.0

        return _ScaledBatchNorm.apply(
            x, self.scale, bn.weight, bn.bias,
            bn.running_mean, bn.running_var,
            bn.eps, momentum, bn.training,
        )
```