import torch
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 libdevice
from torch import Tensor
from torch.nn import Parameter
from typing import Optional
import torch.fx
from typing import Any
import torch.utils.data
from inspect import Parameter
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


@triton.jit
def triton_per_fused_add_div_mean_mul_std_sub_0(in_out_ptr0, in_out_ptr1,
    in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    RBLOCK: tl.constexpr = 256
    xoffset = tl.program_id(0) * XBLOCK
    tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    tl.full([RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp25 = tl.load(in_ptr1 + 0)
    tmp26 = tl.broadcast_to(tmp25, [RBLOCK])
    tmp28 = tl.load(in_ptr2 + 0)
    tmp29 = tl.broadcast_to(tmp28, [RBLOCK])
    tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
    tmp3 = triton_helpers.promote_to_tensor(tl.sum(tmp1, 0))
    tmp4 = 256.0
    tmp5 = tmp3 / tmp4
    tmp6 = tmp0 - tmp5
    tmp7 = tl.broadcast_to(tmp6, [RBLOCK])
    tmp9 = tl.broadcast_to(tmp7, [RBLOCK])
    tmp11 = triton_helpers.promote_to_tensor(tl.sum(tmp9, 0))
    tmp12 = tl.full([1], 256, tl.int32)
    tmp13 = tmp12.to(tl.float32)
    tmp14 = tmp11 / tmp13
    tmp15 = tmp7 - tmp14
    tmp16 = tmp15 * tmp15
    tmp17 = tl.broadcast_to(tmp16, [RBLOCK])
    tmp19 = triton_helpers.promote_to_tensor(tl.sum(tmp17, 0))
    tmp20 = tmp19 / tmp4
    tmp21 = libdevice.sqrt(tmp20)
    tmp22 = 1e-05
    tmp23 = tmp21 + tmp22
    tmp24 = tmp6 / tmp23
    tmp27 = tmp24 * tmp26
    tmp30 = tmp27 + tmp29
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp5, None)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + tl.full([1], 0, tl.int32), tmp23, None)
    tl.store(out_ptr0 + tl.broadcast_to(r0, [RBLOCK]), tmp30, None)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (1,), (1,))
    assert_size_stride(primals_3, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((), (), torch.float32)
        buf1 = buf0
        del buf0
        buf3 = empty_strided_cuda((), (), torch.float32)
        buf5 = buf3
        del buf3
        buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_per_fused_add_div_mean_mul_std_sub_0[grid(1)](buf1, buf5,
            primals_1, primals_2, primals_3, buf6, 1, 256, num_warps=2,
            num_stages=1)
        del primals_2
        del primals_3
    return buf6, primals_1, buf1, buf5


def maybe_num_nodes(edge_index, num_nodes=None):
    if num_nodes is not None:
        return num_nodes
    elif isinstance(edge_index, Tensor):
        return int(edge_index.max()) + 1 if edge_index.numel() > 0 else 0
    else:
        return max(edge_index.size(0), edge_index.size(1))


def constant(value: 'Any', fill_value: 'float'):
    if isinstance(value, Tensor):
        value.data.fill_(fill_value)
    else:
        for v in (value.parameters() if hasattr(value, 'parameters') else []):
            constant(v, fill_value)
        for v in (value.buffers() if hasattr(value, 'buffers') else []):
            constant(v, fill_value)


def zeros(value: 'Any'):
    constant(value, 0.0)


def ones(tensor: 'Any'):
    constant(tensor, 1.0)


def degree(index, num_nodes: 'Optional[int]'=None, dtype: 'Optional[int]'=None
    ):
    """Computes the (unweighted) degree of a given one-dimensional index
    tensor.

    Args:
        index (LongTensor): Index tensor.
        num_nodes (int, optional): The number of nodes, *i.e.*
            :obj:`max_val + 1` of :attr:`index`. (default: :obj:`None`)
        dtype (:obj:`torch.dtype`, optional): The desired data type of the
            returned tensor.

    :rtype: :class:`Tensor`
    """
    N = maybe_num_nodes(index, num_nodes)
    out = torch.zeros((N,), dtype=dtype, device=index.device)
    one = torch.ones((index.size(0),), dtype=out.dtype, device=out.device)
    return out.scatter_add_(0, index, one)


class LayerNormNew(torch.nn.Module):
    """Applies layer normalization over each individual example in a batch
    of node features as described in the `"Layer Normalization"
    <https://arxiv.org/abs/1607.06450>`_ paper

    .. math::
        \\mathbf{x}^{\\prime}_i = \\frac{\\mathbf{x} -
        \\textrm{E}[\\mathbf{x}]}{\\sqrt{\\textrm{Var}[\\mathbf{x}] + \\epsilon}}
        \\odot \\gamma + \\beta

    The mean and standard-deviation are calculated across all nodes and all
    node channels separately for each object in a mini-batch.

    Args:
        in_channels (int): Size of each input sample.
        eps (float, optional): A value added to the denominator for numerical
            stability. (default: :obj:`1e-5`)
        affine (bool, optional): If set to :obj:`True`, this module has
            learnable affine parameters :math:`\\gamma` and :math:`\\beta`.
            (default: :obj:`True`)
    """

    def __init__(self, in_channels, eps=1e-05, affine=True):
        super(LayerNormNew, self).__init__()
        self.in_channels = in_channels
        self.eps = eps
        if affine:
            self.weight = Parameter(torch.Tensor([in_channels]))
            self.bias = Parameter(torch.Tensor([in_channels]))
        else:
            self.register_parameter('weight', None)
            self.register_parameter('bias', None)
        self.reset_parameters()

    def reset_parameters(self):
        ones(self.weight)
        zeros(self.bias)

    def __repr__(self):
        return f'{self.__class__.__name__}({self.in_channels})'

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


Measured latency_ms: 0.013747