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

cuda_src = r"""
#include <torch/extension.h>
#include <ATen/cuda/CUDAContext.h>
#include <cuda_runtime.h>

#define TCO 16

// Fast path: valid when dilation % stride == 0 (per dimension).
// Output o is nonzero only when (o + pad) % stride == 0 for every dim.
// Then with r = dil/stride, m = (o + pad)/stride: out[m] = sum_k w[k] * x[m - k*r].
__global__ void __launch_bounds__(256, 2) tconv3d_reduced_kernel(
    const float* __restrict__ x,   // [B, Ci, D, H, W]
    const float* __restrict__ wt,  // [K*K*K, Ci, Co] (co contiguous)
    const float* __restrict__ bias,// [Co] or null
    float* __restrict__ out,       // [B, Co, Od, Oh, Ow]
    int B, int Ci, int Co,
    int D, int H, int W,
    int Od, int Oh, int Ow,
    int Kd, int Kh, int Kw,
    int sd, int sh, int sw,
    int pd, int ph, int pw,
    int rd, int rh, int rw,
    int md0, int mdn, int mh0, int mhn, int mw0, int mwn)
{
    // Block tile: 4 (md) x 8 (mh) x 32 (mw) reduced voxels, 256 threads.
    const int tid = threadIdx.x;
    const int mw_grp = tid & 7;          // 8 groups x 4 voxels = 32
    const int mh_l   = (tid >> 3) & 7;   // 8
    const int md_l   = tid >> 6;         // 4

    const int mw_base = mw0 + mw_grp * 4;
    const int mh = mh0 + blockIdx.y * 8 + mh_l;
    const int md = md0 + (blockIdx.z & 3) * 4 + md_l;
    const int b  = blockIdx.z >> 2;

    const bool mh_ok = (mh < mh0 + mhn);
    const bool md_ok = (md < md0 + mdn);

    const int64_t x_batch = (int64_t)b * Ci * D * H * W;
    const int64_t o_batch = (int64_t)b * Co * Od * Oh * Ow;

    const int od = sd * md - pd;
    const int oh = sh * mh - ph;

    #pragma unroll 1
    for (int co0 = 0; co0 < Co; co0 += TCO) {
        float acc[TCO][4];
        #pragma unroll
        for (int c = 0; c < TCO; ++c) {
            #pragma unroll
            for (int v = 0; v < 4; ++v) acc[c][v] = 0.f;
        }

        #pragma unroll 1
        for (int kd = 0; kd < Kd; ++kd) {
            const int id = md - kd * rd;
            const bool id_ok = md_ok && (id >= 0) && (id < D);
            #pragma unroll 1
            for (int kh = 0; kh < Kh; ++kh) {
                const int ih = mh - kh * rh;
                const bool rc_ok = id_ok && mh_ok && (ih >= 0) && (ih < W * 0 + H);
                const float* xp = x + x_batch + ((int64_t)id * H + ih) * W;
                const float* wp = wt + ((int64_t)(kd * Kh + kh) * Kw) * Ci * Co + co0;
                #pragma unroll 1
                for (int ci = 0; ci < Ci; ++ci) {
                    float xv[Kw + 3];
                    if (rc_ok) {
                        const float* xr = xp + (int64_t)ci * D * H * W;
                        #pragma unroll
                        for (int j = 0; j < Kw + 3; ++j) {
                            const int iw = mw_base - (Kw - 1) * rw + j * rw;
                            xv[j] = (iw >= 0 && iw < W) ? __ldg(xr + iw) : 0.f;
                        }
                    } else {
                        #pragma unroll
                        for (int j = 0; j < Kw + 3; ++j) xv[j] = 0.f;
                    }
                    #pragma unroll
                    for (int kw = 0; kw < Kw; ++kw) {
                        const float* wq = wp + ((int64_t)kw * Ci + ci) * Co;
                        #pragma unroll
                        for (int c = 0; c < TCO; ++c) {
                            const float wv = __ldg(wq + c);
                            #pragma unroll
                            for (int v = 0; v < 4; ++v) {
                                acc[c][v] = fmaf(xv[v + (Kw - 1 - kw)], wv, acc[c][v]);
                            }
                        }
                    }
                }
            }
        }

        #pragma unroll
        for (int c = 0; c < TCO; ++c) {
            float bv = (bias != nullptr) ? __ldg(bias + co0 + c) : 0.f;
            #pragma unroll
            for (int v = 0; v < 4; ++v) {
                const int mw = mw_base + v;
                if (mw < mw0 + mwn && md_ok && mh_ok) {
                    const int ow = sw * mw - pw;
                    float val = acc[c][v];
                    if (bias != nullptr) val += bv;
                    out[o_batch + (((int64_t)(co0 + c) * Od + od) * Oh + oh) * Ow + ow] = val;
                }
            }
        }
    }
}

// General fallback: handles any stride/padding/dilation combination.
__global__ void tconv3d_general_kernel(
    const float* __restrict__ x,
    const float* __restrict__ wt,
    const float* __restrict__ bias,
    float* __restrict__ out,
    int B, int Ci, int Co,
    int D, int H, int W,
    int Od, int Oh, int Ow,
    int Kd, int Kh, int Kw,
    int sd, int sh, int sw,
    int pd, int ph, int pw,
    int dd, int dh, int dw,
    int64_t total)
{
    const int64_t idx = (int64_t)blockIdx.x * blockDim.x + threadIdx.x;
    if (idx >= total) return;

    const int ow = (int)(idx % Ow);
    const int64_t t1 = idx / Ow;
    const int oh = (int)(t1 % Oh);
    const int64_t t2 = t1 / Oh;
    const int od = (int)(t2 % Od);
    const int64_t t3 = t2 / Od;
    const int co = (int)(t3 % Co);
    const int b  = (int)(t3 / Co);

    const float* xb = x + (int64_t)b * Ci * D * H * W;
    const int nK = Kd * Kh * Kw;

    float acc = 0.f;
    for (int ci = 0; ci < Ci; ++ci) {
        const float* xc = xb + (int64_t)ci * D * H * W;
        const float* wc = wt + (int64_t)ci * Co * nK + (int64_t)co * nK;
        int kk = 0;
        for (int kd = 0; kd < Kd; ++kd) {
            const int tmpd = od + pd - kd * dd;
            if (tmpd % sd != 0) { kk += Kh * Kw; continue; }
            const int id = tmpd / sd;
            if (id < 0 || id >= D) { kk += Kh * Kw; continue; }
            for (int kh = 0; kh < Kh; ++kh) {
                const int tmph = oh + ph - kh * dh;
                if (tmph % sh != 0) { kk += Kw; continue; }
                const int ih = tmph / sh;
                if (ih < 0 || ih >= H) { kk += Kw; continue; }
                for (int kw = 0; kw < Kw; ++kw, ++kk) {
                    const int tmpw = ow + pw - kw * dw;
                    if (tmpw % sw != 0) continue;
                    const int iw = tmpw / sw;
                    if (iw < 0 || iw >= W) continue;
                    acc = fmaf(__ldg(xc + ((int64_t)id * H + ih) * W + iw),
                               __ldg(wc + kk), acc);
                }
            }
        }
    }
    if (bias != nullptr) acc += __ldg(bias + co);
    out[idx] = acc;
}

torch::Tensor tconv3d_forward(
    torch::Tensor x, torch::Tensor w, torch::Tensor bias,
    int64_t sd, int64_t sh, int64_t sw,
    int64_t pd, int64_t ph, int64_t pw,
    int64_t dd, int64_t dh, int64_t dw)
{
    TORCH_CHECK(x.is_cuda() && w.is_cuda(), "inputs must be CUDA");
    TORCH_CHECK(x.dtype() == torch::kFloat32, "only float32 supported");

    auto xc = x.contiguous();
    auto wc = w.contiguous();

    const int B  = xc.size(0);
    const int Ci = xc.size(1);
    const int D  = xc.size(2);
    const int H  = xc.size(3);
    const int W  = xc.size(4);
    const int Co = wc.size(1);
    const int Kd = wc.size(2);
    const int Kh = wc.size(3);
    const int Kw = wc.size(4);

    const int64_t Od = (D - 1) * sd - 2 * pd + dd * (Kd - 1) + 1;
    const int64_t Oh = (H - 1) * sh - 2 * ph + dh * (Kh - 1) + 1;
    const int64_t Ow = (W - 1) * sw - 2 * pw + dw * (Kw - 1) + 1;

    auto out = torch::empty({B, Co, Od, Oh, Ow}, xc.options());
    const bool has_bias = bias.defined() && bias.numel() > 0;
    auto stream = at::cuda::getCurrentCUDAStream();

    const bool fast = (dd % sd == 0) && (dh % sh == 0) && (dw % sw == 0) &&
                      (Co % TCO == 0);

    if (fast) {
        const int rd = dd / sd, rh = dh / sh, rw = dw / sw;
        const int md0 = (pd + sd - 1) / sd;
        const int mdn = (int)((Od - 1 + pd) / sd) - md0 + 1;
        const int mh0 = (ph + sh - 1) / sh;
        const int mhn = (int)((Oh - 1 + ph) / sh) - mh0 + 1;
        const int mw0 = (pw + sw - 1) / sw;
        const int mwn = (int)((Ow - 1 + pw) / sw) - mw0 + 1;

        // zero only if there exist output positions that receive no contribution
        const bool need_zero = (mdn * sd < Od) || (mhn * sh < Oh) || (mwn * sw < Ow) ||
                               (sd > 1) || (sh > 1) || (sw > 1);
        if (need_zero) {
            cudaMemsetAsync(out.data_ptr(), 0, (size_t)out.numel() * sizeof(float), stream);
        }
        if (mdn <= 0 || mhn <= 0 || mwn <= 0) return out;

        // transpose weight to [Kd*Kh*Kw, Ci, Co]
        auto wt = wc.permute({2, 3, 4, 0, 1}).contiguous();

        dim3 block(256);
        dim3 grid((mwn + 31) / 32, (mhn + 7) / 8, B * ((mdn + 3) / 4));
        tconv3d_reduced_kernel<<<grid, block, 0, stream>>>(
            xc.data_ptr<float>(), wt.data_ptr<float>(),
            has_bias ? bias.data_ptr<float>() : nullptr,
            out.data_ptr<float>(),
            B, Ci, Co, D, H, W,
            (int)Od, (int)Oh, (int)Ow,
            Kd, Kh, Kw,
            (int)sd, (int)sh, (int)sw,
            (int)pd, (int)ph, (int)pw,
            rd, rh, rw,
            md0, mdn, mh0, mhn, mw0, mwn);
    } else {
        const int64_t total = out.numel();
        if (total == 0) return out;
        const int threads = 256;
        const int64_t blocks = (total + threads - 1) / threads;
        tconv3d_general_kernel<<<(unsigned)blocks, threads, 0, stream>>>(
            xc.data_ptr<float>(), wc.data_ptr<float>(),
            has_bias ? bias.data_ptr<float>() : nullptr,
            out.data_ptr<float>(),
            B, Ci, Co, D, H, W,
            (int)Od, (int)Oh, (int)Ow,
            Kd, Kh, Kw,
            (int)sd, (int)sh, (int)sw,
            (int)pd, (int)ph, (int)pw,
            (int)dd, (int)dh, (int)dw,
            total);
    }
    return out;
}
"""

cpp_src = """
torch::Tensor tconv3d_forward(
    torch::Tensor x, torch::Tensor w, torch::Tensor bias,
    int64_t sd, int64_t sh, int64_t sw,
    int64_t pd, int64_t ph, int64_t pw,
    int64_t dd, int64_t dh, int64_t dw);
"""

tconv3d = load_inline(
    name="tconv3d_custom",
    cpp_sources=cpp_src,
    cuda_sources=cuda_src,
    functions=["tconv3d_forward"],
    verbose=False,
    extra_cuda_cflags=["-O3", "--use_fast_math"],
)


class ModelNew(nn.Module):
    def __init__(self, in_channels: int, out_channels: int, kernel_size: int,
                 stride: int = 1, padding: int = 0, dilation: int = 1,
                 bias: bool = False):
        super(ModelNew, self).__init__()
        self.conv_transpose3d = nn.ConvTranspose3d(
            in_channels, out_channels,
            kernel_size=(kernel_size, kernel_size, kernel_size),
            stride=stride, padding=padding, dilation=dilation, bias=bias)
        s = self.conv_transpose3d.stride
        p = self.conv_transpose3d.padding
        d = self.conv_transpose3d.dilation
        self.sd, self.sh, self.sw = s[0], s[1], s[2]
        self.pd, self.ph, self.pw = p[0], p[1], p[2]
        self.dd, self.dh, self.dw = d[0], d[1], d[2]

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        w = self.conv_transpose3d.weight
        b = self.conv_transpose3d.bias
        if b is None:
            b = torch.empty(0, device=x.device, dtype=x.dtype)
        return tconv3d.tconv3d_forward(
            x, w, b,
            self.sd, self.sh, self.sw,
            self.pd, self.ph, self.pw,
            self.dd, self.dh, self.dw)
```