```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 matmul_nt_cuda(torch::Tensor A, torch::Tensor B);
"""

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

namespace wmma = nvcuda::wmma;

__global__ void matmul_nt_kernel(
    const float* __restrict__ A,
    const float* __restrict__ B,
    float* __restrict__ C,
    int M, int N, int K)
{
#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 800
    constexpr int TILE = 64;
    constexpr int TILE_K = 32;
    constexpr int PANEL = TILE * TILE_K;

    extern __shared__ __align__(32) float storage[];
    float* ah = storage;
    float* al = storage + PANEL;
    float* bh = storage + 2 * PANEL;
    float* bl = storage + 3 * PANEL;

    const int tid = threadIdx.x;
    const int warp = tid / 32;
    const int warp_m = (warp / 2) * 32;
    const int warp_n = (warp % 2) * 32;
    const int block_m = blockIdx.y * TILE;
    const int block_n = blockIdx.x * TILE;

    wmma::fragment<wmma::accumulator, 16, 16, 8, float> acc[2][2];

    #pragma unroll
    for (int i = 0; i < 2; ++i) {
        #pragma unroll
        for (int j = 0; j < 2; ++j) {
            wmma::fill_fragment(acc[i][j], 0.0f);
        }
    }

    for (int k0 = 0; k0 < K; k0 += TILE_K) {
        for (int index = tid; index < PANEL; index += blockDim.x) {
            const int row = index / TILE_K;
            const int k = k0 + index % TILE_K;

            float a = 0.0f;
            float b = 0.0f;

            if (block_m + row < M && k < K)
                a = A[static_cast<int64_t>(block_m + row) * K + k];
            if (block_n + row < N && k < K)
                b = B[static_cast<int64_t>(block_n + row) * K + k];

            const float a_hi = __float_to_tf32(a);
            const float b_hi = __float_to_tf32(b);

            ah[index] = a_hi;
            al[index] = __float_to_tf32(a - a_hi);
            bh[index] = b_hi;
            bl[index] = __float_to_tf32(b - b_hi);
        }

        __syncthreads();

        #pragma unroll
        for (int kk = 0; kk < TILE_K; kk += 8) {
            wmma::fragment<
                wmma::matrix_a, 16, 16, 8,
                wmma::precision::tf32, wmma::row_major> a_hi[2], a_lo[2];

            wmma::fragment<
                wmma::matrix_b, 16, 16, 8,
                wmma::precision::tf32, wmma::col_major> b_hi[2], b_lo[2];

            #pragma unroll
            for (int i = 0; i < 2; ++i) {
                const int offset = (warp_m + i * 16) * TILE_K + kk;
                wmma::load_matrix_sync(a_hi[i], ah + offset, TILE_K);
                wmma::load_matrix_sync(a_lo[i], al + offset, TILE_K);
            }

            #pragma unroll
            for (int j = 0; j < 2; ++j) {
                const int offset = (warp_n + j * 16) * TILE_K + kk;
                wmma::load_matrix_sync(b_hi[j], bh + offset, TILE_K);
                wmma::load_matrix_sync(b_lo[j], bl + offset, TILE_K);
            }

            #pragma unroll
            for (int i = 0; i < 2; ++i) {
                #pragma unroll
                for (int j = 0; j < 2; ++j) {
                    // Recover FP32-like precision using three TF32 products.
                    wmma::mma_sync(acc[i][j], a_lo[i], b_hi[j], acc[i][j]);
                    wmma::mma_sync(acc[i][j], a_hi[i], b_lo[j], acc[i][j]);
                    wmma::mma_sync(acc[i][j], a_hi[i], b_hi[j], acc[i][j]);
                }
            }
        }

        __syncthreads();
    }

    // Reuse the input staging buffer for a coalesced output write.
    #pragma unroll
    for (int i = 0; i < 2; ++i) {
        #pragma unroll
        for (int j = 0; j < 2; ++j) {
            const int offset =
                (warp_m + i * 16) * TILE + warp_n + j * 16;
            wmma::store_matrix_sync(
                storage + offset, acc[i][j], TILE, wmma::mem_row_major);
        }
    }

    __syncthreads();

    for (int index = tid; index < TILE * TILE; index += blockDim.x) {
        const int row = block_m + index / TILE;
        const int col = block_n + index % TILE;
        if (row < M && col < N)
            C[static_cast<int64_t>(row) * N + col] = storage[index];
    }
#endif
}

torch::Tensor matmul_nt_cuda(torch::Tensor A, torch::Tensor B)
{
    TORCH_CHECK(A.is_cuda() && B.is_cuda(), "Inputs must be CUDA tensors");
    TORCH_CHECK(A.device() == B.device(), "Inputs must share a device");
    TORCH_CHECK(A.dim() == 2 && B.dim() == 2, "Inputs must be matrices");
    TORCH_CHECK(A.size(1) == B.size(1), "Incompatible matrix dimensions");
    TORCH_CHECK(
        A.scalar_type() == at::kFloat && B.scalar_type() == at::kFloat,
        "Inputs must be float32");
    TORCH_CHECK(A.is_contiguous() && B.is_contiguous(),
                "Inputs must be contiguous");

    const c10::cuda::CUDAGuard guard(A.device());

    if (at::cuda::getCurrentDeviceProperties()->major < 8)
        return at::matmul(A, B.transpose(0, 1));

    TORCH_CHECK(
        A.size(0) <= INT_MAX && B.size(0) <= INT_MAX &&
        A.size(1) <= INT_MAX,
        "Matrix dimensions exceed supported limits");

    const int M = static_cast<int>(A.size(0));
    const int N = static_cast<int>(B.size(0));
    const int K = static_cast<int>(A.size(1));

    auto C = torch::empty({M, N}, A.options());
    if (M == 0 || N == 0)
        return C;

    const dim3 grid((N + 63LL) / 64, (M + 63LL) / 64);
    constexpr int shared_bytes = 4 * 64 * 32 * sizeof(float);

    matmul_nt_kernel<<<
        grid, 128, shared_bytes, at::cuda::getCurrentCUDAStream()
    >>>(
        A.data_ptr<float>(), B.data_ptr<float>(), C.data_ptr<float>(),
        M, N, K);

    C10_CUDA_KERNEL_LAUNCH_CHECK();
    return C;
}
"""

_extension = load_inline(
    name="matmul_nt_tf32_compensated",
    cpp_sources=_cpp_source,
    cuda_sources=_cuda_source,
    functions=["matmul_nt_cuda"],
    extra_cflags=["-O3"],
    extra_cuda_cflags=["-O3"],
    verbose=False,
)


class ModelNew(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, A: torch.Tensor, B: torch.Tensor) -> torch.Tensor:
        if (
            A.is_cuda
            and B.is_cuda
            and A.device == B.device
            and A.dtype == torch.float32
            and B.dtype == torch.float32
            and A.ndim == 2
            and B.ndim == 2
            and not (torch.is_grad_enabled() and (A.requires_grad or B.requires_grad))
        ):
            return _extension.matmul_nt_cuda(A.contiguous(), B.contiguous())
        return torch.matmul(A, B.T)
```