import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import random
import torchvision
import torch.nn.parallel
import torch.optim
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 200704 % 64
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 50176 % 128
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 6272 % 256
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_3(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 784 % 512
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_4(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 98 % 512
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_relu_5(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x2 = xindex
    x0 = xindex % 4096
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x2, tmp4, None)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
        primals_13, primals_14, primals_15, primals_16, primals_17,
        primals_18, primals_19, primals_20, primals_21, primals_22, primals_23
        ) = args
    args.clear()
    assert_size_stride(primals_1, (4, 3, 16, 112, 112), (602112, 200704, 
        12544, 112, 1))
    assert_size_stride(primals_2, (64, 3, 3, 3, 3), (81, 27, 9, 3, 1))
    assert_size_stride(primals_3, (64,), (1,))
    assert_size_stride(primals_4, (128, 64, 3, 3, 3), (1728, 27, 9, 3, 1))
    assert_size_stride(primals_5, (128,), (1,))
    assert_size_stride(primals_6, (256, 128, 3, 3, 3), (3456, 27, 9, 3, 1))
    assert_size_stride(primals_7, (256,), (1,))
    assert_size_stride(primals_8, (256, 256, 3, 3, 3), (6912, 27, 9, 3, 1))
    assert_size_stride(primals_9, (256,), (1,))
    assert_size_stride(primals_10, (512, 256, 3, 3, 3), (6912, 27, 9, 3, 1))
    assert_size_stride(primals_11, (512,), (1,))
    assert_size_stride(primals_12, (512, 512, 3, 3, 3), (13824, 27, 9, 3, 1))
    assert_size_stride(primals_13, (512,), (1,))
    assert_size_stride(primals_14, (512, 512, 3, 3, 3), (13824, 27, 9, 3, 1))
    assert_size_stride(primals_15, (512,), (1,))
    assert_size_stride(primals_16, (512, 512, 3, 3, 3), (13824, 27, 9, 3, 1))
    assert_size_stride(primals_17, (512,), (1,))
    assert_size_stride(primals_18, (4096, 8192), (8192, 1))
    assert_size_stride(primals_19, (4096,), (1,))
    assert_size_stride(primals_20, (4096, 4096), (4096, 1))
    assert_size_stride(primals_21, (4096,), (1,))
    assert_size_stride(primals_22, (174, 4096), (4096, 1))
    assert_size_stride(primals_23, (174,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 
            1, 1), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 64, 16, 112, 112), (12845056, 200704, 
            12544, 112, 1))
        buf1 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_convolution_relu_0[grid(51380224)](buf1, primals_3,
            51380224, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_3
        buf2 = torch.ops.aten.max_pool3d_with_indices.default(buf1, [1, 2, 
            2], [1, 2, 2])
        buf3 = buf2[0]
        buf4 = buf2[1]
        del buf2
        buf5 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1, 1),
            padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf5, (4, 128, 16, 56, 56), (6422528, 50176, 
            3136, 56, 1))
        buf6 = buf5
        del buf5
        triton_poi_fused_convolution_relu_1[grid(25690112)](buf6, primals_5,
            25690112, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_5
        buf7 = torch.ops.aten.max_pool3d_with_indices.default(buf6, [2, 2, 
            2], [2, 2, 2])
        buf8 = buf7[0]
        buf9 = buf7[1]
        del buf7
        buf10 = extern_kernels.convolution(buf8, primals_6, stride=(1, 1, 1
            ), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf10, (4, 256, 8, 28, 28), (1605632, 6272, 784,
            28, 1))
        buf11 = buf10
        del buf10
        triton_poi_fused_convolution_relu_2[grid(6422528)](buf11, primals_7,
            6422528, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_7
        buf12 = extern_kernels.convolution(buf11, primals_8, stride=(1, 1, 
            1), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf12, (4, 256, 8, 28, 28), (1605632, 6272, 784,
            28, 1))
        buf13 = buf12
        del buf12
        triton_poi_fused_convolution_relu_2[grid(6422528)](buf13, primals_9,
            6422528, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_9
        buf14 = torch.ops.aten.max_pool3d_with_indices.default(buf13, [2, 2,
            2], [2, 2, 2])
        buf15 = buf14[0]
        buf16 = buf14[1]
        del buf14
        buf17 = extern_kernels.convolution(buf15, primals_10, stride=(1, 1,
            1), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf17, (4, 512, 4, 14, 14), (401408, 784, 196, 
            14, 1))
        buf18 = buf17
        del buf17
        triton_poi_fused_convolution_relu_3[grid(1605632)](buf18,
            primals_11, 1605632, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_11
        buf19 = extern_kernels.convolution(buf18, primals_12, stride=(1, 1,
            1), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf19, (4, 512, 4, 14, 14), (401408, 784, 196, 
            14, 1))
        buf20 = buf19
        del buf19
        triton_poi_fused_convolution_relu_3[grid(1605632)](buf20,
            primals_13, 1605632, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_13
        buf21 = torch.ops.aten.max_pool3d_with_indices.default(buf20, [2, 2,
            2], [2, 2, 2])
        buf22 = buf21[0]
        buf23 = buf21[1]
        del buf21
        buf24 = extern_kernels.convolution(buf22, primals_14, stride=(1, 1,
            1), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf24, (4, 512, 2, 7, 7), (50176, 98, 49, 7, 1))
        buf25 = buf24
        del buf24
        triton_poi_fused_convolution_relu_4[grid(200704)](buf25, primals_15,
            200704, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_15
        buf26 = extern_kernels.convolution(buf25, primals_16, stride=(1, 1,
            1), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf26, (4, 512, 2, 7, 7), (50176, 98, 49, 7, 1))
        buf27 = buf26
        del buf26
        triton_poi_fused_convolution_relu_4[grid(200704)](buf27, primals_17,
            200704, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_17
        buf28 = torch.ops.aten.max_pool3d_with_indices.default(buf27, [2, 2,
            2], [2, 2, 2], [0, 1, 1])
        buf29 = buf28[0]
        buf30 = buf28[1]
        del buf28
        buf31 = empty_strided_cuda((4, 4096), (4096, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf29, (4, 8192), (8192, 1), 0
            ), reinterpret_tensor(primals_18, (8192, 4096), (1, 8192), 0),
            out=buf31)
        buf32 = buf31
        del buf31
        triton_poi_fused_relu_5[grid(16384)](buf32, primals_19, 16384,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_19
        buf33 = empty_strided_cuda((4, 4096), (4096, 1), torch.float32)
        extern_kernels.mm(buf32, reinterpret_tensor(primals_20, (4096, 4096
            ), (1, 4096), 0), out=buf33)
        buf34 = buf33
        del buf33
        triton_poi_fused_relu_5[grid(16384)](buf34, primals_21, 16384,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_21
        buf35 = empty_strided_cuda((4, 174), (174, 1), torch.float32)
        extern_kernels.addmm(primals_23, buf34, reinterpret_tensor(
            primals_22, (4096, 174), (1, 4096), 0), alpha=1, beta=1, out=buf35)
        del primals_23
    return (buf35, primals_2, primals_4, primals_6, primals_8, primals_10,
        primals_12, primals_14, primals_16, primals_1, buf1, buf3, buf4,
        buf6, buf8, buf9, buf11, buf13, buf15, buf16, buf18, buf20, buf22,
        buf23, buf25, buf27, buf30, reinterpret_tensor(buf29, (4, 8192), (
        8192, 1), 0), buf32, buf34, primals_22, primals_20, primals_18)


class GroupMultiScaleCrop(object):

    def __init__(self, input_size, scales=None, max_distort=1, fix_crop=
        True, more_fix_crop=True):
        self.scales = scales if scales is not None else [1, 875, 0.75, 0.66]
        self.max_distort = max_distort
        self.fix_crop = fix_crop
        self.more_fix_crop = more_fix_crop
        self.input_size = input_size if not isinstance(input_size, int) else [
            input_size, input_size]
        self.interpolation = Image.BILINEAR

    def __call__(self, img_group):
        im_size = img_group[0].size
        crop_w, crop_h, offset_w, offset_h = self._sample_crop_size(im_size)
        crop_img_group = [img.crop((offset_w, offset_h, offset_w + crop_w, 
            offset_h + crop_h)) for img in img_group]
        ret_img_group = [img.resize((self.input_size[0], self.input_size[1]
            ), self.interpolation) for img in crop_img_group]
        return ret_img_group

    def _sample_crop_size(self, im_size):
        image_w, image_h = im_size[0], im_size[1]
        base_size = min(image_w, image_h)
        crop_sizes = [int(base_size * x) for x in self.scales]
        crop_h = [(self.input_size[1] if abs(x - self.input_size[1]) < 3 else
            x) for x in crop_sizes]
        crop_w = [(self.input_size[0] if abs(x - self.input_size[0]) < 3 else
            x) for x in crop_sizes]
        pairs = []
        for i, h in enumerate(crop_h):
            for j, w in enumerate(crop_w):
                if abs(i - j) <= self.max_distort:
                    pairs.append((w, h))
        crop_pair = random.choice(pairs)
        if not self.fix_crop:
            w_offset = random.randint(0, image_w - crop_pair[0])
            h_offset = random.randint(0, image_h - crop_pair[1])
        else:
            w_offset, h_offset = self._sample_fix_offset(image_w, image_h,
                crop_pair[0], crop_pair[1])
        return crop_pair[0], crop_pair[1], w_offset, h_offset

    def _sample_fix_offset(self, image_w, image_h, crop_w, crop_h):
        offsets = self.fill_fix_offset(self.more_fix_crop, image_w, image_h,
            crop_w, crop_h)
        return random.choice(offsets)

    @staticmethod
    def fill_fix_offset(more_fix_crop, image_w, image_h, crop_w, crop_h):
        w_step = (image_w - crop_w) // 4
        h_step = (image_h - crop_h) // 4
        ret = list()
        ret.append((0, 0))
        ret.append((4 * w_step, 0))
        ret.append((0, 4 * h_step))
        ret.append((4 * w_step, 4 * h_step))
        ret.append((2 * w_step, 2 * h_step))
        if more_fix_crop:
            ret.append((0, 2 * h_step))
            ret.append((4 * w_step, 2 * h_step))
            ret.append((2 * w_step, 4 * h_step))
            ret.append((2 * w_step, 0 * h_step))
            ret.append((1 * w_step, 1 * h_step))
            ret.append((3 * w_step, 1 * h_step))
            ret.append((1 * w_step, 3 * h_step))
            ret.append((3 * w_step, 3 * h_step))
        return ret


class GroupRandomHorizontalFlip(object):
    """Randomly horizontally flips the given PIL.Image with a probability of 0.5
    """

    def __init__(self, is_flow=False):
        self.is_flow = is_flow

    def __call__(self, img_group, is_flow=False):
        v = random.random()
        if v < 0.5:
            ret = [img.transpose(Image.FLIP_LEFT_RIGHT) for img in img_group]
            if self.is_flow:
                for i in range(0, len(ret), 2):
                    ret[i] = ImageOps.invert(ret[i])
            return ret
        else:
            return img_group


class C3DNew(nn.Module):

    def __init__(self):
        super(C3DNew, self).__init__()
        self.modality = 'RGB'
        self.input_size = 112
        self.input_mean = [104, 117, 128]
        self.input_std = [1]
        self.conv1 = nn.Conv3d(3, 64, kernel_size=(3, 3, 3), padding=(1, 1, 1))
        self.pool1 = nn.MaxPool3d(kernel_size=(1, 2, 2), stride=(1, 2, 2))
        self.conv2 = nn.Conv3d(64, 128, kernel_size=(3, 3, 3), padding=(1, 
            1, 1))
        self.pool2 = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2))
        self.conv3a = nn.Conv3d(128, 256, kernel_size=(3, 3, 3), padding=(1,
            1, 1))
        self.conv3b = nn.Conv3d(256, 256, kernel_size=(3, 3, 3), padding=(1,
            1, 1))
        self.pool3 = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2))
        self.conv4a = nn.Conv3d(256, 512, kernel_size=(3, 3, 3), padding=(1,
            1, 1))
        self.conv4b = nn.Conv3d(512, 512, kernel_size=(3, 3, 3), padding=(1,
            1, 1))
        self.pool4 = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2))
        self.conv5a = nn.Conv3d(512, 512, kernel_size=(3, 3, 3), padding=(1,
            1, 1))
        self.conv5b = nn.Conv3d(512, 512, kernel_size=(3, 3, 3), padding=(1,
            1, 1))
        self.pool5 = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2),
            padding=(0, 1, 1))
        self.fc6 = nn.Linear(8192, 4096)
        self.fc7 = nn.Linear(4096, 4096)
        self.fc8_new = nn.Linear(4096, 174)
        self.dropout = nn.Dropout(p=0.5)
        self.relu = nn.ReLU()
        self.softmax = nn.Softmax()

    def partialBN(self, enable):
        pass

    @property
    def crop_size(self):
        return self.input_size

    @property
    def scale_size(self):
        return self.input_size * 128 // 112

    def get_augmentation(self):
        if self.modality == 'RGB':
            return torchvision.transforms.Compose([GroupMultiScaleCrop(self
                .input_size, [1, 0.875, 0.75, 0.66]),
                GroupRandomHorizontalFlip(is_flow=False)])

    def forward(self, input_0):
        primals_2 = self.conv1.weight
        primals_3 = self.conv1.bias
        primals_4 = self.conv2.weight
        primals_5 = self.conv2.bias
        primals_6 = self.conv3a.weight
        primals_7 = self.conv3a.bias
        primals_8 = self.conv3b.weight
        primals_9 = self.conv3b.bias
        primals_10 = self.conv4a.weight
        primals_11 = self.conv4a.bias
        primals_12 = self.conv4b.weight
        primals_13 = self.conv4b.bias
        primals_14 = self.conv5a.weight
        primals_15 = self.conv5a.bias
        primals_16 = self.conv5b.weight
        primals_17 = self.conv5b.bias
        primals_18 = self.fc6.weight
        primals_19 = self.fc6.bias
        primals_20 = self.fc7.weight
        primals_21 = self.fc7.bias
        primals_22 = self.fc8_new.weight
        primals_23 = self.fc8_new.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12, primals_13, primals_14,
            primals_15, primals_16, primals_17, primals_18, primals_19,
            primals_20, primals_21, primals_22, primals_23])
        return output[0]


Measured latency_ms: 9.127666