You write custom CUDA kernels to replace the pytorch operators in the given architecture to get speedups. 

    You have complete freedom to choose the set of operators you want to replace. You may make the decision to replace some operators with custom CUDA kernels and leave others unchanged. You may replace multiple operators with custom implementations, consider operator fusion opportunities (combining multiple operators into a single kernel, for example, combining matmul+relu), or algorithmic changes (such as online softmax). You are only limited by your imagination.


        Here's an example to show you the syntax of inline embedding custom CUDA operators in torch: The example given architecture is: 

        ``` 

        # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.

import torch
import torch.nn as nn
import torch.nn.functional as F


class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()

    def forward(self, a, b):
        return a + b


def get_inputs():
    # randomly generate input tensors based on the model architecture
    a = torch.randn(1, 128).cuda()
    b = torch.randn(1, 128).cuda()
    return [a, b]


def get_init_inputs():
    # randomly generate tensors required for initialization based on the model architecture
    return []

        ``` 

        The example new arch with custom CUDA kernels looks like this:
        ```
        # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.

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

# Define the custom CUDA kernel for element-wise addition
elementwise_add_source = """
#include <torch/extension.h>
#include <cuda_runtime.h>

__global__ void elementwise_add_kernel(const float* a, const float* b, float* out, int size) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx < size) {
        out[idx] = a[idx] + b[idx];
    }
}

torch::Tensor elementwise_add_cuda(torch::Tensor a, torch::Tensor b) {
    auto size = a.numel();
    auto out = torch::zeros_like(a);

    const int block_size = 256;
    const int num_blocks = (size + block_size - 1) / block_size;

    elementwise_add_kernel<<<num_blocks, block_size>>>(a.data_ptr<float>(), b.data_ptr<float>(), out.data_ptr<float>(), size);

    return out;
}
"""

elementwise_add_cpp_source = (
    "torch::Tensor elementwise_add_cuda(torch::Tensor a, torch::Tensor b);"
)

# Compile the inline CUDA code for element-wise addition
elementwise_add = load_inline(
    name="elementwise_add",
    cpp_sources=elementwise_add_cpp_source,
    cuda_sources=elementwise_add_source,
    functions=["elementwise_add_cuda"],
    verbose=True,
    extra_cflags=[""],
    extra_ldflags=[""],
)


class ModelNew(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.elementwise_add = elementwise_add

    def forward(self, a, b):
        return self.elementwise_add.elementwise_add_cuda(a, b)

        ``` 

        
    You are given the following architecture: 

    ```
    # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.

import torch
import torch.nn as nn

class Model(nn.Module):
    """
    Model that performs a 3D transposed convolution, followed by two max pooling layers and a sum operation.
    """
    def __init__(self, in_channels, out_channels, kernel_size, stride, padding):
        super(Model, self).__init__()
        self.conv_transpose = nn.ConvTranspose3d(in_channels, out_channels, kernel_size, stride=stride, padding=padding)
        self.max_pool1 = nn.MaxPool3d(kernel_size=2)
        self.max_pool2 = nn.MaxPool3d(kernel_size=3)

    def forward(self, x):
        x = self.conv_transpose(x)
        x = self.max_pool1(x)
        x = self.max_pool2(x)
        x = torch.sum(x, dim=1, keepdim=True) 
        return x

batch_size = 16
in_channels = 32
out_channels = 64
depth, height, width = 32, 32, 32
kernel_size = 5
stride = 2
padding = 2

def get_inputs():
    return [torch.rand(batch_size, in_channels, depth, height, width)]

def get_init_inputs():
    return [in_channels, out_channels, kernel_size, stride, padding]
    ```
    
Optimize the architecture named Model with custom CUDA operators! Name your optimized output architecture ModelNew. Output the new code in codeblocks. Please generate real code, NOT pseudocode, make sure the code compiles and is fully functional. Just output the new model code, no other text, and NO testing code! 



This is turn 6 of 6 for this task. Your previous solution (turn 5) was:
```python
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.cpp_extension import load_inline


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

std::vector<torch::Tensor> pack_phases_cuda(
    torch::Tensor x, torch::Tensor weight);

torch::Tensor pool_phases_cuda(
    torch::Tensor a, torch::Tensor b,
    torch::Tensor c, torch::Tensor d,
    torch::Tensor bias);
"""

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

__global__ void pack_input_kernel(
    const float* __restrict__ x,
    float* __restrict__ a,
    float* __restrict__ b,
    float* __restrict__ c,
    float* __restrict__ d,
    int channels, int depth, int height, int width,
    int pd, int ph, int pw,
    int64_t sn, int64_t sc,
    int64_t sd, int64_t sh, int64_t sw
) {
    __shared__ float tile[32][33];

    const int tx = threadIdx.x;
    const int ty = threadIdx.y;
    const int n = blockIdx.z;
    const int first_c = blockIdx.y * 32;
    const int first_s = blockIdx.x * 32;
    const int volume = pd * ph * pw;
    const int s = first_s + tx;

    const int iw = s % pw - 1;
    const int ih = (s / pw) % ph - 1;
    const int id = s / (ph * pw) - 1;

    const bool valid = s < volume &&
        id >= 0 && id < depth &&
        ih >= 0 && ih < height &&
        iw >= 0 && iw < width;

    #pragma unroll
    for (int j = 0; j < 32; j += 8) {
        const int ic = first_c + ty + j;
        float value = 0.0f;
        if (valid && ic < channels) {
            value = x[int64_t(n) * sn + int64_t(ic) * sc +
                      int64_t(id) * sd + int64_t(ih) * sh +
                      int64_t(iw) * sw];
        }
        tile[ty + j][tx] = value;
    }
    __syncthreads();

    const int ic = first_c + tx;

    #pragma unroll
    for (int j = 0; j < 32; j += 8) {
        const int os = first_s + ty + j;
        if (os < volume && ic < channels) {
            const float value = tile[tx][ty + j];
            const int z = os / (ph * pw);
            const int y = (os / pw) % ph;
            const int w = os % pw;

            a[(int64_t(n) * volume + os) * channels + ic] = value;

            if (y > 0) {
                const int64_t target =
                    ((int64_t(n) * pd + z) * (ph - 1) + y - 1) * pw + w;
                b[target * channels + ic] = value;
            }
            if (z > 0) {
                const int64_t target =
                    ((int64_t(n) * (pd - 1) + z - 1) * ph + y) * pw + w;
                c[target * channels + ic] = value;
            }
            if (z > 0 && y > 0) {
                const int64_t target =
                    ((int64_t(n) * (pd - 1) + z - 1) * (ph - 1) +
                     y - 1) * pw + w;
                d[target * channels + ic] = value;
            }
        }
    }
}

__global__ void pack_weight_kernel(
    const float* __restrict__ weight,
    float* __restrict__ a,
    float* __restrict__ b,
    float* __restrict__ c,
    float* __restrict__ d,
    int channels,
    int64_t si, int64_t so,
    int64_t sd, int64_t sh, int64_t sw
) {
    const int phase = blockIdx.y;
    const int dp = phase >> 1;
    const int hp = phase & 1;
    const int kd_size = 3 - dp;
    const int kh_size = 3 - hp;
    const int64_t count = int64_t(128) * kd_size * kh_size * 3 * channels;

    float* target = phase == 0 ? a : (phase == 1 ? b : (phase == 2 ? c : d));

    for (int64_t index = int64_t(blockIdx.x) * blockDim.x + threadIdx.x;
         index < count;
         index += int64_t(blockDim.x) * gridDim.x) {
        int64_t t = index;
        const int ic = t % channels;
        t /= channels;
        const int rw = t % 3;
        t /= 3;
        const int rh = t % kh_size;
        t /= kh_size;
        const int rd = t % kd_size;
        t /= kd_size;
        const int oc = t & 63;
        const int wp = t >> 6;

        const int kd = 4 - dp - 2 * rd;
        const int kh = 4 - hp - 2 * rh;
        const int kw = 4 + wp - 2 * rw;

        float value = 0.0f;
        if (kw < 5) {
            value = weight[int64_t(ic) * si + int64_t(oc) * so +
                           int64_t(kd) * sd + int64_t(kh) * sh +
                           int64_t(kw) * sw];
        }
        target[index] = value;
    }
}

std::vector<torch::Tensor> pack_phases_cuda(
    torch::Tensor x, torch::Tensor weight
) {
    const c10::cuda::CUDAGuard guard(x.device());

    TORCH_CHECK(x.is_cuda() && weight.is_cuda(), "Expected CUDA tensors");
    TORCH_CHECK(x.scalar_type() == at::kFloat &&
                weight.scalar_type() == at::kFloat, "Expected float32");
    TORCH_CHECK(x.device() == weight.device(), "Device mismatch");

    const int n = x.size(0);
    const int ic = x.size(1);
    const int depth = x.size(2);
    const int height = x.size(3);
    const int width = x.size(4);

    const int pd = ((2 * depth - 1) / 6) * 3 + 2;
    const int ph = ((2 * height - 1) / 6) * 3 + 2;
    const int pw = ((2 * width - 1) / 6) * 3 + 2;

    std::vector<torch::Tensor> packed;
    packed.reserve(8);

    for (int p = 0; p < 4; ++p) {
        packed.push_back(
            torch::empty({n, pd - (p >> 1), ph - (p & 1), pw, ic},
                         x.options()).permute({0, 4, 1, 2, 3})
        );
    }
    for (int p = 0; p < 4; ++p) {
        packed.push_back(
            torch::empty({128, 3 - (p >> 1), 3 - (p & 1), 3, ic},
                         weight.options()).permute({0, 4, 1, 2, 3})
        );
    }

    const auto stream = at::cuda::getCurrentCUDAStream();

    pack_input_kernel<<<
        dim3((pd * ph * pw + 31) / 32, (ic + 31) / 32, n),
        dim3(32, 8), 0, stream>>>(
            x.data_ptr<float>(),
            packed[0].data_ptr<float>(),
            packed[1].data_ptr<float>(),
            packed[2].data_ptr<float>(),
            packed[3].data_ptr<float>(),
            ic, depth, height, width, pd, ph, pw,
            x.stride(0), x.stride(1), x.stride(2),
            x.stride(3), x.stride(4)
        );

    const int blocks = static_cast<int>(
        std::min<int64_t>((packed[4].numel() + 255) / 256, 65535)
    );

    pack_weight_kernel<<<dim3(blocks, 4), 256, 0, stream>>>(
        weight.data_ptr<float>(),
        packed[4].data_ptr<float>(),
        packed[5].data_ptr<float>(),
        packed[6].data_ptr<float>(),
        packed[7].data_ptr<float>(),
        ic,
        weight.stride(0), weight.stride(1), weight.stride(2),
        weight.stride(3), weight.stride(4)
    );

    C10_CUDA_KERNEL_LAUNCH_CHECK();
    return packed;
}

__device__ __forceinline__ float max_nan(float a, float b) {
    return isnan(a) ? a : (isnan(b) ? b : fmaxf(a, b));
}

__device__ __forceinline__ float4 max4(float4 a, float4 b) {
    return make_float4(
        max_nan(a.x, b.x), max_nan(a.y, b.y),
        max_nan(a.z, b.z), max_nan(a.w, b.w)
    );
}

__global__ void pool_phases_kernel(
    const float4* __restrict__ a,
    const float4* __restrict__ b,
    const float4* __restrict__ c,
    const float4* __restrict__ d,
    const float4* __restrict__ bias,
    float* __restrict__ output,
    int depth, int height, int width,
    int od, int oh, int ow
) {
    __shared__ float4 partial[4][16];

    const int tid = threadIdx.x;
    const int lane = tid & 31;
    const int warp = tid >> 5;
    const int index = blockIdx.x;
    const int output_volume = od * oh * ow;
    const int n = index / output_volume;

    int s = index % output_volume;
    const int w = s % ow;
    s /= ow;
    const int h = s % oh;
    const int z = s / oh;

    const int64_t origin =
        ((int64_t(n) * depth + 3 * z) * height + 3 * h) * width + 3 * w;

    const float4* phase = warp == 0 ? a : (warp == 1 ? b : (warp == 2 ? c : d));
    const float4* base = phase + origin * 32 + lane;

    float4 maximum = make_float4(
        -INFINITY, -INFINITY, -INFINITY, -INFINITY
    );

    #pragma unroll
    for (int dz = 0; dz < 3; ++dz) {
        #pragma unroll
        for (int dy = 0; dy < 3; ++dy) {
            #pragma unroll
            for (int dx = 0; dx < 3; ++dx) {
                const int64_t offset =
                    (int64_t(dz) * height * width + dy * width + dx) * 32;
                maximum = max4(maximum, base[offset]);
            }
        }
    }

    float4 other;
    other.x = __shfl_xor_sync(0xffffffff, maximum.x, 16);
    other.y = __shfl_xor_sync(0xffffffff, maximum.y, 16);
    other.z = __shfl_xor_sync(0xffffffff, maximum.z, 16);
    other.w = __shfl_xor_sync(0xffffffff, maximum.w, 16);
    maximum = max4(maximum, other);

    if (lane < 16) {
        partial[warp][lane] = maximum;
    }
    __syncthreads();

    if (warp == 0) {
        float sum = 0.0f;
        if (lane < 16) {
            float4 value = max4(
                max4(partial[0][lane], partial[1][lane]),
                max4(partial[2][lane], partial[3][lane])
            );
            const float4 bv = bias[lane];
            value.x += bv.x;
            value.y += bv.y;
            value.z += bv.z;
            value.w += bv.w;
            sum = (value.x + value.y) + (value.z + value.w);
        }

        #pragma unroll
        for (int offset = 8; offset > 0; offset >>= 1) {
            sum += __shfl_down_sync(0xffffffff, sum, offset);
        }
        if (lane == 0) {
            output[index] = sum;
        }
    }
}

torch::Tensor pool_phases_cuda(
    torch::Tensor a, torch::Tensor b,
    torch::Tensor c, torch::Tensor d,
    torch::Tensor bias
) {
    const c10::cuda::CUDAGuard guard(a.device());

    a = a.contiguous(at::MemoryFormat::ChannelsLast3d);
    b = b.contiguous(at::MemoryFormat::ChannelsLast3d);
    c = c.contiguous(at::MemoryFormat::ChannelsLast3d);
    d = d.contiguous(at::MemoryFormat::ChannelsLast3d);
    bias = bias.contiguous();

    const int depth = a.size(2);
    const int height = a.size(3);
    const int width = a.size(4);
    const int od = depth / 3;
    const int oh = height / 3;
    const int ow = width / 3;

    auto output = torch::empty({a.size(0), 1, od, oh, ow}, a.options());

    if (output.numel() > 0) {
        pool_phases_kernel<<<
            static_cast<unsigned int>(output.numel()), 128, 0,
            at::cuda::getCurrentCUDAStream()>>>(
                reinterpret_cast<const float4*>(a.data_ptr<float>()),
                reinterpret_cast<const float4*>(b.data_ptr<float>()),
                reinterpret_cast<const float4*>(c.data_ptr<float>()),
                reinterpret_cast<const float4*>(d.data_ptr<float>()),
                reinterpret_cast<const float4*>(bias.data_ptr<float>()),
                output.data_ptr<float>(),
                depth, height, width, od, oh, ow
            );
        C10_CUDA_KERNEL_LAUNCH_CHECK();
    }
    return output;
}
"""

_ops = load_inline(
    name="polyphase_conv3d_split_depth_height_v5",
    cpp_sources=_cpp_source,
    cuda_sources=_cuda_source,
    functions=["pack_phases_cuda", "pool_phases_cuda"],
    extra_cflags=["-O3"],
    extra_cuda_cflags=["-O3"],
    verbose=False,
)


class ModelNew(nn.Module):
    def __init__(self, in_channels, out_channels, kernel_size, stride, padding):
        super().__init__()
        self.conv_transpose = nn.ConvTranspose3d(
            in_channels,
            out_channels,
            kernel_size,
            stride=stride,
            padding=padding,
        )
        self.max_pool1 = nn.MaxPool3d(kernel_size=2)
        self.max_pool2 = nn.MaxPool3d(kernel_size=3)

    def forward(self, x):
        conv = self.conv_transpose
        use_polyphase = (
            x.is_cuda
            and x.dtype == torch.float32
            and conv.weight.dtype == torch.float32
            and conv.bias is not None
            and conv.bias.dtype == torch.float32
            and x.ndim == 5
            and 0 < x.size(0) <= 65535
            and x.size(1) == conv.in_channels
            and min(x.shape[2:]) >= 4
            and conv.out_channels == 64
            and conv.kernel_size == (5, 5, 5)
            and conv.stride == (2, 2, 2)
            and conv.padding == (2, 2, 2)
            and conv.output_padding == (0, 0, 0)
            and conv.dilation == (1, 1, 1)
            and conv.groups == 1
            and not torch.is_autocast_enabled()
        )

        if not use_polyphase:
            y = conv(x)
            return self.max_pool2(self.max_pool1(y)).sum(
                dim=1, keepdim=True
            )

        packed = _ops.pack_phases_cuda(x, conv.weight)
        a = F.conv3d(packed[0], packed[4])
        b = F.conv3d(packed[1], packed[5])
        c = F.conv3d(packed[2], packed[6])
        d = F.conv3d(packed[3], packed[7])
        return _ops.pool_phases_cuda(a, b, c, d, conv.bias)
```
Result of evaluating it:
The solution is correct on the test inputs. Mean runtime 3.71 ms; the PyTorch reference (with TF32 enabled) takes 14.6 ms; speedup 3.935x.
Profiler, top device kernels of one forward pass of your solution:
| device kernel | total device time (us) | calls |
|---|---|---|
| sm80_xmma_fprop_implicit_gemm_tf32f32_tf32f32_f32_nhwckrsc_nhwc_tilesize128x128x16_stage4_ | 2305.9 | 4 |
| pool_phases_kernel(float4 const*, float4 const*, float4 const*, float4 const*, float4 cons | 617.3 | 1 |
| void cudnn::engines_precompiled::convertTensor_kernel<float, float, float, (cudnnKernelDat | 451.3 | 8 |
| pack_input_kernel(float const*, float*, float*, float*, float*, int, int, int, int, int, i | 268.2 | 1 |
| pack_weight_kernel(float const*, float*, float*, float*, float*, int, long, long, long, lo | 8.9 | 1 |

The fastest correct solution so far (3.957x speedup) is:
```python
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.cpp_extension import load_inline


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

std::vector<torch::Tensor> pack_polyphase_cuda(
    torch::Tensor x, torch::Tensor weight);

torch::Tensor polyphase_pool_sum_cuda(
    torch::Tensor even, torch::Tensor odd, torch::Tensor bias);
"""

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

__global__ void pack_input_kernel(
    const float* __restrict__ x,
    float* __restrict__ even,
    float* __restrict__ odd,
    int channels,
    int depth, int height, int width,
    int pd, int ph, int pw,
    int64_t sn, int64_t sc,
    int64_t sd, int64_t sh, int64_t sw
) {
    __shared__ float tile[32][33];

    const int tx = threadIdx.x;
    const int ty = threadIdx.y;
    const int n = blockIdx.z;
    const int first_c = blockIdx.y * 32;
    const int first_s = blockIdx.x * 32;
    const int volume = pd * ph * pw;

    const int s = first_s + tx;
    const int iw = s % pw - 1;
    const int ih = (s / pw) % ph - 1;
    const int id = s / (pw * ph) - 1;
    const bool valid =
        s < volume && id >= 0 && id < depth &&
        ih >= 0 && ih < height && iw >= 0 && iw < width;

    #pragma unroll
    for (int j = 0; j < 32; j += 8) {
        const int c = first_c + ty + j;
        float value = 0.0f;
        if (valid && c < channels) {
            value = x[int64_t(n) * sn + int64_t(c) * sc +
                      int64_t(id) * sd + int64_t(ih) * sh +
                      int64_t(iw) * sw];
        }
        tile[ty + j][tx] = value;
    }

    __syncthreads();

    const int c = first_c + tx;
    #pragma unroll
    for (int j = 0; j < 32; j += 8) {
        const int os = first_s + ty + j;
        if (os < volume && c < channels) {
            const float value = tile[tx][ty + j];
            even[(int64_t(n) * volume + os) * channels + c] = value;

            if (os >= ph * pw) {
                const int odd_volume = (pd - 1) * ph * pw;
                odd[(int64_t(n) * odd_volume + os - ph * pw) *
                    channels + c] = value;
            }
        }
    }
}

__global__ void pack_weight_kernel(
    const float* __restrict__ weight,
    float* __restrict__ even,
    float* __restrict__ odd,
    int64_t even_count,
    int64_t total_count,
    int in_channels,
    int64_t si, int64_t so,
    int64_t sd, int64_t sh, int64_t sw
) {
    for (int64_t index = int64_t(blockIdx.x) * blockDim.x + threadIdx.x;
         index < total_count;
         index += int64_t(blockDim.x) * gridDim.x) {
        const bool is_odd = index >= even_count;
        const int64_t local = is_odd ? index - even_count : index;
        int64_t t = local;

        const int ic = t % in_channels;
        t /= in_channels;
        const int rw = t % 3;
        t /= 3;
        const int rh = t % 3;
        t /= 3;
        const int kd_size = is_odd ? 2 : 3;
        const int rd = t % kd_size;
        t /= kd_size;
        const int oc = t % 64;
        const int phase = t / 64;

        const int kd = (is_odd ? 3 : 4) - 2 * rd;
        const int kh = ((phase >> 1) & 1) + 4 - 2 * rh;
        const int kw = (phase & 1) + 4 - 2 * rw;

        float value = 0.0f;
        if (kh < 5 && kw < 5) {
            value = weight[int64_t(ic) * si + int64_t(oc) * so +
                           int64_t(kd) * sd + int64_t(kh) * sh +
                           int64_t(kw) * sw];
        }

        if (is_odd) {
            odd[local] = value;
        } else {
            even[local] = value;
        }
    }
}

std::vector<torch::Tensor> pack_polyphase_cuda(
    torch::Tensor x, torch::Tensor weight
) {
    const c10::cuda::CUDAGuard guard(x.device());

    TORCH_CHECK(x.is_cuda() && weight.is_cuda(), "Expected CUDA tensors");
    TORCH_CHECK(x.scalar_type() == at::kFloat &&
                weight.scalar_type() == at::kFloat,
                "Expected float32 tensors");
    TORCH_CHECK(x.device() == weight.device(), "Device mismatch");
    TORCH_CHECK(weight.size(1) == 64, "Expected 64 output channels");

    const int n = x.size(0);
    const int ic = x.size(1);
    const int d = x.size(2);
    const int h = x.size(3);
    const int w = x.size(4);

    const int pd = ((2 * d - 1) / 6) * 3 + 2;
    const int ph = ((2 * h - 1) / 6) * 3 + 2;
    const int pw = ((2 * w - 1) / 6) * 3 + 2;

    auto even_x = torch::empty({n, pd, ph, pw, ic}, x.options())
                      .permute({0, 4, 1, 2, 3});
    auto odd_x = torch::empty({n, pd - 1, ph, pw, ic}, x.options())
                     .permute({0, 4, 1, 2, 3});

    auto even_weight = torch::empty({256, 3, 3, 3, ic}, weight.options())
                           .permute({0, 4, 1, 2, 3});
    auto odd_weight = torch::empty({256, 2, 3, 3, ic}, weight.options())
                          .permute({0, 4, 1, 2, 3});

    const auto stream = at::cuda::getCurrentCUDAStream();
    const dim3 threads(32, 8);
    const dim3 blocks(
        (pd * ph * pw + 31) / 32,
        (ic + 31) / 32,
        n
    );

    pack_input_kernel<<<blocks, threads, 0, stream>>>(
        x.data_ptr<float>(),
        even_x.data_ptr<float>(), odd_x.data_ptr<float>(),
        ic, d, h, w, pd, ph, pw,
        x.stride(0), x.stride(1), x.stride(2),
        x.stride(3), x.stride(4)
    );

    const int64_t total_count = even_weight.numel() + odd_weight.numel();
    const int weight_blocks = static_cast<int>(
        std::min<int64_t>((total_count + 255) / 256, 65535)
    );

    pack_weight_kernel<<<weight_blocks, 256, 0, stream>>>(
        weight.data_ptr<float>(),
        even_weight.data_ptr<float>(), odd_weight.data_ptr<float>(),
        even_weight.numel(), total_count, ic,
        weight.stride(0), weight.stride(1), weight.stride(2),
        weight.stride(3), weight.stride(4)
    );

    C10_CUDA_KERNEL_LAUNCH_CHECK();
    return {even_x, odd_x, even_weight, odd_weight};
}

__device__ __forceinline__ float max_nan(float a, float b) {
    return isnan(a) ? a : (isnan(b) ? b : fmaxf(a, b));
}

__device__ __forceinline__ float4 max4(float4 a, float4 b) {
    return make_float4(
        max_nan(a.x, b.x),
        max_nan(a.y, b.y),
        max_nan(a.z, b.z),
        max_nan(a.w, b.w)
    );
}

__global__ void polyphase_pool_sum_kernel(
    const float4* __restrict__ even,
    const float4* __restrict__ odd,
    const float4* __restrict__ bias,
    float* __restrict__ output,
    int depth, int height, int width,
    int od, int oh, int ow
) {
    __shared__ float4 partial[4][16];

    const int tid = threadIdx.x;
    const int lane = tid & 31;
    const int warp = tid >> 5;

    const int index = blockIdx.x;
    const int output_volume = od * oh * ow;
    const int n = index / output_volume;

    int s = index % output_volume;
    const int w = s % ow;
    s /= ow;
    const int h = s % oh;
    const int d = s / oh;

    const int64_t origin =
        ((int64_t(n) * depth + 3 * d) * height + 3 * h) * width +
        3 * w;

    const float4* base =
        (tid < 64 ? even : odd) + origin * 64 + (tid & 63);

    float4 maximum = make_float4(
        -INFINITY, -INFINITY, -INFINITY, -INFINITY
    );

    #pragma unroll
    for (int z = 0; z < 3; ++z) {
        #pragma unroll
        for (int y = 0; y < 3; ++y) {
            #pragma unroll
            for (int x = 0; x < 3; ++x) {
                const int64_t offset =
                    (int64_t(z) * height * width + y * width + x) * 64;
                maximum = max4(maximum, base[offset]);
            }
        }
    }

    float4 paired;
    paired.x = __shfl_xor_sync(0xffffffff, maximum.x, 16);
    paired.y = __shfl_xor_sync(0xffffffff, maximum.y, 16);
    paired.z = __shfl_xor_sync(0xffffffff, maximum.z, 16);
    paired.w = __shfl_xor_sync(0xffffffff, maximum.w, 16);
    maximum = max4(maximum, paired);

    if (lane < 16) {
        partial[warp][lane] = maximum;
    }
    __syncthreads();

    if (tid < 32) {
        float sum = 0.0f;

        if (tid < 16) {
            float4 pooled = max4(
                max4(partial[0][tid], partial[1][tid]),
                max4(partial[2][tid], partial[3][tid])
            );
            const float4 b = bias[tid];

            pooled.x += b.x;
            pooled.y += b.y;
            pooled.z += b.z;
            pooled.w += b.w;
            sum = (pooled.x + pooled.y) + (pooled.z + pooled.w);
        }

        #pragma unroll
        for (int offset = 8; offset > 0; offset >>= 1) {
            sum += __shfl_down_sync(0xffffffff, sum, offset);
        }

        if (tid == 0) {
            output[index] = sum;
        }
    }
}

torch::Tensor polyphase_pool_sum_cuda(
    torch::Tensor even, torch::Tensor odd, torch::Tensor bias
) {
    const c10::cuda::CUDAGuard guard(even.device());

    TORCH_CHECK(even.scalar_type() == at::kFloat &&
                odd.scalar_type() == at::kFloat &&
                bias.scalar_type() == at::kFloat,
                "Expected float32 tensors");
    TORCH_CHECK(even.device() == odd.device() &&
                even.device() == bias.device(), "Device mismatch");
    TORCH_CHECK(even.sizes() == odd.sizes(), "Phase shape mismatch");

    even = even.contiguous(at::MemoryFormat::ChannelsLast3d);
    odd = odd.contiguous(at::MemoryFormat::ChannelsLast3d);
    bias = bias.contiguous();

    const int d = even.size(2);
    const int h = even.size(3);
    const int w = even.size(4);
    const int od = d / 3;
    const int oh = h / 3;
    const int ow = w / 3;

    auto output = torch::empty(
        {even.size(0), 1, od, oh, ow}, even.options()
    );

    if (output.numel() != 0) {
        polyphase_pool_sum_kernel
            <<<static_cast<unsigned int>(output.numel()), 128, 0,
               at::cuda::getCurrentCUDAStream()>>>(
                reinterpret_cast<const float4*>(even.data_ptr<float>()),
                reinterpret_cast<const float4*>(odd.data_ptr<float>()),
                reinterpret_cast<const float4*>(bias.data_ptr<float>()),
                output.data_ptr<float>(),
                d, h, w, od, oh, ow
            );
        C10_CUDA_KERNEL_LAUNCH_CHECK();
    }

    return output;
}
"""

_ops = load_inline(
    name="polyphase_conv3d_split_depth_v4",
    cpp_sources=_cpp_source,
    cuda_sources=_cuda_source,
    functions=["pack_polyphase_cuda", "polyphase_pool_sum_cuda"],
    extra_cflags=["-O3"],
    extra_cuda_cflags=["-O3"],
    verbose=False,
)


class ModelNew(nn.Module):
    def __init__(self, in_channels, out_channels, kernel_size, stride, padding):
        super().__init__()
        self.conv_transpose = nn.ConvTranspose3d(
            in_channels,
            out_channels,
            kernel_size,
            stride=stride,
            padding=padding,
        )
        self.max_pool1 = nn.MaxPool3d(kernel_size=2)
        self.max_pool2 = nn.MaxPool3d(kernel_size=3)

    def forward(self, x):
        conv = self.conv_transpose
        use_polyphase = (
            x.is_cuda
            and x.dtype == torch.float32
            and conv.weight.dtype == torch.float32
            and conv.bias is not None
            and conv.bias.dtype == torch.float32
            and x.ndim == 5
            and 0 < x.size(0) <= 65535
            and min(x.shape[2:]) >= 4
            and conv.out_channels == 64
            and conv.kernel_size == (5, 5, 5)
            and conv.stride == (2, 2, 2)
            and conv.padding == (2, 2, 2)
            and conv.output_padding == (0, 0, 0)
            and conv.dilation == (1, 1, 1)
            and conv.groups == 1
            and not torch.is_autocast_enabled()
        )

        if not use_polyphase:
            y = conv(x)
            return self.max_pool2(self.max_pool1(y)).sum(
                dim=1, keepdim=True
            )

        even_x, odd_x, even_weight, odd_weight = _ops.pack_polyphase_cuda(
            x, conv.weight
        )
        even = F.conv3d(even_x, even_weight)
        odd = F.conv3d(odd_x, odd_weight)
        return _ops.polyphase_pool_sum_cuda(even, odd, conv.bias)
```

Write an improved complete ModelNew: fix any error, and if the solution is already correct, make it faster. Output the new code in one ```python codeblock. Just the model code, no other text, and NO testing code.
