# 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_7/inductor_cache/45/c45e2c4xlsryjzha4kwkpovw6f7gjxrkeaa2uy3nd7iqhfroie2b.py
# Topologically Sorted Source Nodes: [probs], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   probs => amax, exp, sub, sum_1
# Graph fragment:
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%view_2, [2], True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%view_2, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub,), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [2], True), 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: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), 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': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', '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, out_ptr1, 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 + (5*x0), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + (5*x0)), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + (5*x0)), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + (5*x0)), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (4 + (5*x0)), xmask, eviction_policy='evict_last')
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp6 = triton_helpers.maximum(tmp4, tmp5)
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp0 - tmp8
    tmp10 = tl_math.exp(tmp9)
    tmp11 = tmp1 - tmp8
    tmp12 = tl_math.exp(tmp11)
    tmp13 = tmp10 + tmp12
    tmp14 = tmp3 - tmp8
    tmp15 = tl_math.exp(tmp14)
    tmp16 = tmp13 + tmp15
    tmp17 = tmp5 - tmp8
    tmp18 = tl_math.exp(tmp17)
    tmp19 = tmp16 + tmp18
    tmp20 = tmp7 - tmp8
    tmp21 = tl_math.exp(tmp20)
    tmp22 = tmp19 + tmp21
    tl.store(out_ptr0 + (x0), tmp8, xmask)
    tl.store(out_ptr1 + (x0), tmp22, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/w6/cw6xtenyazqrrjyylbvm5uy5biotvroknofocfkvb4x3pby2sda6.py
# Topologically Sorted Source Nodes: [probs], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   probs => amax, div, exp, sub, sum_1
# Graph fragment:
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%view_2, [2], True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%view_2, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub,), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [2], True), kwargs = {})
#   %div : [num_users=5] = 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=[2048], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_1', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 3, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', '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_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK : tl.constexpr):
    xnumel = 1280
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = (xindex // 5)
    tmp0 = tl.load(in_out_ptr0 + (x2), xmask)
    tmp1 = tl.load(in_ptr0 + (x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (x1), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp3 = tl_math.exp(tmp2)
    tmp5 = tmp3 / tmp4
    tl.store(in_out_ptr0 + (x2), tmp5, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/k5/ck5cqp5iaitgnpbr5mbenp52ja4zazjq4wb5u2p433wf2kgqm75t.py
# Topologically Sorted Source Nodes: [sub, mul, getitem_2, sub_1, slot_total, alloc, sub_2, mul_2, getitem_4, sub_3, slot_total_1, alloc_1, sub_4, mul_4, getitem_6, sub_5, slot_total_2, alloc_2], Original ATen: [aten.rsub, aten.mul, aten.index, aten.add]
# Source node to ATen node mapping:
#   alloc => add
#   alloc_1 => add_2
#   alloc_2 => add_4
#   getitem_2 => index
#   getitem_4 => index_1
#   getitem_6 => index_2
#   mul => mul
#   mul_2 => mul_2
#   mul_4 => mul_4
#   slot_total => mul_1
#   slot_total_1 => mul_3
#   slot_total_2 => mul_5
#   sub => sub_1
#   sub_1 => sub_2
#   sub_2 => sub_3
#   sub_3 => sub_4
#   sub_4 => sub_5
#   sub_5 => sub_6
# Graph fragment:
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %slice_2), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_1, %slice_4), kwargs = {})
#   %index : [num_users=1] = call_function[target=torch.ops.aten.index.Tensor](args = (%select, [None, %lift_fresh_copy]), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %index), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul, %sub_2), kwargs = {})
#   %add : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%slice_2, %mul_1), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %add), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_3, %slice_7), kwargs = {})
#   %index_1 : [num_users=1] = call_function[target=torch.ops.aten.index.Tensor](args = (%select_1, [None, %lift_fresh_copy_1]), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %index_1), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_2, %sub_4), kwargs = {})
#   %add_2 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%add, %mul_3), kwargs = {})
#   %sub_5 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %add_2), kwargs = {})
#   %mul_4 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_5, %slice_10), kwargs = {})
#   %index_2 : [num_users=1] = call_function[target=torch.ops.aten.index.Tensor](args = (%select_3, [None, %lift_fresh_copy_2]), kwargs = {})
#   %sub_6 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %index_2), kwargs = {})
#   %mul_5 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_4, %sub_6), kwargs = {})
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_2, %mul_5), kwargs = {})
triton_poi_fused_add_index_mul_rsub_2 = async_compile.triton('triton_poi_fused_add_index_mul_rsub_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=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_index_mul_rsub_2', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 4, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', '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_add_index_mul_rsub_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = (xindex // 4)
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + (20*x1)), xmask)
    tmp3 = tl.load(in_ptr0 + (5 + x0 + (20*x1)), xmask)
    tmp21 = tl.load(in_ptr0 + (10 + x0 + (20*x1)), xmask)
    tmp28 = tl.load(in_ptr0 + (15 + x0 + (20*x1)), xmask)
    tmp1 = 1.0
    tmp2 = tmp1 - tmp0
    tmp4 = tmp2 * tmp3
    tmp5 = x0
    tmp6 = tl.full([1], 2, tl.int64)
    tmp7 = tmp5 < tmp6
    tmp8 = tl.full([1], 1, tl.int64)
    tmp9 = tmp5 < tmp8
    tmp10 = tl.full([1], 4, tl.int64)
    tmp11 = tl.where(tmp9, tmp10, tmp10)
    tmp12 = tl.full([1], 3, tl.int64)
    tmp13 = tmp5 < tmp12
    tmp14 = tl.where(tmp13, tmp10, tmp10)
    tmp15 = tl.where(tmp7, tmp11, tmp14)
    tmp16 = tl.load(in_ptr0 + (tmp15 + (20*x1)), xmask, eviction_policy='evict_last')
    tmp17 = tmp1 - tmp16
    tmp18 = tmp4 * tmp17
    tmp19 = tmp0 + tmp18
    tmp20 = tmp1 - tmp19
    tmp22 = tmp20 * tmp21
    tmp23 = tl.load(in_ptr0 + (5 + tmp15 + (20*x1)), xmask, eviction_policy='evict_last')
    tmp24 = tmp1 - tmp23
    tmp25 = tmp22 * tmp24
    tmp26 = tmp19 + tmp25
    tmp27 = tmp1 - tmp26
    tmp29 = tmp27 * tmp28
    tmp30 = tl.load(in_ptr0 + (10 + tmp15 + (20*x1)), xmask, eviction_policy='evict_last')
    tmp31 = tmp1 - tmp30
    tmp32 = tmp29 * tmp31
    tmp33 = tmp26 + tmp32
    tl.store(in_out_ptr0 + (x2), tmp33, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (20, 4), (4, 1))
    assert_size_stride(primals_2, (20, ), (1, ))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((64, 20), (20, 1), torch.float32)
        # Topologically Sorted Source Nodes: [linear], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 20), (1, 4), 0), alpha=1, beta=1, out=buf0)
        del primals_1
        del primals_2
        buf1 = empty_strided_cuda((64, 4, 1), (4, 1, 256), torch.float32)
        buf2 = empty_strided_cuda((64, 4, 1), (4, 1, 256), torch.float32)
        # Topologically Sorted Source Nodes: [probs], Original ATen: [aten._softmax]
        stream0 = get_raw_stream(0)
        triton_poi_fused__softmax_0.run(buf0, buf1, buf2, 256, grid=grid(256), stream=stream0)
        buf3 = reinterpret_tensor(buf0, (64, 4, 5), (20, 5, 1), 0); del buf0  # reuse
        # Topologically Sorted Source Nodes: [probs], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf3, buf1, buf2, 1280, grid=grid(1280), stream=stream0)
        del buf1
        buf4 = reinterpret_tensor(buf2, (64, 4), (4, 1), 0); del buf2  # reuse
        buf5 = buf4; del buf4  # reuse
        # Topologically Sorted Source Nodes: [sub, mul, getitem_2, sub_1, slot_total, alloc, sub_2, mul_2, getitem_4, sub_3, slot_total_1, alloc_1, sub_4, mul_4, getitem_6, sub_5, slot_total_2, alloc_2], Original ATen: [aten.rsub, aten.mul, aten.index, aten.add]
        triton_poi_fused_add_index_mul_rsub_2.run(buf5, buf3, 256, grid=grid(256), stream=stream0)
    return (buf5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf3, )


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((20, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((20, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2, primals_3])
    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)

from torch.nn import Module
import torch
from torch.nn import functional as F
from torch.nn import Linear


def _sequential_allocation(p, weights):
    _, slots, bidders_plus_one = p.shape
    bidders = bidders_plus_one - 1
    cumulative_total = p[:, 0, :bidders]
    if weights is None:
        alloc = cumulative_total
    else:
        alloc = cumulative_total * weights[0]
    for k in range(1, slots):
        slot_total = (1 - cumulative_total) * p[:, k, :bidders] * (1 - p[:,
            k - 1, [bidders for _ in range(bidders)]])
        if weights is None:
            alloc = alloc + slot_total
        else:
            alloc = alloc + slot_total * weights[k]
        cumulative_total = cumulative_total + slot_total
    return alloc


class SequentialAllocation(Module):
    __constants__ = ['in_features', 'bidders', 'slots', 'weights']

    def __init__(self, in_features, slots, bidders, weights=None):
        super(SequentialAllocation, self).__init__()
        self.in_features = in_features
        self.slots = slots
        self.bidders = bidders
        self.weights = weights
        self.linear = Linear(in_features, slots * (bidders + 1))

    def forward(self, x):
        probs = F.softmax(self.linear(x).reshape(-1, self.slots, self.
            bidders + 1), dim=2)
        return _sequential_allocation(probs, weights=self.weights)


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


def get_init_inputs():
    return [[], {'in_features': 4, 'slots': 4, 'bidders': 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
from torch.nn import Module
from torch.nn import Linear
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, out_ptr1, 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 + 5 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 5 * x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 5 * x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + 5 * x0), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (4 + 5 * x0), xmask, eviction_policy='evict_last')
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp6 = triton_helpers.maximum(tmp4, tmp5)
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp0 - tmp8
    tmp10 = tl_math.exp(tmp9)
    tmp11 = tmp1 - tmp8
    tmp12 = tl_math.exp(tmp11)
    tmp13 = tmp10 + tmp12
    tmp14 = tmp3 - tmp8
    tmp15 = tl_math.exp(tmp14)
    tmp16 = tmp13 + tmp15
    tmp17 = tmp5 - tmp8
    tmp18 = tl_math.exp(tmp17)
    tmp19 = tmp16 + tmp18
    tmp20 = tmp7 - tmp8
    tmp21 = tl_math.exp(tmp20)
    tmp22 = tmp19 + tmp21
    tl.store(out_ptr0 + x0, tmp8, xmask)
    tl.store(out_ptr1 + x0, tmp22, xmask)


@triton.jit
def triton_poi_fused__softmax_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 1280
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 5
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp3 = tl_math.exp(tmp2)
    tmp5 = tmp3 / tmp4
    tl.store(in_out_ptr0 + x2, tmp5, xmask)


@triton.jit
def triton_poi_fused_add_index_mul_rsub_2(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = xindex // 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 20 * x1), xmask)
    tmp3 = tl.load(in_ptr0 + (5 + x0 + 20 * x1), xmask)
    tmp21 = tl.load(in_ptr0 + (10 + x0 + 20 * x1), xmask)
    tmp28 = tl.load(in_ptr0 + (15 + x0 + 20 * x1), xmask)
    tmp1 = 1.0
    tmp2 = tmp1 - tmp0
    tmp4 = tmp2 * tmp3
    tmp5 = x0
    tmp6 = tl.full([1], 2, tl.int64)
    tmp7 = tmp5 < tmp6
    tmp8 = tl.full([1], 1, tl.int64)
    tmp9 = tmp5 < tmp8
    tmp10 = tl.full([1], 4, tl.int64)
    tmp11 = tl.where(tmp9, tmp10, tmp10)
    tmp12 = tl.full([1], 3, tl.int64)
    tmp13 = tmp5 < tmp12
    tmp14 = tl.where(tmp13, tmp10, tmp10)
    tmp15 = tl.where(tmp7, tmp11, tmp14)
    tmp16 = tl.load(in_ptr0 + (tmp15 + 20 * x1), xmask, eviction_policy=
        'evict_last')
    tmp17 = tmp1 - tmp16
    tmp18 = tmp4 * tmp17
    tmp19 = tmp0 + tmp18
    tmp20 = tmp1 - tmp19
    tmp22 = tmp20 * tmp21
    tmp23 = tl.load(in_ptr0 + (5 + tmp15 + 20 * x1), xmask, eviction_policy
        ='evict_last')
    tmp24 = tmp1 - tmp23
    tmp25 = tmp22 * tmp24
    tmp26 = tmp19 + tmp25
    tmp27 = tmp1 - tmp26
    tmp29 = tmp27 * tmp28
    tmp30 = tl.load(in_ptr0 + (10 + tmp15 + 20 * x1), xmask,
        eviction_policy='evict_last')
    tmp31 = tmp1 - tmp30
    tmp32 = tmp29 * tmp31
    tmp33 = tmp26 + tmp32
    tl.store(in_out_ptr0 + x2, tmp33, xmask)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (20, 4), (4, 1))
    assert_size_stride(primals_2, (20,), (1,))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((64, 20), (20, 1), torch.float32)
        extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 
            4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 20), (1, 4), 
            0), alpha=1, beta=1, out=buf0)
        del primals_1
        del primals_2
        buf1 = empty_strided_cuda((64, 4, 1), (4, 1, 256), torch.float32)
        buf2 = empty_strided_cuda((64, 4, 1), (4, 1, 256), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__softmax_0[grid(256)](buf0, buf1, buf2, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        buf3 = reinterpret_tensor(buf0, (64, 4, 5), (20, 5, 1), 0)
        del buf0
        triton_poi_fused__softmax_1[grid(1280)](buf3, buf1, buf2, 1280,
            XBLOCK=256, num_warps=4, num_stages=1)
        del buf1
        buf4 = reinterpret_tensor(buf2, (64, 4), (4, 1), 0)
        del buf2
        buf5 = buf4
        del buf4
        triton_poi_fused_add_index_mul_rsub_2[grid(256)](buf5, buf3, 256,
            XBLOCK=128, num_warps=4, num_stages=1)
    return buf5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf3


def _sequential_allocation(p, weights):
    _, slots, bidders_plus_one = p.shape
    bidders = bidders_plus_one - 1
    cumulative_total = p[:, 0, :bidders]
    if weights is None:
        alloc = cumulative_total
    else:
        alloc = cumulative_total * weights[0]
    for k in range(1, slots):
        slot_total = (1 - cumulative_total) * p[:, k, :bidders] * (1 - p[:,
            k - 1, [bidders for _ in range(bidders)]])
        if weights is None:
            alloc = alloc + slot_total
        else:
            alloc = alloc + slot_total * weights[k]
        cumulative_total = cumulative_total + slot_total
    return alloc


class SequentialAllocationNew(Module):
    __constants__ = ['in_features', 'bidders', 'slots', 'weights']

    def __init__(self, in_features, slots, bidders, weights=None):
        super(SequentialAllocationNew, self).__init__()
        self.in_features = in_features
        self.slots = slots
        self.bidders = bidders
        self.weights = weights
        self.linear = Linear(in_features, slots * (bidders + 1))

    def forward(self, input_0):
        primals_1 = self.linear.weight
        primals_2 = self.linear.bias
        primals_3 = input_0
        output = call([primals_1, primals_2, primals_3])
        return output[0]
