# AOT ID: ['0_forward']
from ctypes import c_void_p, c_long, c_int
import torch
import math
import random
import os
import tempfile
from math import inf, nan
from torch._inductor.hooks import run_intermediate_hooks
from torch._inductor.utils import maybe_profile
from torch._inductor.codegen.memory_planning import _align as align
from torch import device, empty_strided
from torch._inductor.async_compile import AsyncCompile
from torch._inductor.select_algorithm import extern_kernels
from torch._inductor.codegen.multi_kernel import MultiKernelCall
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid, split_scan_grid, grid_combo_kernels, start_graph, end_graph
from torch._C import _cuda_getCurrentRawStream as get_raw_stream

aten = torch.ops.aten
inductor_ops = torch.ops.inductor
_quantized = torch.ops._quantized
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cpu = torch._C._dynamo.guards._empty_strided_cpu
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
empty_strided_xpu = torch._C._dynamo.guards._empty_strided_xpu
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
alloc_from_pool = torch.ops.inductor._alloc_from_pool
async_compile = AsyncCompile()


# kernel path: runs/run_shard_1/inductor_cache/kq/ckqglep2uxxmtpvso6erxkbhcljhsx4d2chzqc2ps72gtorqejiz.py
# Topologically Sorted Source Nodes: [Q], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   Q => amax, exp, sub
# Graph fragment:
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%primals_1, [-3], True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%primals_1, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub,), kwargs = {})
triton_poi_fused__softmax_0 = async_compile.triton('triton_poi_fused__softmax_0', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 16
    x2 = (xindex // 64)
    tmp0 = tl.load(in_ptr0 + (x3), xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (16 + x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (32 + x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (48 + x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + (x3), tmp9, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/tv/ctvxncyzu7pcogaepwuywlkrtigk7ke4tdgbkdfypvu626jp7xvj.py
# Topologically Sorted Source Nodes: [Q], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   Q => div, sum_1
# Graph fragment:
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [-3], True), kwargs = {})
#   %div : [num_users=3] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp, %sum_1), kwargs = {})
triton_poi_fused__softmax_1 = async_compile.triton('triton_poi_fused__softmax_1', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 16
    x2 = (xindex // 64)
    tmp0 = tl.load(in_ptr0 + (x3), xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (16 + x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (32 + x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (48 + x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + (x3), tmp8, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/uu/cuuswrsugg2cgvh4d6zimoyuivw2uiokmvkofctueepl5aaluwha.py
# Topologically Sorted Source Nodes: [sub, pow_1, K, neg, K_1, sub_1, pow_2, K_2, neg_1, K_3], Original ATen: [aten.sub, aten.pow, aten.div, aten.neg, aten.exp]
# Source node to ATen node mapping:
#   K => div_1
#   K_1 => exp_1
#   K_2 => div_3
#   K_3 => exp_2
#   neg => neg
#   neg_1 => neg_1
#   pow_1 => pow_1
#   pow_2 => pow_2
#   sub => sub_1
#   sub_1 => sub_2
# Graph fragment:
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%view, %unsqueeze), kwargs = {})
#   %pow_1 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%sub_1, 2), kwargs = {})
#   %div_1 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%pow_1, 4.5), kwargs = {})
#   %neg : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%div_1,), kwargs = {})
#   %exp_1 : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%neg,), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%view_2, %unsqueeze), kwargs = {})
#   %pow_2 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%sub_2, 2), kwargs = {})
#   %div_3 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%pow_2, 12.5), kwargs = {})
#   %neg_1 : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%div_3,), kwargs = {})
#   %exp_2 : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%neg_1,), kwargs = {})
triton_poi_fused_div_exp_neg_pow_sub_2 = async_compile.triton('triton_poi_fused_div_exp_neg_pow_sub_2', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[2048], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_div_exp_neg_pow_sub_2', 'mutated_arg_names': ['in_out_ptr0', 'in_out_ptr1'], 'no_x_dim': False, 'num_load': 3, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_div_exp_neg_pow_sub_2(in_out_ptr0, in_out_ptr1, in_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 2048
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x0 = xindex % 16
    x2 = (xindex // 128)
    tmp0 = tl.load(in_out_ptr0 + (x3), None)
    tmp1 = tl.load(in_ptr0 + (x0 + (16*x2)), None, eviction_policy='evict_last')
    tmp8 = tl.load(in_out_ptr1 + (x3), None)
    tmp2 = tmp0 - tmp1
    tmp3 = tmp2 * tmp2
    tmp4 = 0.2222222222222222
    tmp5 = tmp3 * tmp4
    tmp6 = -tmp5
    tmp7 = tl_math.exp(tmp6)
    tmp9 = tmp8 - tmp1
    tmp10 = tmp9 * tmp9
    tmp11 = 0.08
    tmp12 = tmp10 * tmp11
    tmp13 = -tmp12
    tmp14 = tl_math.exp(tmp13)
    tl.store(in_out_ptr0 + (x3), tmp7, None)
    tl.store(in_out_ptr1 + (x3), tmp14, None)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/b6/cb6jyptfhv2kgl32c3vscr7txzqq2opkxy6obbbpyp65cbqxksc5.py
# Topologically Sorted Source Nodes: [norm_weight, norm_weight_1], Original ATen: [aten.mul, aten.sum]
# Source node to ATen node mapping:
#   norm_weight => mul_2
#   norm_weight_1 => sum_3
# Graph fragment:
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%exp_1, %squeeze), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_2, [2]), kwargs = {})
triton_per_fused_mul_sum_3 = async_compile.triton('triton_per_fused_mul_sum_3', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.persistent_reduction(
    size_hints=[256, 8],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_mul_sum_3', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 1, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False}
)
@triton.jit
def triton_per_fused_mul_sum_3(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    rnumel = 8
    RBLOCK: tl.constexpr = 8
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r2 = rindex
    x0 = xindex % 16
    x1 = (xindex // 16)
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + (16*r2) + (128*x1)), xmask, other=0.0)
    tmp1 = tl.load(in_ptr1 + (r2), None, eviction_policy='evict_last')
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(xmask, tmp3, 0)
    tmp6 = tl.sum(tmp5, 1)[:, None]
    tl.store(out_ptr0 + (x3), tmp6, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/jo/cjoxdtj62mwet74fwdxrqoe2a3ij7qfjuseel6p3muzufgn2i5w7.py
# Topologically Sorted Source Nodes: [Qj, Qj_1, Qtilde, Qtilde_1], Original ATen: [aten.mul, aten.sum, aten.div]
# Source node to ATen node mapping:
#   Qj => mul
#   Qj_1 => mul_1
#   Qtilde => sum_2
#   Qtilde_1 => div_2
# Graph fragment:
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%unsqueeze_1, %unsqueeze_2), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul, %primals_5), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_1, [3]), kwargs = {})
#   %div_2 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%sum_2, %unsqueeze_3), kwargs = {})
triton_per_fused_div_mul_sum_4 = async_compile.triton('triton_per_fused_div_mul_sum_4', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.persistent_reduction(
    size_hints=[1024, 8],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32', 6: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_div_mul_sum_4', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 4, 'num_reduction': 1, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False}
)
@triton.jit
def triton_per_fused_div_mul_sum_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr1, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 1024
    rnumel = 8
    RBLOCK: tl.constexpr = 8
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r4 = rindex
    x0 = xindex % 16
    x5 = (xindex // 64)
    x1 = (xindex // 16) % 4
    x3 = (xindex // 256)
    x6 = xindex
    x2 = (xindex // 64) % 4
    x7 = xindex % 64
    tmp0 = tl.load(in_ptr0 + (x0 + (16*r4) + (128*x5)), xmask, eviction_policy='evict_last', other=0.0)
    tmp1 = tl.load(in_ptr1 + (x0 + (16*r4) + (128*x1) + (512*x3)), xmask, eviction_policy='evict_last', other=0.0)
    tmp3 = tl.load(in_ptr2 + (r4), None, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr3 + (x0 + (16*x5)), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 * tmp1
    tmp4 = tmp2 * tmp3
    tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
    tmp7 = tl.where(xmask, tmp5, 0)
    tmp8 = tl.sum(tmp7, 1)[:, None]
    tmp10 = tmp8 / tmp9
    tl.store(out_ptr1 + (x2 + (9*x7) + (576*x3)), tmp10, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/cf/ccfldygqg6amwgjphthp56bocseulat4ga4juddns7ltma7vu3bk.py
# Topologically Sorted Source Nodes: [Qj_2, Qj_3, Qtilde_2, Qtilde_3], Original ATen: [aten.mul, aten.sum, aten.div]
# Source node to ATen node mapping:
#   Qj_2 => mul_3
#   Qj_3 => mul_4
#   Qtilde_2 => sum_4
#   Qtilde_3 => div_4
# Graph fragment:
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%unsqueeze_5, %unsqueeze_6), kwargs = {})
#   %mul_4 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_3, %primals_8), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_4, [3]), kwargs = {})
#   %div_4 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%sum_4, %unsqueeze_7), kwargs = {})
triton_per_fused_div_mul_sum_5 = async_compile.triton('triton_per_fused_div_mul_sum_5', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.persistent_reduction(
    size_hints=[1024, 8],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32', 6: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 5), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_div_mul_sum_5', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 4, 'num_reduction': 1, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False}
)
@triton.jit
def triton_per_fused_div_mul_sum_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr1, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 1024
    rnumel = 8
    RBLOCK: tl.constexpr = 8
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r4 = rindex
    x0 = xindex % 16
    x5 = (xindex // 64)
    x1 = (xindex // 16) % 4
    x3 = (xindex // 256)
    x6 = xindex
    x2 = (xindex // 64) % 4
    x7 = xindex % 64
    tmp0 = tl.load(in_ptr0 + (x0 + (16*r4) + (128*x5)), xmask, eviction_policy='evict_last', other=0.0)
    tmp1 = tl.load(in_ptr1 + (x0 + (16*r4) + (128*x1) + (512*x3)), xmask, eviction_policy='evict_last', other=0.0)
    tmp3 = tl.load(in_ptr2 + (r4), None, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr3 + (x0 + (16*x5)), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 * tmp1
    tmp4 = tmp2 * tmp3
    tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
    tmp7 = tl.where(xmask, tmp5, 0)
    tmp8 = tl.sum(tmp7, 1)[:, None]
    tmp10 = tmp8 / tmp9
    tl.store(out_ptr1 + (x2 + (9*x7) + (576*x3)), tmp10, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/3u/c3uwcp4dydpnkllc4ygp7lxk23ckbpt2jvvs5lymfxxwrje227hx.py
# Topologically Sorted Source Nodes: [new_ones, norm_weight_4], Original ATen: [aten.new_ones, aten.convolution]
# Source node to ATen node mapping:
#   new_ones => full_default
#   norm_weight_4 => convolution_5
# Graph fragment:
#   %full_default : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([4, 4, 4, 4], 1), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %convolution_5 : [num_users=9] = call_function[target=torch.ops.aten.convolution.default](args = (%full_default, %primals_9, None, [1, 1], [1, 1], [1, 1], False, [0, 0], 4), kwargs = {})
triton_poi_fused_convolution_new_ones_6 = async_compile.triton('triton_poi_fused_convolution_new_ones_6', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_convolution_new_ones_6', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 0, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_convolution_new_ones_6(out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = 1.0
    tl.store(out_ptr0 + (x0), tmp0, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/vs/cvscsilggj7ydsny5qvix74zfntkuh5e4qwlwz444rb3agrxjq6t.py
# Topologically Sorted Source Nodes: [Qtilde_6], Original ATen: [aten.cat]
# Source node to ATen node mapping:
#   Qtilde_6 => cat
# Graph fragment:
#   %cat : [num_users=2] = call_function[target=torch.ops.aten.cat.default](args = ([%div_2, %div_4, %unsqueeze_8], 1), kwargs = {})
triton_poi_fused_cat_7 = async_compile.triton('triton_poi_fused_cat_7', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_cat_7', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_cat_7(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (x0), xmask)
    tmp1 = tl.load(in_ptr1 + (x0), xmask)
    tmp2 = tmp0 / tmp1
    tl.store(out_ptr0 + (9*x0), tmp2, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/7u/c7uwdjw7xkyqaw7f6hgxuxnwpukxp2v5bnrtsqyx3jh5nt3gflfd.py
# Topologically Sorted Source Nodes: [Qtilde_6], Original ATen: [aten.cat]
# Source node to ATen node mapping:
#   Qtilde_6 => cat
# Graph fragment:
#   %cat : [num_users=2] = call_function[target=torch.ops.aten.cat.default](args = ([%div_2, %div_4, %unsqueeze_8], 1), kwargs = {})
triton_poi_fused_cat_8 = async_compile.triton('triton_poi_fused_cat_8', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[64, 64], tile_hint=TileHint.SQUARE,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_cat_8', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_cat_8(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK : tl.constexpr, XBLOCK : tl.constexpr):
    ynumel = 36
    xnumel = 64
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y0 = yindex % 9
    y1 = (yindex // 9)
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + (9*x2) + (576*y1)), xmask & ymask, eviction_policy='evict_last')
    tl.store(out_ptr0 + (x2 + (64*y3)), tmp0, xmask & ymask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/pp/cppoeykvpbroo2qknj2ku7p6xgmzpxe3s5ova2gmiblsjz434563.py
# Topologically Sorted Source Nodes: [Q_1, Q_2], Original ATen: [aten.mul, aten.sum]
# Source node to ATen node mapping:
#   Q_1 => mul_6
#   Q_2 => sum_6
# Graph fragment:
#   %mul_6 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%cat, %primals_10), kwargs = {})
#   %sum_6 : [num_users=3] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_6, [1]), kwargs = {})
triton_per_fused_mul_sum_9 = async_compile.triton('triton_per_fused_mul_sum_9', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.persistent_reduction(
    size_hints=[256, 16],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_mul_sum_9', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 1, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False}
)
@triton.jit
def triton_per_fused_mul_sum_9(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    rnumel = 9
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = rindex < rnumel
    r3 = rindex
    x2 = (xindex // 64)
    x4 = xindex % 64
    x1 = (xindex // 16) % 4
    x5 = xindex
    tmp0 = tl.load(in_ptr0 + (x4 + (64*r3) + (576*x2)), rmask & xmask, other=0.0)
    tmp1 = tl.load(in_ptr1 + (x1 + (4*r3)), rmask & xmask, eviction_policy='evict_last', other=0.0)
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(rmask & xmask, tmp3, 0)
    tmp6 = tl.sum(tmp5, 1)[:, None]
    tl.store(out_ptr0 + (x5), tmp6, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/vh/cvhzydbti757pjyuarlfiobfk4wfxqmjmt4sr5esprshamm6rgfv.py
# Topologically Sorted Source Nodes: [diag], Original ATen: [aten.diagonal_copy]
# Source node to ATen node mapping:
#   diag => diagonal_copy
# Graph fragment:
#   %diagonal_copy : [num_users=2] = call_function[target=torch.ops.aten.diagonal_copy.default](args = (%squeeze_2,), kwargs = {})
triton_poi_fused_diagonal_copy_10 = async_compile.triton('triton_poi_fused_diagonal_copy_10', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[4], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_diagonal_copy_10', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_diagonal_copy_10(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (5*x0), xmask, eviction_policy='evict_last')
    tl.store(out_ptr0 + (x0), tmp0, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/xt/cxticklgbzl3am5jduqxktfvcfqvjzycp3il4oj7ybpsepwgaamy.py
# Topologically Sorted Source Nodes: [mul_7, Q_3, Q_4, Q_5], Original ATen: [aten.mul, aten.sub, aten._softmax]
# Source node to ATen node mapping:
#   Q_3 => sub_3
#   Q_4 => sub_4
#   Q_5 => amax_1
#   mul_7 => mul_7
# Graph fragment:
#   %mul_7 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_6, %view_4), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%convolution_6, %mul_7), kwargs = {})
#   %sub_4 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%primals_1, %sub_3), kwargs = {})
#   %amax_1 : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%sub_4, [-3], True), kwargs = {})
triton_poi_fused__softmax_mul_sub_11 = async_compile.triton('triton_poi_fused__softmax_mul_sub_11', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_mul_sub_11', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 16, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__softmax_mul_sub_11(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x1 = (xindex // 16)
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + (64*x1)), xmask)
    tmp1 = tl.load(in_ptr1 + (x0 + (64*x1)), xmask)
    tmp2 = tl.load(in_ptr2 + (x0 + (64*x1)), xmask)
    tmp3 = tl.load(in_ptr3 + (0))
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK])
    tmp8 = tl.load(in_ptr0 + (16 + x0 + (64*x1)), xmask)
    tmp9 = tl.load(in_ptr1 + (16 + x0 + (64*x1)), xmask)
    tmp10 = tl.load(in_ptr2 + (16 + x0 + (64*x1)), xmask)
    tmp11 = tl.load(in_ptr3 + (1))
    tmp12 = tl.broadcast_to(tmp11, [XBLOCK])
    tmp17 = tl.load(in_ptr0 + (32 + x0 + (64*x1)), xmask)
    tmp18 = tl.load(in_ptr1 + (32 + x0 + (64*x1)), xmask)
    tmp19 = tl.load(in_ptr2 + (32 + x0 + (64*x1)), xmask)
    tmp20 = tl.load(in_ptr3 + (2))
    tmp21 = tl.broadcast_to(tmp20, [XBLOCK])
    tmp26 = tl.load(in_ptr0 + (48 + x0 + (64*x1)), xmask)
    tmp27 = tl.load(in_ptr1 + (48 + x0 + (64*x1)), xmask)
    tmp28 = tl.load(in_ptr2 + (48 + x0 + (64*x1)), xmask)
    tmp29 = tl.load(in_ptr3 + (3))
    tmp30 = tl.broadcast_to(tmp29, [XBLOCK])
    tmp5 = tmp2 * tmp4
    tmp6 = tmp1 - tmp5
    tmp7 = tmp0 - tmp6
    tmp13 = tmp10 * tmp12
    tmp14 = tmp9 - tmp13
    tmp15 = tmp8 - tmp14
    tmp16 = triton_helpers.maximum(tmp7, tmp15)
    tmp22 = tmp19 * tmp21
    tmp23 = tmp18 - tmp22
    tmp24 = tmp17 - tmp23
    tmp25 = triton_helpers.maximum(tmp16, tmp24)
    tmp31 = tmp28 * tmp30
    tmp32 = tmp27 - tmp31
    tmp33 = tmp26 - tmp32
    tmp34 = triton_helpers.maximum(tmp25, tmp33)
    tl.store(out_ptr0 + (x2), tmp34, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/6t/c6tc6tizi5fdj3oxtthtksk4xbgqpzvhmh6rlqhl545yn4mxb43e.py
# Topologically Sorted Source Nodes: [mul_7, Q_3, Q_4, Q_5], Original ATen: [aten.mul, aten.sub, aten._softmax]
# Source node to ATen node mapping:
#   Q_3 => sub_3
#   Q_4 => sub_4
#   Q_5 => exp_3, sub_5
#   mul_7 => mul_7
# Graph fragment:
#   %mul_7 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_6, %view_4), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%convolution_6, %mul_7), kwargs = {})
#   %sub_4 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%primals_1, %sub_3), kwargs = {})
#   %sub_5 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sub_4, %amax_1), kwargs = {})
#   %exp_3 : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_5,), kwargs = {})
triton_poi_fused__softmax_mul_sub_12 = async_compile.triton('triton_poi_fused__softmax_mul_sub_12', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_mul_sub_12', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__softmax_mul_sub_12(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, xnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = (xindex // 16) % 4
    x0 = xindex % 16
    x2 = (xindex // 64)
    tmp0 = tl.load(in_ptr0 + (x3), xmask)
    tmp1 = tl.load(in_out_ptr0 + (x3), xmask)
    tmp2 = tl.load(in_ptr1 + (x3), xmask)
    tmp3 = tl.load(in_ptr2 + (x1), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr3 + (x0 + (16*x2)), xmask, eviction_policy='evict_last')
    tmp4 = tmp2 * tmp3
    tmp5 = tmp1 - tmp4
    tmp6 = tmp0 - tmp5
    tmp8 = tmp6 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(in_out_ptr0 + (x3), tmp9, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/qh/cqhv4uf4hvut24ixtv5lslvn7vvogtvxkza3b6bxoubwztjedcwx.py
# Topologically Sorted Source Nodes: [mul_63, Q_38, Q_39], Original ATen: [aten.mul, aten.sub]
# Source node to ATen node mapping:
#   Q_38 => sub_38
#   Q_39 => sub_39
#   mul_63 => mul_63
# Graph fragment:
#   %mul_63 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_48, %view_4), kwargs = {})
#   %sub_38 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%convolution_55, %mul_63), kwargs = {})
#   %sub_39 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%primals_1, %sub_38), kwargs = {})
triton_poi_fused_mul_sub_13 = async_compile.triton('triton_poi_fused_mul_sub_13', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_mul_sub_13', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 4, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_mul_sub_13(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = (xindex // 16) % 4
    tmp0 = tl.load(in_ptr0 + (x3), xmask)
    tmp1 = tl.load(in_out_ptr0 + (x3), xmask)
    tmp2 = tl.load(in_ptr1 + (x3), xmask)
    tmp3 = tl.load(in_ptr2 + (x1), xmask, eviction_policy='evict_last')
    tmp4 = tmp2 * tmp3
    tmp5 = tmp1 - tmp4
    tmp6 = tmp0 - tmp5
    tl.store(in_out_ptr0 + (x3), tmp6, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

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 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_3, (32, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_4, (32, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_5, (1, 1, 1, 8, 1, 1), (8, 8, 8, 1, 1, 1))
    assert_size_stride(primals_6, (32, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_7, (32, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_8, (1, 1, 1, 8, 1, 1), (8, 8, 8, 1, 1, 1))
    assert_size_stride(primals_9, (4, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_10, (1, 9, 4, 1, 1), (36, 4, 1, 1, 1))
    assert_size_stride(primals_11, (4, 4, 1, 1), (4, 1, 1, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [Q], Original ATen: [aten._softmax]
        stream0 = get_raw_stream(0)
        triton_poi_fused__softmax_0.run(primals_1, buf0, 256, grid=grid(256), stream=stream0)
        buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [Q], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf0, buf1, 256, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d], Original ATen: [aten.convolution]
        buf2 = extern_kernels.convolution(primals_2, primals_3, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf2, (4, 32, 4, 4), (512, 16, 4, 1))
        del primals_3
        # Topologically Sorted Source Nodes: [conv2d_1], Original ATen: [aten.convolution]
        buf3 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf3, (4, 32, 4, 4), (512, 16, 4, 1))
        # Topologically Sorted Source Nodes: [conv2d_2], Original ATen: [aten.convolution]
        buf7 = extern_kernels.convolution(primals_2, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf7, (4, 32, 4, 4), (512, 16, 4, 1))
        del primals_6
        buf4 = reinterpret_tensor(buf2, (4, 4, 8, 4, 4), (512, 128, 16, 4, 1), 0); del buf2  # reuse
        buf9 = reinterpret_tensor(buf7, (4, 4, 8, 4, 4), (512, 128, 16, 4, 1), 0); del buf7  # reuse
        # Topologically Sorted Source Nodes: [sub, pow_1, K, neg, K_1, sub_1, pow_2, K_2, neg_1, K_3], Original ATen: [aten.sub, aten.pow, aten.div, aten.neg, aten.exp]
        triton_poi_fused_div_exp_neg_pow_sub_2.run(buf4, buf9, primals_2, 2048, grid=grid(2048), stream=stream0)
        del primals_2
        buf6 = buf0; del buf0  # reuse
        # Topologically Sorted Source Nodes: [norm_weight, norm_weight_1], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_3.run(buf4, primals_5, buf6, 256, 8, grid=grid(256), stream=stream0)
        buf18 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 1, 144, 36, 9), torch.float32)
        buf15 = reinterpret_tensor(buf18, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 0)  # alias
        # Topologically Sorted Source Nodes: [Qj, Qj_1, Qtilde, Qtilde_1], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_4.run(buf4, buf3, primals_5, buf6, buf15, 1024, 8, grid=grid(1024), stream=stream0)
        del buf3
        # Topologically Sorted Source Nodes: [conv2d_3], Original ATen: [aten.convolution]
        buf8 = extern_kernels.convolution(buf1, primals_7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf8, (4, 32, 4, 4), (512, 16, 4, 1))
        buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [norm_weight_2, norm_weight_3], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_3.run(buf9, primals_8, buf11, 256, 8, grid=grid(256), stream=stream0)
        buf16 = reinterpret_tensor(buf18, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 4)  # alias
        # Topologically Sorted Source Nodes: [Qj_2, Qj_3, Qtilde_2, Qtilde_3], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_5.run(buf9, buf8, primals_8, buf11, buf16, 1024, 8, grid=grid(1024), stream=stream0)
        del buf8
        # Topologically Sorted Source Nodes: [Qtilde_4], Original ATen: [aten.convolution]
        buf12 = extern_kernels.convolution(buf1, primals_9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf12, (4, 4, 4, 4), (64, 16, 4, 1))
        buf13 = buf1; del buf1  # reuse
        # Topologically Sorted Source Nodes: [new_ones, norm_weight_4], Original ATen: [aten.new_ones, aten.convolution]
        triton_poi_fused_convolution_new_ones_6.run(buf13, 256, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [new_ones, norm_weight_4], Original ATen: [aten.new_ones, aten.convolution]
        buf14 = extern_kernels.convolution(buf13, primals_9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf14, (4, 4, 4, 4), (64, 16, 4, 1))
        buf17 = reinterpret_tensor(buf18, (4, 1, 4, 4, 4), (576, 1, 144, 36, 9), 8)  # alias
        # Topologically Sorted Source Nodes: [Qtilde_6], Original ATen: [aten.cat]
        triton_poi_fused_cat_7.run(buf12, buf14, buf17, 256, grid=grid(256), stream=stream0)
        buf19 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [Qtilde_6], Original ATen: [aten.cat]
        triton_poi_fused_cat_8.run(buf18, buf19, 36, 64, grid=grid(36, 64), stream=stream0)
        del buf15
        del buf16
        del buf17
        buf20 = buf12; del buf12  # reuse
        # Topologically Sorted Source Nodes: [Q_1, Q_2], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_9.run(buf19, primals_10, buf20, 256, 9, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_6], Original ATen: [aten.convolution]
        buf21 = extern_kernels.convolution(buf20, primals_11, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf21, (4, 4, 4, 4), (64, 16, 4, 1))
        buf22 = empty_strided_cuda((4, ), (1, ), torch.float32)
        # Topologically Sorted Source Nodes: [diag], Original ATen: [aten.diagonal_copy]
        triton_poi_fused_diagonal_copy_10.run(primals_11, buf22, 4, grid=grid(4), stream=stream0)
        buf23 = empty_strided_cuda((4, 1, 4, 4), (16, 64, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [mul_7, Q_3, Q_4, Q_5], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_11.run(primals_1, buf21, buf20, buf22, buf23, 64, grid=grid(64), stream=stream0)
        buf24 = buf21; del buf21  # reuse
        # Topologically Sorted Source Nodes: [mul_7, Q_3, Q_4, Q_5], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_12.run(buf24, primals_1, buf20, buf22, buf23, 256, grid=grid(256), stream=stream0)
        buf25 = buf13; del buf13  # reuse
        # Topologically Sorted Source Nodes: [Q_5], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf24, buf25, 256, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_8], Original ATen: [aten.convolution]
        buf26 = extern_kernels.convolution(buf25, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf26, (4, 32, 4, 4), (512, 16, 4, 1))
        buf34 = buf18; del buf18  # reuse
        buf31 = reinterpret_tensor(buf34, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 0)  # alias
        # Topologically Sorted Source Nodes: [Qj_4, Qj_5, Qtilde_7, Qtilde_8], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_4.run(buf4, buf26, primals_5, buf6, buf31, 1024, 8, grid=grid(1024), stream=stream0)
        del buf26
        # Topologically Sorted Source Nodes: [conv2d_10], Original ATen: [aten.convolution]
        buf28 = extern_kernels.convolution(buf25, primals_7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf28, (4, 32, 4, 4), (512, 16, 4, 1))
        buf32 = reinterpret_tensor(buf34, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 4)  # alias
        # Topologically Sorted Source Nodes: [Qj_6, Qj_7, Qtilde_9, Qtilde_10], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_5.run(buf9, buf28, primals_8, buf11, buf32, 1024, 8, grid=grid(1024), stream=stream0)
        del buf28
        # Topologically Sorted Source Nodes: [Qtilde_11], Original ATen: [aten.convolution]
        buf30 = extern_kernels.convolution(buf25, primals_9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf30, (4, 4, 4, 4), (64, 16, 4, 1))
        buf33 = reinterpret_tensor(buf34, (4, 1, 4, 4, 4), (576, 1, 144, 36, 9), 8)  # alias
        # Topologically Sorted Source Nodes: [Qtilde_13], Original ATen: [aten.cat]
        triton_poi_fused_cat_7.run(buf30, buf14, buf33, 256, grid=grid(256), stream=stream0)
        buf35 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [Qtilde_13], Original ATen: [aten.cat]
        triton_poi_fused_cat_8.run(buf34, buf35, 36, 64, grid=grid(36, 64), stream=stream0)
        del buf31
        del buf32
        del buf33
        buf36 = buf30; del buf30  # reuse
        # Topologically Sorted Source Nodes: [Q_6, Q_7], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_9.run(buf35, primals_10, buf36, 256, 9, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_13], Original ATen: [aten.convolution]
        buf37 = extern_kernels.convolution(buf36, primals_11, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf37, (4, 4, 4, 4), (64, 16, 4, 1))
        buf38 = buf23; del buf23  # reuse
        # Topologically Sorted Source Nodes: [mul_15, Q_8, Q_9, Q_10], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_11.run(primals_1, buf37, buf36, buf22, buf38, 64, grid=grid(64), stream=stream0)
        buf39 = buf37; del buf37  # reuse
        # Topologically Sorted Source Nodes: [mul_15, Q_8, Q_9, Q_10], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_12.run(buf39, primals_1, buf36, buf22, buf38, 256, grid=grid(256), stream=stream0)
        buf40 = buf24; del buf24  # reuse
        # Topologically Sorted Source Nodes: [Q_10], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf39, buf40, 256, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_15], Original ATen: [aten.convolution]
        buf41 = extern_kernels.convolution(buf40, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf41, (4, 32, 4, 4), (512, 16, 4, 1))
        buf49 = buf34; del buf34  # reuse
        buf46 = reinterpret_tensor(buf49, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 0)  # alias
        # Topologically Sorted Source Nodes: [Qj_8, Qj_9, Qtilde_14, Qtilde_15], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_4.run(buf4, buf41, primals_5, buf6, buf46, 1024, 8, grid=grid(1024), stream=stream0)
        del buf41
        # Topologically Sorted Source Nodes: [conv2d_17], Original ATen: [aten.convolution]
        buf43 = extern_kernels.convolution(buf40, primals_7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf43, (4, 32, 4, 4), (512, 16, 4, 1))
        buf47 = reinterpret_tensor(buf49, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 4)  # alias
        # Topologically Sorted Source Nodes: [Qj_10, Qj_11, Qtilde_16, Qtilde_17], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_5.run(buf9, buf43, primals_8, buf11, buf47, 1024, 8, grid=grid(1024), stream=stream0)
        del buf43
        # Topologically Sorted Source Nodes: [Qtilde_18], Original ATen: [aten.convolution]
        buf45 = extern_kernels.convolution(buf40, primals_9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf45, (4, 4, 4, 4), (64, 16, 4, 1))
        buf48 = reinterpret_tensor(buf49, (4, 1, 4, 4, 4), (576, 1, 144, 36, 9), 8)  # alias
        # Topologically Sorted Source Nodes: [Qtilde_20], Original ATen: [aten.cat]
        triton_poi_fused_cat_7.run(buf45, buf14, buf48, 256, grid=grid(256), stream=stream0)
        buf50 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [Qtilde_20], Original ATen: [aten.cat]
        triton_poi_fused_cat_8.run(buf49, buf50, 36, 64, grid=grid(36, 64), stream=stream0)
        del buf46
        del buf47
        del buf48
        buf51 = buf45; del buf45  # reuse
        # Topologically Sorted Source Nodes: [Q_11, Q_12], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_9.run(buf50, primals_10, buf51, 256, 9, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_20], Original ATen: [aten.convolution]
        buf52 = extern_kernels.convolution(buf51, primals_11, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf52, (4, 4, 4, 4), (64, 16, 4, 1))
        buf53 = buf38; del buf38  # reuse
        # Topologically Sorted Source Nodes: [mul_23, Q_13, Q_14, Q_15], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_11.run(primals_1, buf52, buf51, buf22, buf53, 64, grid=grid(64), stream=stream0)
        buf54 = buf52; del buf52  # reuse
        # Topologically Sorted Source Nodes: [mul_23, Q_13, Q_14, Q_15], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_12.run(buf54, primals_1, buf51, buf22, buf53, 256, grid=grid(256), stream=stream0)
        buf55 = buf39; del buf39  # reuse
        # Topologically Sorted Source Nodes: [Q_15], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf54, buf55, 256, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_22], Original ATen: [aten.convolution]
        buf56 = extern_kernels.convolution(buf55, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf56, (4, 32, 4, 4), (512, 16, 4, 1))
        buf64 = buf49; del buf49  # reuse
        buf61 = reinterpret_tensor(buf64, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 0)  # alias
        # Topologically Sorted Source Nodes: [Qj_12, Qj_13, Qtilde_21, Qtilde_22], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_4.run(buf4, buf56, primals_5, buf6, buf61, 1024, 8, grid=grid(1024), stream=stream0)
        del buf56
        # Topologically Sorted Source Nodes: [conv2d_24], Original ATen: [aten.convolution]
        buf58 = extern_kernels.convolution(buf55, primals_7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf58, (4, 32, 4, 4), (512, 16, 4, 1))
        buf62 = reinterpret_tensor(buf64, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 4)  # alias
        # Topologically Sorted Source Nodes: [Qj_14, Qj_15, Qtilde_23, Qtilde_24], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_5.run(buf9, buf58, primals_8, buf11, buf62, 1024, 8, grid=grid(1024), stream=stream0)
        del buf58
        # Topologically Sorted Source Nodes: [Qtilde_25], Original ATen: [aten.convolution]
        buf60 = extern_kernels.convolution(buf55, primals_9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf60, (4, 4, 4, 4), (64, 16, 4, 1))
        buf63 = reinterpret_tensor(buf64, (4, 1, 4, 4, 4), (576, 1, 144, 36, 9), 8)  # alias
        # Topologically Sorted Source Nodes: [Qtilde_27], Original ATen: [aten.cat]
        triton_poi_fused_cat_7.run(buf60, buf14, buf63, 256, grid=grid(256), stream=stream0)
        buf65 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [Qtilde_27], Original ATen: [aten.cat]
        triton_poi_fused_cat_8.run(buf64, buf65, 36, 64, grid=grid(36, 64), stream=stream0)
        del buf61
        del buf62
        del buf63
        buf66 = buf60; del buf60  # reuse
        # Topologically Sorted Source Nodes: [Q_16, Q_17], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_9.run(buf65, primals_10, buf66, 256, 9, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_27], Original ATen: [aten.convolution]
        buf67 = extern_kernels.convolution(buf66, primals_11, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf67, (4, 4, 4, 4), (64, 16, 4, 1))
        buf68 = buf53; del buf53  # reuse
        # Topologically Sorted Source Nodes: [mul_31, Q_18, Q_19, Q_20], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_11.run(primals_1, buf67, buf66, buf22, buf68, 64, grid=grid(64), stream=stream0)
        buf69 = buf67; del buf67  # reuse
        # Topologically Sorted Source Nodes: [mul_31, Q_18, Q_19, Q_20], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_12.run(buf69, primals_1, buf66, buf22, buf68, 256, grid=grid(256), stream=stream0)
        buf70 = buf54; del buf54  # reuse
        # Topologically Sorted Source Nodes: [Q_20], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf69, buf70, 256, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_29], Original ATen: [aten.convolution]
        buf71 = extern_kernels.convolution(buf70, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf71, (4, 32, 4, 4), (512, 16, 4, 1))
        buf79 = buf64; del buf64  # reuse
        buf76 = reinterpret_tensor(buf79, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 0)  # alias
        # Topologically Sorted Source Nodes: [Qj_16, Qj_17, Qtilde_28, Qtilde_29], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_4.run(buf4, buf71, primals_5, buf6, buf76, 1024, 8, grid=grid(1024), stream=stream0)
        del buf71
        # Topologically Sorted Source Nodes: [conv2d_31], Original ATen: [aten.convolution]
        buf73 = extern_kernels.convolution(buf70, primals_7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf73, (4, 32, 4, 4), (512, 16, 4, 1))
        buf77 = reinterpret_tensor(buf79, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 4)  # alias
        # Topologically Sorted Source Nodes: [Qj_18, Qj_19, Qtilde_30, Qtilde_31], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_5.run(buf9, buf73, primals_8, buf11, buf77, 1024, 8, grid=grid(1024), stream=stream0)
        del buf73
        # Topologically Sorted Source Nodes: [Qtilde_32], Original ATen: [aten.convolution]
        buf75 = extern_kernels.convolution(buf70, primals_9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf75, (4, 4, 4, 4), (64, 16, 4, 1))
        buf78 = reinterpret_tensor(buf79, (4, 1, 4, 4, 4), (576, 1, 144, 36, 9), 8)  # alias
        # Topologically Sorted Source Nodes: [Qtilde_34], Original ATen: [aten.cat]
        triton_poi_fused_cat_7.run(buf75, buf14, buf78, 256, grid=grid(256), stream=stream0)
        buf80 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [Qtilde_34], Original ATen: [aten.cat]
        triton_poi_fused_cat_8.run(buf79, buf80, 36, 64, grid=grid(36, 64), stream=stream0)
        del buf76
        del buf77
        del buf78
        buf81 = buf75; del buf75  # reuse
        # Topologically Sorted Source Nodes: [Q_21, Q_22], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_9.run(buf80, primals_10, buf81, 256, 9, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_34], Original ATen: [aten.convolution]
        buf82 = extern_kernels.convolution(buf81, primals_11, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf82, (4, 4, 4, 4), (64, 16, 4, 1))
        buf83 = buf68; del buf68  # reuse
        # Topologically Sorted Source Nodes: [mul_39, Q_23, Q_24, Q_25], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_11.run(primals_1, buf82, buf81, buf22, buf83, 64, grid=grid(64), stream=stream0)
        buf84 = buf82; del buf82  # reuse
        # Topologically Sorted Source Nodes: [mul_39, Q_23, Q_24, Q_25], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_12.run(buf84, primals_1, buf81, buf22, buf83, 256, grid=grid(256), stream=stream0)
        buf85 = buf69; del buf69  # reuse
        # Topologically Sorted Source Nodes: [Q_25], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf84, buf85, 256, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_36], Original ATen: [aten.convolution]
        buf86 = extern_kernels.convolution(buf85, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf86, (4, 32, 4, 4), (512, 16, 4, 1))
        buf94 = buf79; del buf79  # reuse
        buf91 = reinterpret_tensor(buf94, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 0)  # alias
        # Topologically Sorted Source Nodes: [Qj_20, Qj_21, Qtilde_35, Qtilde_36], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_4.run(buf4, buf86, primals_5, buf6, buf91, 1024, 8, grid=grid(1024), stream=stream0)
        del buf86
        # Topologically Sorted Source Nodes: [conv2d_38], Original ATen: [aten.convolution]
        buf88 = extern_kernels.convolution(buf85, primals_7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf88, (4, 32, 4, 4), (512, 16, 4, 1))
        buf92 = reinterpret_tensor(buf94, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 4)  # alias
        # Topologically Sorted Source Nodes: [Qj_22, Qj_23, Qtilde_37, Qtilde_38], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_5.run(buf9, buf88, primals_8, buf11, buf92, 1024, 8, grid=grid(1024), stream=stream0)
        del buf88
        # Topologically Sorted Source Nodes: [Qtilde_39], Original ATen: [aten.convolution]
        buf90 = extern_kernels.convolution(buf85, primals_9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf90, (4, 4, 4, 4), (64, 16, 4, 1))
        buf93 = reinterpret_tensor(buf94, (4, 1, 4, 4, 4), (576, 1, 144, 36, 9), 8)  # alias
        # Topologically Sorted Source Nodes: [Qtilde_41], Original ATen: [aten.cat]
        triton_poi_fused_cat_7.run(buf90, buf14, buf93, 256, grid=grid(256), stream=stream0)
        buf95 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [Qtilde_41], Original ATen: [aten.cat]
        triton_poi_fused_cat_8.run(buf94, buf95, 36, 64, grid=grid(36, 64), stream=stream0)
        del buf91
        del buf92
        del buf93
        buf96 = buf90; del buf90  # reuse
        # Topologically Sorted Source Nodes: [Q_26, Q_27], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_9.run(buf95, primals_10, buf96, 256, 9, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_41], Original ATen: [aten.convolution]
        buf97 = extern_kernels.convolution(buf96, primals_11, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf97, (4, 4, 4, 4), (64, 16, 4, 1))
        buf98 = buf83; del buf83  # reuse
        # Topologically Sorted Source Nodes: [mul_47, Q_28, Q_29, Q_30], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_11.run(primals_1, buf97, buf96, buf22, buf98, 64, grid=grid(64), stream=stream0)
        buf99 = buf97; del buf97  # reuse
        # Topologically Sorted Source Nodes: [mul_47, Q_28, Q_29, Q_30], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_12.run(buf99, primals_1, buf96, buf22, buf98, 256, grid=grid(256), stream=stream0)
        buf100 = buf84; del buf84  # reuse
        # Topologically Sorted Source Nodes: [Q_30], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf99, buf100, 256, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_43], Original ATen: [aten.convolution]
        buf101 = extern_kernels.convolution(buf100, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf101, (4, 32, 4, 4), (512, 16, 4, 1))
        buf109 = buf94; del buf94  # reuse
        buf106 = reinterpret_tensor(buf109, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 0)  # alias
        # Topologically Sorted Source Nodes: [Qj_24, Qj_25, Qtilde_42, Qtilde_43], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_4.run(buf4, buf101, primals_5, buf6, buf106, 1024, 8, grid=grid(1024), stream=stream0)
        del buf101
        # Topologically Sorted Source Nodes: [conv2d_45], Original ATen: [aten.convolution]
        buf103 = extern_kernels.convolution(buf100, primals_7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf103, (4, 32, 4, 4), (512, 16, 4, 1))
        buf107 = reinterpret_tensor(buf109, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 4)  # alias
        # Topologically Sorted Source Nodes: [Qj_26, Qj_27, Qtilde_44, Qtilde_45], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_5.run(buf9, buf103, primals_8, buf11, buf107, 1024, 8, grid=grid(1024), stream=stream0)
        del buf103
        # Topologically Sorted Source Nodes: [Qtilde_46], Original ATen: [aten.convolution]
        buf105 = extern_kernels.convolution(buf100, primals_9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf105, (4, 4, 4, 4), (64, 16, 4, 1))
        buf108 = reinterpret_tensor(buf109, (4, 1, 4, 4, 4), (576, 1, 144, 36, 9), 8)  # alias
        # Topologically Sorted Source Nodes: [Qtilde_48], Original ATen: [aten.cat]
        triton_poi_fused_cat_7.run(buf105, buf14, buf108, 256, grid=grid(256), stream=stream0)
        buf110 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [Qtilde_48], Original ATen: [aten.cat]
        triton_poi_fused_cat_8.run(buf109, buf110, 36, 64, grid=grid(36, 64), stream=stream0)
        del buf106
        del buf107
        del buf108
        buf111 = buf105; del buf105  # reuse
        # Topologically Sorted Source Nodes: [Q_31, Q_32], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_9.run(buf110, primals_10, buf111, 256, 9, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_48], Original ATen: [aten.convolution]
        buf112 = extern_kernels.convolution(buf111, primals_11, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf112, (4, 4, 4, 4), (64, 16, 4, 1))
        buf113 = buf98; del buf98  # reuse
        # Topologically Sorted Source Nodes: [mul_55, Q_33, Q_34, Q_35], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_11.run(primals_1, buf112, buf111, buf22, buf113, 64, grid=grid(64), stream=stream0)
        buf114 = buf112; del buf112  # reuse
        # Topologically Sorted Source Nodes: [mul_55, Q_33, Q_34, Q_35], Original ATen: [aten.mul, aten.sub, aten._softmax]
        triton_poi_fused__softmax_mul_sub_12.run(buf114, primals_1, buf111, buf22, buf113, 256, grid=grid(256), stream=stream0)
        del buf113
        buf115 = buf99; del buf99  # reuse
        # Topologically Sorted Source Nodes: [Q_35], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf114, buf115, 256, grid=grid(256), stream=stream0)
        del buf114
        # Topologically Sorted Source Nodes: [conv2d_50], Original ATen: [aten.convolution]
        buf116 = extern_kernels.convolution(buf115, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf116, (4, 32, 4, 4), (512, 16, 4, 1))
        buf124 = buf109; del buf109  # reuse
        buf121 = reinterpret_tensor(buf124, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 0)  # alias
        # Topologically Sorted Source Nodes: [Qj_28, Qj_29, Qtilde_49, Qtilde_50], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_4.run(buf4, buf116, primals_5, buf6, buf121, 1024, 8, grid=grid(1024), stream=stream0)
        del buf116
        # Topologically Sorted Source Nodes: [conv2d_52], Original ATen: [aten.convolution]
        buf118 = extern_kernels.convolution(buf115, primals_7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf118, (4, 32, 4, 4), (512, 16, 4, 1))
        buf122 = reinterpret_tensor(buf124, (4, 4, 4, 4, 4), (576, 1, 144, 36, 9), 4)  # alias
        # Topologically Sorted Source Nodes: [Qj_30, Qj_31, Qtilde_51, Qtilde_52], Original ATen: [aten.mul, aten.sum, aten.div]
        triton_per_fused_div_mul_sum_5.run(buf9, buf118, primals_8, buf11, buf122, 1024, 8, grid=grid(1024), stream=stream0)
        del buf118
        # Topologically Sorted Source Nodes: [Qtilde_53], Original ATen: [aten.convolution]
        buf120 = extern_kernels.convolution(buf115, primals_9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf120, (4, 4, 4, 4), (64, 16, 4, 1))
        buf123 = reinterpret_tensor(buf124, (4, 1, 4, 4, 4), (576, 1, 144, 36, 9), 8)  # alias
        # Topologically Sorted Source Nodes: [Qtilde_55], Original ATen: [aten.cat]
        triton_poi_fused_cat_7.run(buf120, buf14, buf123, 256, grid=grid(256), stream=stream0)
        buf125 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [Qtilde_55], Original ATen: [aten.cat]
        triton_poi_fused_cat_8.run(buf124, buf125, 36, 64, grid=grid(36, 64), stream=stream0)
        del buf121
        del buf122
        del buf123
        del buf124
        buf126 = buf120; del buf120  # reuse
        # Topologically Sorted Source Nodes: [Q_36, Q_37], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_9.run(buf125, primals_10, buf126, 256, 9, grid=grid(256), stream=stream0)
        # Topologically Sorted Source Nodes: [conv2d_55], Original ATen: [aten.convolution]
        buf127 = extern_kernels.convolution(buf126, primals_11, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf127, (4, 4, 4, 4), (64, 16, 4, 1))
        buf128 = buf127; del buf127  # reuse
        # Topologically Sorted Source Nodes: [mul_63, Q_38, Q_39], Original ATen: [aten.mul, aten.sub]
        triton_poi_fused_mul_sub_13.run(buf128, primals_1, buf126, buf22, 256, grid=grid(256), stream=stream0)
        del primals_1
    return (buf128, primals_4, primals_5, primals_7, primals_8, primals_9, primals_10, primals_11, reinterpret_tensor(buf4, (4, 4, 1, 8, 4, 4), (512, 128, 128, 16, 4, 1), 0), reinterpret_tensor(buf6, (4, 4, 1, 4, 4), (64, 16, 16, 4, 1), 0), reinterpret_tensor(buf9, (4, 4, 1, 8, 4, 4), (512, 128, 128, 16, 4, 1), 0), reinterpret_tensor(buf11, (4, 4, 1, 4, 4), (64, 16, 16, 4, 1), 0), buf14, buf19, buf20, buf22, buf25, buf35, buf36, buf40, buf50, buf51, buf55, buf65, buf66, buf70, buf80, buf81, buf85, buf95, buf96, buf100, buf110, buf111, buf115, buf125, buf126, )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    primals_1 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((32, 1, 3, 3), (9, 9, 3, 1), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((32, 1, 3, 3), (9, 9, 3, 1), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((1, 1, 1, 8, 1, 1), (8, 8, 8, 1, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_6 = rand_strided((32, 1, 3, 3), (9, 9, 3, 1), device='cuda:0', dtype=torch.float32)
    primals_7 = rand_strided((32, 1, 3, 3), (9, 9, 3, 1), device='cuda:0', dtype=torch.float32)
    primals_8 = rand_strided((1, 1, 1, 8, 1, 1), (8, 8, 8, 1, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_9 = rand_strided((4, 1, 3, 3), (9, 9, 3, 1), device='cuda:0', dtype=torch.float32)
    primals_10 = rand_strided((1, 9, 4, 1, 1), (36, 4, 1, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_11 = rand_strided((4, 4, 1, 1), (4, 1, 1, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11])
    return print_performance(fn, times=times, repeat=repeat)


if __name__ == "__main__":
    from torch._inductor.wrapper_benchmark import compiled_module_main
    compiled_module_main('None', benchmark_compiled_module)

import torch
import torch._C
import torch.serialization
from torch import nn
from torch.nn import init
from torch.nn import Parameter


def make_onehot_kernel(kernel_size, index):
    """
    Make 2D one hot square kernel, i.e. h=w
    k[kernel_size, kernel_size] = 0 except k.view(-1)[index] = 1
    """
    kernel = torch.zeros(kernel_size, kernel_size)
    kernel.view(-1)[index] = 1
    return kernel.view(1, 1, kernel_size, kernel_size)


def make_spatial_kernel(kernel_size, bandwidth, isreshape=True):
    """
    Make 2D square smoothness kernel, i.e. h=w
    k = 1/bandwidth * exp(-(pj-pi)**2/(2*bandwidth**2))
    pj, pi = location of pixel
    """
    assert bandwidth > 0, 'bandwidth of kernel must be > 0'
    assert kernel_size % 2 != 0, 'kernel must be odd'
    p_end = (kernel_size - 1) // 2
    X = torch.linspace(-p_end, p_end, steps=kernel_size).expand(kernel_size,
        kernel_size)
    Y = X.clone().t()
    kernel = torch.exp(-(X ** 2 + Y ** 2) / (2 * bandwidth ** 2))
    kernel[p_end, p_end] = 0
    if isreshape:
        return kernel.view(1, 1, kernel_size, kernel_size)
    return kernel


class GaussianMask(nn.Module):
    """
    Break down Gaussian kernel (2nd part of appearance kernel) into CNN
    kj = (I(j) - I(i))**2/2*bandwidth**2, j#i
    but compute all maps instead of 1 kernel
    """

    def __init__(self, in_channels, kernel_size, bandwidth, iskernel=True):
        super(GaussianMask, self).__init__()
        assert bandwidth > 0, 'bandwidth of kernel must be > 0'
        assert kernel_size % 2 != 0, 'kernel must be odd'
        self.bandwidth = bandwidth
        self.iskernel = iskernel
        self.n_kernels = kernel_size ** 2 - 1
        kernel_weight = self._make_kernel_weight(in_channels, kernel_size,
            self.n_kernels)
        padding = kernel_size // 2
        self.conv = nn.Conv2d(in_channels, in_channels * self.n_kernels,
            kernel_size, stride=1, padding=padding, groups=in_channels,
            bias=False)
        self.conv.weight.requires_grad = False
        self.conv.weight.copy_(kernel_weight.view_as(self.conv.weight))

    def _make_kernel_weight(self, in_channels, kernel_size, n_kernels):
        kernel_weight = torch.zeros(in_channels, n_kernels, kernel_size,
            kernel_size)
        for i in range(n_kernels):
            index = i if i < n_kernels // 2 else i + 1
            kernel_i = make_onehot_kernel(kernel_size, index)
            kernel_weight[:, i, :] = kernel_i
        return kernel_weight

    def forward(self, X):
        batch_size, in_channels, H, W = X.shape
        Xj = self.conv(X).view(batch_size, in_channels, self.n_kernels, H, W)
        if not self.iskernel:
            return Xj
        Xi = X.unsqueeze(dim=2)
        K = (Xj - Xi) ** 2 / (2 * self.bandwidth ** 2)
        K = torch.exp(-K)
        return K


class SpatialFilter(nn.Module):
    """
    Break down spatial filter (smoothest kernel) into CNN blocks
    refer: https://arxiv.org/pdf/1210.5644.pdf
    """

    def __init__(self, n_classes, kernel_size, theta_gamma):
        super(SpatialFilter, self).__init__()
        padding = kernel_size // 2
        kernel_weight = make_spatial_kernel(kernel_size, theta_gamma)
        self.conv = nn.Conv2d(n_classes, n_classes, kernel_size, stride=1,
            padding=padding, groups=n_classes, bias=False)
        self.conv.weight.requires_grad = False
        self.conv.weight.copy_(kernel_weight)

    def forward(self, Q):
        Qtilde = self.conv(Q)
        norm_weight = self.conv(Q.new_ones(*Q.shape, requires_grad=False))
        Qtilde = Qtilde / norm_weight
        return Qtilde


class BilateralFilter(nn.Module):
    """
    Break down bilateral filter (appearance kernel) into CNN blocks
    remember that exp(-a-b) =exp(-a)*exp(b)
    """

    def __init__(self, in_channels, n_classes, kernel_size, theta_alpha,
        theta_beta):
        super(BilateralFilter, self).__init__()
        kernel_weight = make_spatial_kernel(kernel_size, theta_alpha,
            isreshape=False)
        self.spatial_weight = Parameter(kernel_weight[kernel_weight > 0].
            view(1, 1, 1, -1, 1, 1), requires_grad=False)
        self.gauss_mask_I = GaussianMask(in_channels, kernel_size, theta_beta)
        self.guass_mask_Q = GaussianMask(n_classes, kernel_size, 1,
            iskernel=False)

    def forward(self, Q, I):
        Ij = self.gauss_mask_I(I)
        Qj = self.guass_mask_Q(Q)
        Qj = Ij.unsqueeze(dim=2) * Qj.unsqueeze(dim=1)
        Qj = Qj * self.spatial_weight
        Qtilde = Qj.sum(dim=3)
        norm_weight = Ij * self.spatial_weight.squeeze(dim=2)
        norm_weight = norm_weight.sum(dim=2)
        Qtilde = Qtilde / norm_weight.unsqueeze(dim=2)
        return Qtilde


class MessagePassing(nn.Module):
    """
    Combine bilateral filter (appearance filter)
    and spatial filter to make message passing
    """

    def __init__(self, in_channels, n_classes, kernel_size=[3], theta_alpha
        =[2.0], theta_beta=[2.0], theta_gamma=[2.0]):
        super(MessagePassing, self).__init__()
        assert len(theta_alpha) == len(theta_beta
            ), 'theta_alpha and theta_beta have different lengths'
        self.n_bilaterals, self.n_spatials = len(theta_alpha), len(theta_gamma)
        for i in range(self.n_bilaterals):
            self.add_module('bilateral{}'.format(i), BilateralFilter(
                in_channels, n_classes, kernel_size[i], theta_alpha[i],
                theta_beta[i]))
        for i in range(self.n_spatials):
            self.add_module('spatial{}'.format(i), SpatialFilter(n_classes,
                kernel_size[i], theta_gamma[i]))

    def _get_child(self, child_name):
        return getattr(self, child_name)

    def forward(self, Q, I):
        filteredQ = []
        for i in range(self.n_bilaterals):
            tmp_bilateral = self._get_child('bilateral{}'.format(i))(Q, I)
            filteredQ.append(tmp_bilateral)
        for i in range(self.n_spatials):
            tmp_spatial = self._get_child('spatial{}'.format(i))(Q)
            filteredQ.append(tmp_spatial.unsqueeze(dim=1))
        Qtilde = torch.cat(filteredQ, dim=1)
        return Qtilde


class CRFRNN(nn.Module):
    """ Break meanfields down as CNN and do iteration """

    def __init__(self, n_iter, in_channels, n_classes, kernel_size=[3, 3],
        theta_alpha=[1.5, 2.5], theta_beta=[1.5, 2.5], theta_gamma=[1.5]):
        super(CRFRNN, self).__init__()
        self.n_iter = n_iter
        self.n_classes = n_classes
        n_filters = in_channels * len(theta_alpha) + len(theta_gamma)
        self.softmax = nn.Softmax2d()
        self.messagepassing = MessagePassing(in_channels, n_classes,
            kernel_size=kernel_size, theta_alpha=theta_alpha, theta_beta=
            theta_beta, theta_gamma=theta_gamma)
        self.weightfiltering = Parameter(torch.rand(1, n_filters, n_classes,
            1, 1))
        self.compatibilitytransf = nn.Conv2d(n_classes, n_classes,
            kernel_size=1, stride=1, padding=0, bias=False)
        self._weight_initial()
        self.train_step = 0

    def _weight_initial(self):
        init.kaiming_normal_(self.weightfiltering)
        init.kaiming_normal_(self.compatibilitytransf.weight)

    def forward(self, U, I):
        if self.training:
            if self.train_step < 60000:
                self.n_iter = 1
            elif self.train_step < 70000:
                self.n_iter = 2
            elif self.train_step < 75000:
                self.n_iter = 3
            else:
                self.n_iter = 4
            self.train_step = self.train_step + 1
        else:
            self.n_iter = 8
        Q = U
        for _ in range(self.n_iter):
            Q = self.softmax(Q)
            Q = self.messagepassing(Q, I)
            Q = Q * self.weightfiltering
            Q = Q.sum(dim=1)
            Q = self.compatibilitytransf(Q
                ) - Q * self.compatibilitytransf.weight.squeeze().diag().view(
                1, self.n_classes, 1, 1)
            Q = U - Q
        return Q


def get_inputs():
    return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]


def get_init_inputs():
    return [[], {'n_iter': 4, 'in_channels': 4, 'n_classes': 4}]

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
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch._C
import torch.serialization
from torch import nn
from torch.nn import init
from torch.nn import Parameter
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__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 16
    x2 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + x3, tmp9, xmask)


@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 16
    x2 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + x3, tmp8, xmask)


@triton.jit
def triton_poi_fused_div_exp_neg_pow_sub_2(in_out_ptr0, in_out_ptr1,
    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
    x0 = xindex % 16
    x2 = xindex // 128
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), None, eviction_policy='evict_last'
        )
    tmp8 = tl.load(in_out_ptr1 + x3, None)
    tmp2 = tmp0 - tmp1
    tmp3 = tmp2 * tmp2
    tmp4 = 0.2222222222222222
    tmp5 = tmp3 * tmp4
    tmp6 = -tmp5
    tmp7 = tl_math.exp(tmp6)
    tmp9 = tmp8 - tmp1
    tmp10 = tmp9 * tmp9
    tmp11 = 0.08
    tmp12 = tmp10 * tmp11
    tmp13 = -tmp12
    tmp14 = tl_math.exp(tmp13)
    tl.store(in_out_ptr0 + x3, tmp7, None)
    tl.store(in_out_ptr1 + x3, tmp14, None)


@triton.jit
def triton_per_fused_mul_sum_3(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    xnumel = 256
    RBLOCK: tl.constexpr = 8
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r2 = rindex
    x0 = xindex % 16
    x1 = xindex // 16
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 16 * r2 + 128 * x1), xmask, other=0.0)
    tmp1 = tl.load(in_ptr1 + r2, None, eviction_policy='evict_last')
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(xmask, tmp3, 0)
    tmp6 = tl.sum(tmp5, 1)[:, None]
    tl.store(out_ptr0 + x3, tmp6, xmask)


@triton.jit
def triton_per_fused_div_mul_sum_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 1024
    RBLOCK: tl.constexpr = 8
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r4 = rindex
    x0 = xindex % 16
    x5 = xindex // 64
    x1 = xindex // 16 % 4
    x3 = xindex // 256
    x2 = xindex // 64 % 4
    x7 = xindex % 64
    tmp0 = tl.load(in_ptr0 + (x0 + 16 * r4 + 128 * x5), xmask,
        eviction_policy='evict_last', other=0.0)
    tmp1 = tl.load(in_ptr1 + (x0 + 16 * r4 + 128 * x1 + 512 * x3), xmask,
        eviction_policy='evict_last', other=0.0)
    tmp3 = tl.load(in_ptr2 + r4, None, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr3 + (x0 + 16 * x5), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp0 * tmp1
    tmp4 = tmp2 * tmp3
    tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
    tmp7 = tl.where(xmask, tmp5, 0)
    tmp8 = tl.sum(tmp7, 1)[:, None]
    tmp10 = tmp8 / tmp9
    tl.store(out_ptr1 + (x2 + 9 * x7 + 576 * x3), tmp10, xmask)


@triton.jit
def triton_per_fused_div_mul_sum_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 1024
    RBLOCK: tl.constexpr = 8
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r4 = rindex
    x0 = xindex % 16
    x5 = xindex // 64
    x1 = xindex // 16 % 4
    x3 = xindex // 256
    x2 = xindex // 64 % 4
    x7 = xindex % 64
    tmp0 = tl.load(in_ptr0 + (x0 + 16 * r4 + 128 * x5), xmask,
        eviction_policy='evict_last', other=0.0)
    tmp1 = tl.load(in_ptr1 + (x0 + 16 * r4 + 128 * x1 + 512 * x3), xmask,
        eviction_policy='evict_last', other=0.0)
    tmp3 = tl.load(in_ptr2 + r4, None, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr3 + (x0 + 16 * x5), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp0 * tmp1
    tmp4 = tmp2 * tmp3
    tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
    tmp7 = tl.where(xmask, tmp5, 0)
    tmp8 = tl.sum(tmp7, 1)[:, None]
    tmp10 = tmp8 / tmp9
    tl.store(out_ptr1 + (x2 + 9 * x7 + 576 * x3), tmp10, xmask)


@triton.jit
def triton_poi_fused_convolution_new_ones_6(out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = 1.0
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused_cat_7(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask)
    tmp2 = tmp0 / tmp1
    tl.store(out_ptr0 + 9 * x0, tmp2, xmask)


@triton.jit
def triton_poi_fused_cat_8(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 36
    xnumel = 64
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y0 = yindex % 9
    y1 = yindex // 9
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 9 * x2 + 576 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tl.store(out_ptr0 + (x2 + 64 * y3), tmp0, xmask & ymask)


@triton.jit
def triton_per_fused_mul_sum_9(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    xnumel = 256
    rnumel = 9
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    rmask = rindex < rnumel
    r3 = rindex
    x2 = xindex // 64
    x4 = xindex % 64
    x1 = xindex // 16 % 4
    x5 = xindex
    tmp0 = tl.load(in_ptr0 + (x4 + 64 * r3 + 576 * x2), rmask & xmask,
        other=0.0)
    tmp1 = tl.load(in_ptr1 + (x1 + 4 * r3), rmask & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(rmask & xmask, tmp3, 0)
    tmp6 = tl.sum(tmp5, 1)[:, None]
    tl.store(out_ptr0 + x5, tmp6, xmask)


@triton.jit
def triton_poi_fused_diagonal_copy_10(in_ptr0, out_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 5 * x0, xmask, eviction_policy='evict_last')
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused__softmax_mul_sub_11(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x1 = xindex // 16
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
    tmp1 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask)
    tmp2 = tl.load(in_ptr2 + (x0 + 64 * x1), xmask)
    tmp3 = tl.load(in_ptr3 + 0)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK])
    tmp8 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
    tmp9 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask)
    tmp10 = tl.load(in_ptr2 + (16 + x0 + 64 * x1), xmask)
    tmp11 = tl.load(in_ptr3 + 1)
    tmp12 = tl.broadcast_to(tmp11, [XBLOCK])
    tmp17 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
    tmp18 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask)
    tmp19 = tl.load(in_ptr2 + (32 + x0 + 64 * x1), xmask)
    tmp20 = tl.load(in_ptr3 + 2)
    tmp21 = tl.broadcast_to(tmp20, [XBLOCK])
    tmp26 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
    tmp27 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask)
    tmp28 = tl.load(in_ptr2 + (48 + x0 + 64 * x1), xmask)
    tmp29 = tl.load(in_ptr3 + 3)
    tmp30 = tl.broadcast_to(tmp29, [XBLOCK])
    tmp5 = tmp2 * tmp4
    tmp6 = tmp1 - tmp5
    tmp7 = tmp0 - tmp6
    tmp13 = tmp10 * tmp12
    tmp14 = tmp9 - tmp13
    tmp15 = tmp8 - tmp14
    tmp16 = triton_helpers.maximum(tmp7, tmp15)
    tmp22 = tmp19 * tmp21
    tmp23 = tmp18 - tmp22
    tmp24 = tmp17 - tmp23
    tmp25 = triton_helpers.maximum(tmp16, tmp24)
    tmp31 = tmp28 * tmp30
    tmp32 = tmp27 - tmp31
    tmp33 = tmp26 - tmp32
    tmp34 = triton_helpers.maximum(tmp25, tmp33)
    tl.store(out_ptr0 + x2, tmp34, xmask)


@triton.jit
def triton_poi_fused__softmax_mul_sub_12(in_out_ptr0, in_ptr0, in_ptr1,
    in_ptr2, in_ptr3, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 4
    x0 = xindex % 16
    x2 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_out_ptr0 + x3, xmask)
    tmp2 = tl.load(in_ptr1 + x3, xmask)
    tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr3 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tmp2 * tmp3
    tmp5 = tmp1 - tmp4
    tmp6 = tmp0 - tmp5
    tmp8 = tmp6 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(in_out_ptr0 + x3, tmp9, xmask)


@triton.jit
def triton_poi_fused_mul_sub_13(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 4
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_out_ptr0 + x3, xmask)
    tmp2 = tl.load(in_ptr1 + x3, xmask)
    tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp4 = tmp2 * tmp3
    tmp5 = tmp1 - tmp4
    tmp6 = tmp0 - tmp5
    tl.store(in_out_ptr0 + x3, tmp6, xmask)


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) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_3, (32, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_4, (32, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_5, (1, 1, 1, 8, 1, 1), (8, 8, 8, 1, 1, 1))
    assert_size_stride(primals_6, (32, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_7, (32, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_8, (1, 1, 1, 8, 1, 1), (8, 8, 8, 1, 1, 1))
    assert_size_stride(primals_9, (4, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_10, (1, 9, 4, 1, 1), (36, 4, 1, 1, 1))
    assert_size_stride(primals_11, (4, 4, 1, 1), (4, 1, 1, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__softmax_0[grid(256)](primals_1, buf0, 256, XBLOCK
            =128, num_warps=4, num_stages=1)
        buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused__softmax_1[grid(256)](buf0, buf1, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf2 = extern_kernels.convolution(primals_2, primals_3, stride=(1, 
            1), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf2, (4, 32, 4, 4), (512, 16, 4, 1))
        del primals_3
        buf3 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf3, (4, 32, 4, 4), (512, 16, 4, 1))
        buf7 = extern_kernels.convolution(primals_2, primals_6, stride=(1, 
            1), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf7, (4, 32, 4, 4), (512, 16, 4, 1))
        del primals_6
        buf4 = reinterpret_tensor(buf2, (4, 4, 8, 4, 4), (512, 128, 16, 4, 
            1), 0)
        del buf2
        buf9 = reinterpret_tensor(buf7, (4, 4, 8, 4, 4), (512, 128, 16, 4, 
            1), 0)
        del buf7
        triton_poi_fused_div_exp_neg_pow_sub_2[grid(2048)](buf4, buf9,
            primals_2, 2048, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_2
        buf6 = buf0
        del buf0
        triton_per_fused_mul_sum_3[grid(256)](buf4, primals_5, buf6, 256, 8,
            XBLOCK=8, num_warps=2, num_stages=1)
        buf18 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 1, 144, 36, 9),
            torch.float32)
        buf15 = reinterpret_tensor(buf18, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf3, primals_5,
            buf6, buf15, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf3
        buf8 = extern_kernels.convolution(buf1, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf8, (4, 32, 4, 4), (512, 16, 4, 1))
        buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_per_fused_mul_sum_3[grid(256)](buf9, primals_8, buf11, 256, 
            8, XBLOCK=8, num_warps=2, num_stages=1)
        buf16 = reinterpret_tensor(buf18, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf8, primals_8,
            buf11, buf16, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf8
        buf12 = extern_kernels.convolution(buf1, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf12, (4, 4, 4, 4), (64, 16, 4, 1))
        buf13 = buf1
        del buf1
        triton_poi_fused_convolution_new_ones_6[grid(256)](buf13, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        buf14 = extern_kernels.convolution(buf13, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf14, (4, 4, 4, 4), (64, 16, 4, 1))
        buf17 = reinterpret_tensor(buf18, (4, 1, 4, 4, 4), (576, 1, 144, 36,
            9), 8)
        triton_poi_fused_cat_7[grid(256)](buf12, buf14, buf17, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf19 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf18, buf19, 36, 64, XBLOCK=
            32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf15
        del buf16
        del buf17
        buf20 = buf12
        del buf12
        triton_per_fused_mul_sum_9[grid(256)](buf19, primals_10, buf20, 256,
            9, XBLOCK=1, num_warps=2, num_stages=1)
        buf21 = extern_kernels.convolution(buf20, primals_11, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf21, (4, 4, 4, 4), (64, 16, 4, 1))
        buf22 = empty_strided_cuda((4,), (1,), torch.float32)
        triton_poi_fused_diagonal_copy_10[grid(4)](primals_11, buf22, 4,
            XBLOCK=4, num_warps=1, num_stages=1)
        buf23 = empty_strided_cuda((4, 1, 4, 4), (16, 64, 4, 1), torch.float32)
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf21,
            buf20, buf22, buf23, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf24 = buf21
        del buf21
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf24, primals_1,
            buf20, buf22, buf23, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf25 = buf13
        del buf13
        triton_poi_fused__softmax_1[grid(256)](buf24, buf25, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf26 = extern_kernels.convolution(buf25, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf26, (4, 32, 4, 4), (512, 16, 4, 1))
        buf34 = buf18
        del buf18
        buf31 = reinterpret_tensor(buf34, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf26, primals_5,
            buf6, buf31, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf26
        buf28 = extern_kernels.convolution(buf25, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf28, (4, 32, 4, 4), (512, 16, 4, 1))
        buf32 = reinterpret_tensor(buf34, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf28, primals_8,
            buf11, buf32, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf28
        buf30 = extern_kernels.convolution(buf25, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf30, (4, 4, 4, 4), (64, 16, 4, 1))
        buf33 = reinterpret_tensor(buf34, (4, 1, 4, 4, 4), (576, 1, 144, 36,
            9), 8)
        triton_poi_fused_cat_7[grid(256)](buf30, buf14, buf33, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf35 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf34, buf35, 36, 64, XBLOCK=
            32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf31
        del buf32
        del buf33
        buf36 = buf30
        del buf30
        triton_per_fused_mul_sum_9[grid(256)](buf35, primals_10, buf36, 256,
            9, XBLOCK=1, num_warps=2, num_stages=1)
        buf37 = extern_kernels.convolution(buf36, primals_11, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf37, (4, 4, 4, 4), (64, 16, 4, 1))
        buf38 = buf23
        del buf23
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf37,
            buf36, buf22, buf38, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf39 = buf37
        del buf37
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf39, primals_1,
            buf36, buf22, buf38, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf40 = buf24
        del buf24
        triton_poi_fused__softmax_1[grid(256)](buf39, buf40, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf41 = extern_kernels.convolution(buf40, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf41, (4, 32, 4, 4), (512, 16, 4, 1))
        buf49 = buf34
        del buf34
        buf46 = reinterpret_tensor(buf49, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf41, primals_5,
            buf6, buf46, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf41
        buf43 = extern_kernels.convolution(buf40, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf43, (4, 32, 4, 4), (512, 16, 4, 1))
        buf47 = reinterpret_tensor(buf49, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf43, primals_8,
            buf11, buf47, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf43
        buf45 = extern_kernels.convolution(buf40, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf45, (4, 4, 4, 4), (64, 16, 4, 1))
        buf48 = reinterpret_tensor(buf49, (4, 1, 4, 4, 4), (576, 1, 144, 36,
            9), 8)
        triton_poi_fused_cat_7[grid(256)](buf45, buf14, buf48, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf50 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf49, buf50, 36, 64, XBLOCK=
            32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf46
        del buf47
        del buf48
        buf51 = buf45
        del buf45
        triton_per_fused_mul_sum_9[grid(256)](buf50, primals_10, buf51, 256,
            9, XBLOCK=1, num_warps=2, num_stages=1)
        buf52 = extern_kernels.convolution(buf51, primals_11, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf52, (4, 4, 4, 4), (64, 16, 4, 1))
        buf53 = buf38
        del buf38
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf52,
            buf51, buf22, buf53, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf54 = buf52
        del buf52
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf54, primals_1,
            buf51, buf22, buf53, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf55 = buf39
        del buf39
        triton_poi_fused__softmax_1[grid(256)](buf54, buf55, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf56 = extern_kernels.convolution(buf55, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf56, (4, 32, 4, 4), (512, 16, 4, 1))
        buf64 = buf49
        del buf49
        buf61 = reinterpret_tensor(buf64, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf56, primals_5,
            buf6, buf61, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf56
        buf58 = extern_kernels.convolution(buf55, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf58, (4, 32, 4, 4), (512, 16, 4, 1))
        buf62 = reinterpret_tensor(buf64, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf58, primals_8,
            buf11, buf62, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf58
        buf60 = extern_kernels.convolution(buf55, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf60, (4, 4, 4, 4), (64, 16, 4, 1))
        buf63 = reinterpret_tensor(buf64, (4, 1, 4, 4, 4), (576, 1, 144, 36,
            9), 8)
        triton_poi_fused_cat_7[grid(256)](buf60, buf14, buf63, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf65 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf64, buf65, 36, 64, XBLOCK=
            32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf61
        del buf62
        del buf63
        buf66 = buf60
        del buf60
        triton_per_fused_mul_sum_9[grid(256)](buf65, primals_10, buf66, 256,
            9, XBLOCK=1, num_warps=2, num_stages=1)
        buf67 = extern_kernels.convolution(buf66, primals_11, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf67, (4, 4, 4, 4), (64, 16, 4, 1))
        buf68 = buf53
        del buf53
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf67,
            buf66, buf22, buf68, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf69 = buf67
        del buf67
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf69, primals_1,
            buf66, buf22, buf68, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf70 = buf54
        del buf54
        triton_poi_fused__softmax_1[grid(256)](buf69, buf70, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf71 = extern_kernels.convolution(buf70, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf71, (4, 32, 4, 4), (512, 16, 4, 1))
        buf79 = buf64
        del buf64
        buf76 = reinterpret_tensor(buf79, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf71, primals_5,
            buf6, buf76, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf71
        buf73 = extern_kernels.convolution(buf70, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf73, (4, 32, 4, 4), (512, 16, 4, 1))
        buf77 = reinterpret_tensor(buf79, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf73, primals_8,
            buf11, buf77, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf73
        buf75 = extern_kernels.convolution(buf70, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf75, (4, 4, 4, 4), (64, 16, 4, 1))
        buf78 = reinterpret_tensor(buf79, (4, 1, 4, 4, 4), (576, 1, 144, 36,
            9), 8)
        triton_poi_fused_cat_7[grid(256)](buf75, buf14, buf78, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf80 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf79, buf80, 36, 64, XBLOCK=
            32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf76
        del buf77
        del buf78
        buf81 = buf75
        del buf75
        triton_per_fused_mul_sum_9[grid(256)](buf80, primals_10, buf81, 256,
            9, XBLOCK=1, num_warps=2, num_stages=1)
        buf82 = extern_kernels.convolution(buf81, primals_11, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf82, (4, 4, 4, 4), (64, 16, 4, 1))
        buf83 = buf68
        del buf68
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf82,
            buf81, buf22, buf83, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf84 = buf82
        del buf82
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf84, primals_1,
            buf81, buf22, buf83, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf85 = buf69
        del buf69
        triton_poi_fused__softmax_1[grid(256)](buf84, buf85, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf86 = extern_kernels.convolution(buf85, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf86, (4, 32, 4, 4), (512, 16, 4, 1))
        buf94 = buf79
        del buf79
        buf91 = reinterpret_tensor(buf94, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf86, primals_5,
            buf6, buf91, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf86
        buf88 = extern_kernels.convolution(buf85, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf88, (4, 32, 4, 4), (512, 16, 4, 1))
        buf92 = reinterpret_tensor(buf94, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf88, primals_8,
            buf11, buf92, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf88
        buf90 = extern_kernels.convolution(buf85, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf90, (4, 4, 4, 4), (64, 16, 4, 1))
        buf93 = reinterpret_tensor(buf94, (4, 1, 4, 4, 4), (576, 1, 144, 36,
            9), 8)
        triton_poi_fused_cat_7[grid(256)](buf90, buf14, buf93, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf95 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf94, buf95, 36, 64, XBLOCK=
            32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf91
        del buf92
        del buf93
        buf96 = buf90
        del buf90
        triton_per_fused_mul_sum_9[grid(256)](buf95, primals_10, buf96, 256,
            9, XBLOCK=1, num_warps=2, num_stages=1)
        buf97 = extern_kernels.convolution(buf96, primals_11, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf97, (4, 4, 4, 4), (64, 16, 4, 1))
        buf98 = buf83
        del buf83
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf97,
            buf96, buf22, buf98, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf99 = buf97
        del buf97
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf99, primals_1,
            buf96, buf22, buf98, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf100 = buf84
        del buf84
        triton_poi_fused__softmax_1[grid(256)](buf99, buf100, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf101 = extern_kernels.convolution(buf100, primals_4, stride=(1, 1
            ), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf101, (4, 32, 4, 4), (512, 16, 4, 1))
        buf109 = buf94
        del buf94
        buf106 = reinterpret_tensor(buf109, (4, 4, 4, 4, 4), (576, 1, 144, 
            36, 9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf101, primals_5,
            buf6, buf106, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf101
        buf103 = extern_kernels.convolution(buf100, primals_7, stride=(1, 1
            ), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf103, (4, 32, 4, 4), (512, 16, 4, 1))
        buf107 = reinterpret_tensor(buf109, (4, 4, 4, 4, 4), (576, 1, 144, 
            36, 9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf103, primals_8,
            buf11, buf107, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf103
        buf105 = extern_kernels.convolution(buf100, primals_9, stride=(1, 1
            ), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf105, (4, 4, 4, 4), (64, 16, 4, 1))
        buf108 = reinterpret_tensor(buf109, (4, 1, 4, 4, 4), (576, 1, 144, 
            36, 9), 8)
        triton_poi_fused_cat_7[grid(256)](buf105, buf14, buf108, 256,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf110 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf109, buf110, 36, 64, XBLOCK
            =32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf106
        del buf107
        del buf108
        buf111 = buf105
        del buf105
        triton_per_fused_mul_sum_9[grid(256)](buf110, primals_10, buf111, 
            256, 9, XBLOCK=1, num_warps=2, num_stages=1)
        buf112 = extern_kernels.convolution(buf111, primals_11, stride=(1, 
            1), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf112, (4, 4, 4, 4), (64, 16, 4, 1))
        buf113 = buf98
        del buf98
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf112,
            buf111, buf22, buf113, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf114 = buf112
        del buf112
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf114, primals_1,
            buf111, buf22, buf113, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del buf113
        buf115 = buf99
        del buf99
        triton_poi_fused__softmax_1[grid(256)](buf114, buf115, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        del buf114
        buf116 = extern_kernels.convolution(buf115, primals_4, stride=(1, 1
            ), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf116, (4, 32, 4, 4), (512, 16, 4, 1))
        buf124 = buf109
        del buf109
        buf121 = reinterpret_tensor(buf124, (4, 4, 4, 4, 4), (576, 1, 144, 
            36, 9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf116, primals_5,
            buf6, buf121, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf116
        buf118 = extern_kernels.convolution(buf115, primals_7, stride=(1, 1
            ), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf118, (4, 32, 4, 4), (512, 16, 4, 1))
        buf122 = reinterpret_tensor(buf124, (4, 4, 4, 4, 4), (576, 1, 144, 
            36, 9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf118, primals_8,
            buf11, buf122, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf118
        buf120 = extern_kernels.convolution(buf115, primals_9, stride=(1, 1
            ), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf120, (4, 4, 4, 4), (64, 16, 4, 1))
        buf123 = reinterpret_tensor(buf124, (4, 1, 4, 4, 4), (576, 1, 144, 
            36, 9), 8)
        triton_poi_fused_cat_7[grid(256)](buf120, buf14, buf123, 256,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf125 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf124, buf125, 36, 64, XBLOCK
            =32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf121
        del buf122
        del buf123
        del buf124
        buf126 = buf120
        del buf120
        triton_per_fused_mul_sum_9[grid(256)](buf125, primals_10, buf126, 
            256, 9, XBLOCK=1, num_warps=2, num_stages=1)
        buf127 = extern_kernels.convolution(buf126, primals_11, stride=(1, 
            1), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf127, (4, 4, 4, 4), (64, 16, 4, 1))
        buf128 = buf127
        del buf127
        triton_poi_fused_mul_sub_13[grid(256)](buf128, primals_1, buf126,
            buf22, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_1
    return (buf128, primals_4, primals_5, primals_7, primals_8, primals_9,
        primals_10, primals_11, reinterpret_tensor(buf4, (4, 4, 1, 8, 4, 4),
        (512, 128, 128, 16, 4, 1), 0), reinterpret_tensor(buf6, (4, 4, 1, 4,
        4), (64, 16, 16, 4, 1), 0), reinterpret_tensor(buf9, (4, 4, 1, 8, 4,
        4), (512, 128, 128, 16, 4, 1), 0), reinterpret_tensor(buf11, (4, 4,
        1, 4, 4), (64, 16, 16, 4, 1), 0), buf14, buf19, buf20, buf22, buf25,
        buf35, buf36, buf40, buf50, buf51, buf55, buf65, buf66, buf70,
        buf80, buf81, buf85, buf95, buf96, buf100, buf110, buf111, buf115,
        buf125, buf126)


def make_onehot_kernel(kernel_size, index):
    """
    Make 2D one hot square kernel, i.e. h=w
    k[kernel_size, kernel_size] = 0 except k.view(-1)[index] = 1
    """
    kernel = torch.zeros(kernel_size, kernel_size)
    kernel.view(-1)[index] = 1
    return kernel.view(1, 1, kernel_size, kernel_size)


def make_spatial_kernel(kernel_size, bandwidth, isreshape=True):
    """
    Make 2D square smoothness kernel, i.e. h=w
    k = 1/bandwidth * exp(-(pj-pi)**2/(2*bandwidth**2))
    pj, pi = location of pixel
    """
    assert bandwidth > 0, 'bandwidth of kernel must be > 0'
    assert kernel_size % 2 != 0, 'kernel must be odd'
    p_end = (kernel_size - 1) // 2
    X = torch.linspace(-p_end, p_end, steps=kernel_size).expand(kernel_size,
        kernel_size)
    Y = X.clone().t()
    kernel = torch.exp(-(X ** 2 + Y ** 2) / (2 * bandwidth ** 2))
    kernel[p_end, p_end] = 0
    if isreshape:
        return kernel.view(1, 1, kernel_size, kernel_size)
    return kernel


class GaussianMask(nn.Module):
    """
    Break down Gaussian kernel (2nd part of appearance kernel) into CNN
    kj = (I(j) - I(i))**2/2*bandwidth**2, j#i
    but compute all maps instead of 1 kernel
    """

    def __init__(self, in_channels, kernel_size, bandwidth, iskernel=True):
        super(GaussianMask, self).__init__()
        assert bandwidth > 0, 'bandwidth of kernel must be > 0'
        assert kernel_size % 2 != 0, 'kernel must be odd'
        self.bandwidth = bandwidth
        self.iskernel = iskernel
        self.n_kernels = kernel_size ** 2 - 1
        kernel_weight = self._make_kernel_weight(in_channels, kernel_size,
            self.n_kernels)
        padding = kernel_size // 2
        self.conv = nn.Conv2d(in_channels, in_channels * self.n_kernels,
            kernel_size, stride=1, padding=padding, groups=in_channels,
            bias=False)
        self.conv.weight.requires_grad = False
        self.conv.weight.copy_(kernel_weight.view_as(self.conv.weight))

    def _make_kernel_weight(self, in_channels, kernel_size, n_kernels):
        kernel_weight = torch.zeros(in_channels, n_kernels, kernel_size,
            kernel_size)
        for i in range(n_kernels):
            index = i if i < n_kernels // 2 else i + 1
            kernel_i = make_onehot_kernel(kernel_size, index)
            kernel_weight[:, i, :] = kernel_i
        return kernel_weight

    def forward(self, X):
        batch_size, in_channels, H, W = X.shape
        Xj = self.conv(X).view(batch_size, in_channels, self.n_kernels, H, W)
        if not self.iskernel:
            return Xj
        Xi = X.unsqueeze(dim=2)
        K = (Xj - Xi) ** 2 / (2 * self.bandwidth ** 2)
        K = torch.exp(-K)
        return K


class SpatialFilter(nn.Module):
    """
    Break down spatial filter (smoothest kernel) into CNN blocks
    refer: https://arxiv.org/pdf/1210.5644.pdf
    """

    def __init__(self, n_classes, kernel_size, theta_gamma):
        super(SpatialFilter, self).__init__()
        padding = kernel_size // 2
        kernel_weight = make_spatial_kernel(kernel_size, theta_gamma)
        self.conv = nn.Conv2d(n_classes, n_classes, kernel_size, stride=1,
            padding=padding, groups=n_classes, bias=False)
        self.conv.weight.requires_grad = False
        self.conv.weight.copy_(kernel_weight)

    def forward(self, Q):
        Qtilde = self.conv(Q)
        norm_weight = self.conv(Q.new_ones(*Q.shape, requires_grad=False))
        Qtilde = Qtilde / norm_weight
        return Qtilde


class BilateralFilter(nn.Module):
    """
    Break down bilateral filter (appearance kernel) into CNN blocks
    remember that exp(-a-b) =exp(-a)*exp(b)
    """

    def __init__(self, in_channels, n_classes, kernel_size, theta_alpha,
        theta_beta):
        super(BilateralFilter, self).__init__()
        kernel_weight = make_spatial_kernel(kernel_size, theta_alpha,
            isreshape=False)
        self.spatial_weight = Parameter(kernel_weight[kernel_weight > 0].
            view(1, 1, 1, -1, 1, 1), requires_grad=False)
        self.gauss_mask_I = GaussianMask(in_channels, kernel_size, theta_beta)
        self.guass_mask_Q = GaussianMask(n_classes, kernel_size, 1,
            iskernel=False)

    def forward(self, Q, I):
        Ij = self.gauss_mask_I(I)
        Qj = self.guass_mask_Q(Q)
        Qj = Ij.unsqueeze(dim=2) * Qj.unsqueeze(dim=1)
        Qj = Qj * self.spatial_weight
        Qtilde = Qj.sum(dim=3)
        norm_weight = Ij * self.spatial_weight.squeeze(dim=2)
        norm_weight = norm_weight.sum(dim=2)
        Qtilde = Qtilde / norm_weight.unsqueeze(dim=2)
        return Qtilde


class MessagePassing(nn.Module):
    """
    Combine bilateral filter (appearance filter)
    and spatial filter to make message passing
    """

    def __init__(self, in_channels, n_classes, kernel_size=[3], theta_alpha
        =[2.0], theta_beta=[2.0], theta_gamma=[2.0]):
        super(MessagePassing, self).__init__()
        assert len(theta_alpha) == len(theta_beta
            ), 'theta_alpha and theta_beta have different lengths'
        self.n_bilaterals, self.n_spatials = len(theta_alpha), len(theta_gamma)
        for i in range(self.n_bilaterals):
            self.add_module('bilateral{}'.format(i), BilateralFilter(
                in_channels, n_classes, kernel_size[i], theta_alpha[i],
                theta_beta[i]))
        for i in range(self.n_spatials):
            self.add_module('spatial{}'.format(i), SpatialFilter(n_classes,
                kernel_size[i], theta_gamma[i]))

    def _get_child(self, child_name):
        return getattr(self, child_name)

    def forward(self, Q, I):
        filteredQ = []
        for i in range(self.n_bilaterals):
            tmp_bilateral = self._get_child('bilateral{}'.format(i))(Q, I)
            filteredQ.append(tmp_bilateral)
        for i in range(self.n_spatials):
            tmp_spatial = self._get_child('spatial{}'.format(i))(Q)
            filteredQ.append(tmp_spatial.unsqueeze(dim=1))
        Qtilde = torch.cat(filteredQ, dim=1)
        return Qtilde


class CRFRNNNew(nn.Module):
    """ Break meanfields down as CNN and do iteration """

    def __init__(self, n_iter, in_channels, n_classes, kernel_size=[3, 3],
        theta_alpha=[1.5, 2.5], theta_beta=[1.5, 2.5], theta_gamma=[1.5]):
        super(CRFRNNNew, self).__init__()
        self.n_iter = n_iter
        self.n_classes = n_classes
        n_filters = in_channels * len(theta_alpha) + len(theta_gamma)
        self.softmax = nn.Softmax2d()
        self.messagepassing = MessagePassing(in_channels, n_classes,
            kernel_size=kernel_size, theta_alpha=theta_alpha, theta_beta=
            theta_beta, theta_gamma=theta_gamma)
        self.weightfiltering = Parameter(torch.rand(1, n_filters, n_classes,
            1, 1))
        self.compatibilitytransf = nn.Conv2d(n_classes, n_classes,
            kernel_size=1, stride=1, padding=0, bias=False)
        self._weight_initial()
        self.train_step = 0

    def _weight_initial(self):
        init.kaiming_normal_(self.weightfiltering)
        init.kaiming_normal_(self.compatibilitytransf.weight)

    def forward(self, input_0, input_1):
        primals_10 = self.weightfiltering
        primals_5 = self.messagepassing.bilateral0.spatial_weight
        primals_3 = self.messagepassing.bilateral0.gauss_mask_I.conv.weight
        primals_4 = self.messagepassing.bilateral0.guass_mask_Q.conv.weight
        primals_8 = self.messagepassing.bilateral1.spatial_weight
        primals_6 = self.messagepassing.bilateral1.gauss_mask_I.conv.weight
        primals_7 = self.messagepassing.bilateral1.guass_mask_Q.conv.weight
        primals_9 = self.messagepassing.spatial0.conv.weight
        primals_11 = self.compatibilitytransf.weight
        primals_1 = input_0
        primals_2 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11])
        return output[0]
