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.triton_helpers import libdevice
from torch import Tensor
from typing import List
from typing import Tuple
from torch import nn
from functools import partial
from torch.nn.parameter 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_stack_0(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
    tmp0 = 0.0
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused_clone_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 64
    xnumel = 4
    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 % 16
    y1 = yindex // 16
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 16 * x2 + 64 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)


@triton.jit
def triton_poi_fused_add_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 192
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 48
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x2, tmp2, xmask)


@triton.jit
def triton_poi_fused_add_mul_rsub_sigmoid_tanh_3(in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, out_ptr0, out_ptr1, out_ptr2, out_ptr3, 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 + (16 + x0 + 192 * x1), xmask)
    tmp1 = tl.load(in_ptr1 + (16 + x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + (16 + x0 + 48 * x1), xmask)
    tmp6 = tl.load(in_ptr0 + (x0 + 192 * x1), xmask)
    tmp7 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + (x0 + 48 * x1), xmask)
    tmp12 = tl.load(in_ptr0 + (32 + x0 + 192 * x1), xmask)
    tmp13 = tl.load(in_ptr1 + (32 + x0), xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr2 + (32 + x0 + 48 * x1), xmask)
    tmp22 = tl.load(in_ptr3 + x2, xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp5 = tl.sigmoid(tmp4)
    tmp8 = tmp6 + tmp7
    tmp10 = tmp8 + tmp9
    tmp11 = tl.sigmoid(tmp10)
    tmp14 = tmp12 + tmp13
    tmp16 = tmp11 * tmp15
    tmp17 = tmp14 + tmp16
    tmp18 = libdevice.tanh(tmp17)
    tmp19 = 1.0
    tmp20 = tmp19 - tmp5
    tmp21 = tmp20 * tmp18
    tmp23 = tmp5 * tmp22
    tmp24 = tmp21 + tmp23
    tl.store(out_ptr0 + x2, tmp5, xmask)
    tl.store(out_ptr1 + x2, tmp11, xmask)
    tl.store(out_ptr2 + x2, tmp18, xmask)
    tl.store(out_ptr3 + x2, tmp24, xmask)


@triton.jit
def triton_poi_fused_add_mul_rsub_sigmoid_tanh_4(in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, out_ptr0, out_ptr1, out_ptr2, out_ptr3, 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 + (64 + x0 + 192 * x1), xmask)
    tmp1 = tl.load(in_ptr1 + (16 + x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + (16 + x0 + 48 * x1), xmask)
    tmp6 = tl.load(in_ptr0 + (48 + x0 + 192 * x1), xmask)
    tmp7 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + (x0 + 48 * x1), xmask)
    tmp12 = tl.load(in_ptr0 + (80 + x0 + 192 * x1), xmask)
    tmp13 = tl.load(in_ptr1 + (32 + x0), xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr2 + (32 + x0 + 48 * x1), xmask)
    tmp22 = tl.load(in_ptr3 + x2, xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp5 = tl.sigmoid(tmp4)
    tmp8 = tmp6 + tmp7
    tmp10 = tmp8 + tmp9
    tmp11 = tl.sigmoid(tmp10)
    tmp14 = tmp12 + tmp13
    tmp16 = tmp11 * tmp15
    tmp17 = tmp14 + tmp16
    tmp18 = libdevice.tanh(tmp17)
    tmp19 = 1.0
    tmp20 = tmp19 - tmp5
    tmp21 = tmp20 * tmp18
    tmp23 = tmp5 * tmp22
    tmp24 = tmp21 + tmp23
    tl.store(out_ptr0 + x2, tmp5, xmask)
    tl.store(out_ptr1 + x2, tmp11, xmask)
    tl.store(out_ptr2 + x2, tmp18, xmask)
    tl.store(out_ptr3 + x2, tmp24, xmask)


@triton.jit
def triton_poi_fused_add_mul_rsub_sigmoid_tanh_5(in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, out_ptr0, out_ptr1, out_ptr2, out_ptr3, 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 + (112 + x0 + 192 * x1), xmask)
    tmp1 = tl.load(in_ptr1 + (16 + x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + (16 + x0 + 48 * x1), xmask)
    tmp6 = tl.load(in_ptr0 + (96 + x0 + 192 * x1), xmask)
    tmp7 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + (x0 + 48 * x1), xmask)
    tmp12 = tl.load(in_ptr0 + (128 + x0 + 192 * x1), xmask)
    tmp13 = tl.load(in_ptr1 + (32 + x0), xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr2 + (32 + x0 + 48 * x1), xmask)
    tmp22 = tl.load(in_ptr3 + x2, xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp5 = tl.sigmoid(tmp4)
    tmp8 = tmp6 + tmp7
    tmp10 = tmp8 + tmp9
    tmp11 = tl.sigmoid(tmp10)
    tmp14 = tmp12 + tmp13
    tmp16 = tmp11 * tmp15
    tmp17 = tmp14 + tmp16
    tmp18 = libdevice.tanh(tmp17)
    tmp19 = 1.0
    tmp20 = tmp19 - tmp5
    tmp21 = tmp20 * tmp18
    tmp23 = tmp5 * tmp22
    tmp24 = tmp21 + tmp23
    tl.store(out_ptr0 + x2, tmp5, xmask)
    tl.store(out_ptr1 + x2, tmp11, xmask)
    tl.store(out_ptr2 + x2, tmp18, xmask)
    tl.store(out_ptr3 + x2, tmp24, xmask)


@triton.jit
def triton_poi_fused_add_mul_rsub_sigmoid_tanh_6(in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, out_ptr0, out_ptr1, out_ptr2, out_ptr3, 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 + (160 + x0 + 192 * x1), xmask)
    tmp1 = tl.load(in_ptr1 + (16 + x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + (16 + x0 + 48 * x1), xmask)
    tmp6 = tl.load(in_ptr0 + (144 + x0 + 192 * x1), xmask)
    tmp7 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + (x0 + 48 * x1), xmask)
    tmp12 = tl.load(in_ptr0 + (176 + x0 + 192 * x1), xmask)
    tmp13 = tl.load(in_ptr1 + (32 + x0), xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr2 + (32 + x0 + 48 * x1), xmask)
    tmp22 = tl.load(in_ptr3 + x2, xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp5 = tl.sigmoid(tmp4)
    tmp8 = tmp6 + tmp7
    tmp10 = tmp8 + tmp9
    tmp11 = tl.sigmoid(tmp10)
    tmp14 = tmp12 + tmp13
    tmp16 = tmp11 * tmp15
    tmp17 = tmp14 + tmp16
    tmp18 = libdevice.tanh(tmp17)
    tmp19 = 1.0
    tmp20 = tmp19 - tmp5
    tmp21 = tmp20 * tmp18
    tmp23 = tmp5 * tmp22
    tmp24 = tmp21 + tmp23
    tl.store(out_ptr0 + x2, tmp5, xmask)
    tl.store(out_ptr1 + x2, tmp11, xmask)
    tl.store(out_ptr2 + x2, tmp18, xmask)
    tl.store(out_ptr3 + x2, tmp24, xmask)


@triton.jit
def triton_poi_fused_stack_7(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 4
    x0 = xindex % 16
    x2 = xindex // 64
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tmp7 = tl.full([1], 2, tl.int64)
    tmp8 = tmp0 < tmp7
    tmp9 = tmp6 & tmp8
    tmp10 = tl.load(in_ptr1 + (x0 + 16 * x2), tmp9 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp11 = tmp0 >= tmp7
    tmp12 = tl.full([1], 3, tl.int64)
    tmp13 = tmp0 < tmp12
    tmp14 = tmp11 & tmp13
    tmp15 = tl.load(in_ptr2 + (x0 + 16 * x2), tmp14 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp16 = tmp0 >= tmp12
    tl.full([1], 4, tl.int64)
    tmp19 = tl.load(in_ptr3 + (x0 + 16 * x2), tmp16 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp20 = 1.0
    tmp21 = tmp20 - tmp19
    tmp22 = tl.load(in_ptr4 + (x0 + 16 * x2), tmp16 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp23 = tmp21 * tmp22
    tmp24 = tl.load(in_ptr2 + (x0 + 16 * x2), tmp16 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp25 = tmp19 * tmp24
    tmp26 = tmp23 + tmp25
    tmp27 = tl.full(tmp26.shape, 0.0, tmp26.dtype)
    tmp28 = tl.where(tmp16, tmp26, tmp27)
    tmp29 = tl.where(tmp14, tmp15, tmp28)
    tmp30 = tl.where(tmp9, tmp10, tmp29)
    tmp31 = tl.where(tmp4, tmp5, tmp30)
    tl.store(out_ptr0 + x3, tmp31, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (1, 48, 16), (768, 16, 1))
    assert_size_stride(primals_3, (1, 48), (48, 1))
    assert_size_stride(primals_4, (1, 48, 16), (768, 16, 1))
    assert_size_stride(primals_5, (1, 48), (48, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((1, 4, 1, 16), (64, 16, 16, 1), torch.float32
            )
        get_raw_stream(0)
        triton_poi_fused_stack_0[grid(64)](buf0, 64, XBLOCK=64, num_warps=1,
            num_stages=1)
        buf1 = empty_strided_cuda((4, 4, 1, 4, 4), (64, 16, 16, 4, 1),
            torch.float32)
        triton_poi_fused_clone_1[grid(64, 4)](primals_1, buf1, 64, 4,
            XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_1
        buf2 = empty_strided_cuda((1, 16, 48), (768, 48, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf1, (1, 16, 16), (0, 16, 1),
            0), reinterpret_tensor(primals_2, (1, 16, 48), (0, 1, 16), 0),
            out=buf2)
        del primals_2
        buf3 = empty_strided_cuda((1, 4, 48), (192, 48, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf0, (1, 4, 16), (64, 16, 1),
            0), reinterpret_tensor(primals_4, (1, 16, 48), (0, 1, 16), 0),
            out=buf3)
        buf4 = reinterpret_tensor(buf3, (4, 1, 48), (48, 48, 1), 0)
        del buf3
        triton_poi_fused_add_2[grid(192)](buf4, primals_5, 192, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf6 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        buf5 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        buf7 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        buf8 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        triton_poi_fused_add_mul_rsub_sigmoid_tanh_3[grid(64)](buf2,
            primals_3, buf4, buf0, buf6, buf5, buf7, buf8, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf9 = empty_strided_cuda((1, 4, 48), (192, 48, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf8, (1, 4, 16), (64, 16, 1),
            0), reinterpret_tensor(primals_4, (1, 16, 48), (0, 1, 16), 0),
            out=buf9)
        buf10 = reinterpret_tensor(buf9, (4, 1, 48), (48, 48, 1), 0)
        del buf9
        triton_poi_fused_add_2[grid(192)](buf10, primals_5, 192, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf12 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        buf11 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        buf13 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        buf14 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        triton_poi_fused_add_mul_rsub_sigmoid_tanh_4[grid(64)](buf2,
            primals_3, buf10, buf8, buf12, buf11, buf13, buf14, 64, XBLOCK=
            64, num_warps=1, num_stages=1)
        buf15 = empty_strided_cuda((1, 4, 48), (192, 48, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf14, (1, 4, 16), (64, 16, 1
            ), 0), reinterpret_tensor(primals_4, (1, 16, 48), (0, 1, 16), 0
            ), out=buf15)
        buf16 = reinterpret_tensor(buf15, (4, 1, 48), (48, 48, 1), 0)
        del buf15
        triton_poi_fused_add_2[grid(192)](buf16, primals_5, 192, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf18 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        buf17 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        buf19 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        buf20 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        triton_poi_fused_add_mul_rsub_sigmoid_tanh_5[grid(64)](buf2,
            primals_3, buf16, buf14, buf18, buf17, buf19, buf20, 64, XBLOCK
            =64, num_warps=1, num_stages=1)
        buf21 = empty_strided_cuda((1, 4, 48), (192, 48, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf20, (1, 4, 16), (64, 16, 1
            ), 0), reinterpret_tensor(primals_4, (1, 16, 48), (0, 1, 16), 0
            ), out=buf21)
        buf22 = reinterpret_tensor(buf21, (4, 1, 48), (48, 48, 1), 0)
        del buf21
        triton_poi_fused_add_2[grid(192)](buf22, primals_5, 192, XBLOCK=128,
            num_warps=4, num_stages=1)
        del primals_5
        buf24 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        buf23 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        buf25 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        buf27 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32)
        triton_poi_fused_add_mul_rsub_sigmoid_tanh_6[grid(64)](buf2,
            primals_3, buf22, buf20, buf24, buf23, buf25, buf27, 64, XBLOCK
            =64, num_warps=1, num_stages=1)
        del buf2
        del primals_3
        buf26 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32)
        triton_poi_fused_stack_7[grid(256)](buf8, buf14, buf20, buf24,
            buf25, buf26, 256, XBLOCK=128, num_warps=4, num_stages=1)
    return reinterpret_tensor(buf26, (4, 4, 4, 4), (64, 1, 16, 4), 0
        ), reinterpret_tensor(buf27, (1, 4, 1, 16), (64, 16, 16, 1), 0
        ), reinterpret_tensor(buf0, (4, 1, 16), (16, 16, 1), 0
        ), reinterpret_tensor(buf4, (4, 1, 16), (48, 48, 1), 32
        ), buf5, buf6, buf7, buf8, reinterpret_tensor(buf10, (4, 1, 16), (
        48, 48, 1), 32), buf11, buf12, buf13, buf14, reinterpret_tensor(buf16,
        (4, 1, 16), (48, 48, 1), 32
        ), buf17, buf18, buf19, buf20, reinterpret_tensor(buf22, (4, 1, 16),
        (48, 48, 1), 32), buf23, buf24, buf25, reinterpret_tensor(primals_4,
        (1, 48, 16), (16, 16, 1), 0), reinterpret_tensor(buf1, (1, 16, 16),
        (256, 1, 16), 0)


class GroupedGRULayerMS(nn.Module):

    def __init__(self, in_ch: 'int', out_ch: 'int', n_freqs: 'int',
        n_groups: 'int', bias: 'bool'=True):
        super().__init__()
        assert n_freqs % n_groups == 0
        self.n_freqs = n_freqs
        self.g_freqs = n_freqs // n_groups
        self.n_groups = n_groups
        self.out_ch = self.g_freqs * out_ch
        self._in_ch = in_ch
        self.input_size = self.g_freqs * in_ch
        self.register_parameter('weight_ih_l', Parameter(torch.zeros(
            n_groups, 3 * self.out_ch, self.input_size), requires_grad=True))
        self.register_parameter('weight_hh_l', Parameter(torch.zeros(
            n_groups, 3 * self.out_ch, self.out_ch), requires_grad=True))
        if bias:
            self.register_parameter('bias_ih_l', Parameter(torch.zeros(
                n_groups, 3 * self.out_ch), requires_grad=True))
            self.register_parameter('bias_hh_l', Parameter(torch.zeros(
                n_groups, 3 * self.out_ch), requires_grad=True))
        else:
            self.bias_ih_l = None
            self.bias_hh_l = None

    def init_hidden(self, batch_size: 'int', device: 'torch.device'=torch.
        device('cpu')) ->Tensor:
        return torch.zeros(batch_size, self.n_groups, self.out_ch, device=
            device)

    def forward(self, input: 'Tensor', h=None) ->Tuple[Tensor, Tensor]:
        assert self.n_freqs == input.shape[-1]
        assert self._in_ch == input.shape[1]
        if h is None:
            h = self.init_hidden(input.shape[0])
        input = input.permute(0, 2, 3, 1).unflatten(2, (self.n_groups, self
            .g_freqs)).flatten(3)
        input = torch.einsum('btgi,goi->btgo', input, self.weight_ih_l)
        if self.bias_ih_l is not None:
            input = input + self.bias_ih_l
        h_out: 'List[Tensor]' = []
        for t in range(input.shape[1]):
            hh = torch.einsum('bgo,gpo->bgp', h, self.weight_hh_l)
            if self.bias_hh_l is not None:
                hh = hh + self.bias_hh_l
            ri, zi, ni = input[:, t].split(self.out_ch, dim=2)
            rh, zh, nh = hh.split(self.out_ch, dim=2)
            r = torch.sigmoid(ri + rh)
            z = torch.sigmoid(zi + zh)
            n = torch.tanh(ni + r * nh)
            h = (1 - z) * n + z * h
            h_out.append(h)
        out = torch.stack(h_out, dim=1)
        out = out.unflatten(3, (self.g_freqs, -1)).flatten(2, 3)
        out = out.permute(0, 3, 1, 2)
        return out, h


class GroupedGRUMSNew(nn.Module):

    def __init__(self, in_ch: 'int', out_ch: 'int', n_freqs: 'int',
        n_groups: 'int', n_layers: 'int'=1, bias: 'bool'=True, add_outputs:
        'bool'=False):
        super().__init__()
        self.n_layers = n_layers
        self.grus: 'List[GroupedGRULayerMS]' = nn.ModuleList()
        gru_layer = partial(GroupedGRULayerMS, out_ch=out_ch, n_freqs=
            n_freqs, n_groups=n_groups, bias=bias)
        self.gru0 = gru_layer(in_ch=in_ch)
        for _ in range(1, n_layers):
            self.grus.append(gru_layer(in_ch=out_ch))
        self.add_outputs = add_outputs

    def init_hidden(self, batch_size: 'int', device: 'torch.device'=torch.
        device('cpu')) ->Tensor:
        return torch.stack(tuple(self.gru0.init_hidden(batch_size, device) for
            _ in range(self.n_layers)))

    def forward(self, input_0):
        primals_2 = self.gru0.weight_ih_l
        primals_4 = self.gru0.weight_hh_l
        primals_3 = self.gru0.bias_ih_l
        primals_5 = self.gru0.bias_hh_l
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0], output[1]


Measured latency_ms: 0.014919