# 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/dh/cdh7thxgq76cywbiys7o3xrowoojcupcla2vg4oph4hiyptk7cct.py
# Topologically Sorted Source Nodes: [delta, mul, dist, q_idx], Original ATen: [aten.sub, aten.mul, aten.sum, aten.argmin]
# Source node to ATen node mapping:
#   delta => sub
#   dist => sum_1
#   mul => mul
#   q_idx => argmin
# Graph fragment:
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%unsqueeze, %unsqueeze_1), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub, %sub), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul, [-1]), kwargs = {})
#   %argmin : [num_users=2] = call_function[target=torch.ops.aten.argmin.default](args = (%sum_1, -1), kwargs = {})
triton_poi_fused_argmin_mul_sub_sum_0 = async_compile.triton('triton_poi_fused_argmin_mul_sub_sum_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=[4], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*i64', 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), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_argmin_mul_sub_sum_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 20, '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_argmin_mul_sub_sum_0(in_ptr0, in_ptr1, 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 + (0))
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = tl.load(in_ptr1 + (4*x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (1))
    tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
    tmp7 = tl.load(in_ptr1 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + (2))
    tmp12 = tl.broadcast_to(tmp11, [XBLOCK])
    tmp13 = tl.load(in_ptr1 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp17 = tl.load(in_ptr0 + (3))
    tmp18 = tl.broadcast_to(tmp17, [XBLOCK])
    tmp19 = tl.load(in_ptr1 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr0 + (4))
    tmp24 = tl.broadcast_to(tmp23, [XBLOCK])
    tmp27 = tl.load(in_ptr0 + (5))
    tmp28 = tl.broadcast_to(tmp27, [XBLOCK])
    tmp32 = tl.load(in_ptr0 + (6))
    tmp33 = tl.broadcast_to(tmp32, [XBLOCK])
    tmp37 = tl.load(in_ptr0 + (7))
    tmp38 = tl.broadcast_to(tmp37, [XBLOCK])
    tmp57 = tl.load(in_ptr0 + (8))
    tmp58 = tl.broadcast_to(tmp57, [XBLOCK])
    tmp61 = tl.load(in_ptr0 + (9))
    tmp62 = tl.broadcast_to(tmp61, [XBLOCK])
    tmp66 = tl.load(in_ptr0 + (10))
    tmp67 = tl.broadcast_to(tmp66, [XBLOCK])
    tmp71 = tl.load(in_ptr0 + (11))
    tmp72 = tl.broadcast_to(tmp71, [XBLOCK])
    tmp90 = tl.load(in_ptr0 + (12))
    tmp91 = tl.broadcast_to(tmp90, [XBLOCK])
    tmp94 = tl.load(in_ptr0 + (13))
    tmp95 = tl.broadcast_to(tmp94, [XBLOCK])
    tmp99 = tl.load(in_ptr0 + (14))
    tmp100 = tl.broadcast_to(tmp99, [XBLOCK])
    tmp104 = tl.load(in_ptr0 + (15))
    tmp105 = tl.broadcast_to(tmp104, [XBLOCK])
    tmp3 = tmp1 - tmp2
    tmp4 = tmp3 * tmp3
    tmp8 = tmp6 - tmp7
    tmp9 = tmp8 * tmp8
    tmp10 = tmp4 + tmp9
    tmp14 = tmp12 - tmp13
    tmp15 = tmp14 * tmp14
    tmp16 = tmp10 + tmp15
    tmp20 = tmp18 - tmp19
    tmp21 = tmp20 * tmp20
    tmp22 = tmp16 + tmp21
    tmp25 = tmp24 - tmp2
    tmp26 = tmp25 * tmp25
    tmp29 = tmp28 - tmp7
    tmp30 = tmp29 * tmp29
    tmp31 = tmp26 + tmp30
    tmp34 = tmp33 - tmp13
    tmp35 = tmp34 * tmp34
    tmp36 = tmp31 + tmp35
    tmp39 = tmp38 - tmp19
    tmp40 = tmp39 * tmp39
    tmp41 = tmp36 + tmp40
    tmp42 = tmp22 < tmp41
    tmp43 = tmp22 == tmp41
    tmp44 = tmp22 != tmp22
    tmp45 = tmp41 != tmp41
    tmp46 = tmp44 > tmp45
    tmp47 = tmp42 | tmp46
    tmp48 = tmp44 & tmp45
    tmp49 = tmp43 | tmp48
    tmp50 = tl.full([1], 0, tl.int64)
    tmp51 = tl.full([1], 1, tl.int64)
    tmp52 = tmp50 < tmp51
    tmp53 = tmp49 & tmp52
    tmp54 = tmp47 | tmp53
    tmp55 = tl.where(tmp54, tmp22, tmp41)
    tmp56 = tl.where(tmp54, tmp50, tmp51)
    tmp59 = tmp58 - tmp2
    tmp60 = tmp59 * tmp59
    tmp63 = tmp62 - tmp7
    tmp64 = tmp63 * tmp63
    tmp65 = tmp60 + tmp64
    tmp68 = tmp67 - tmp13
    tmp69 = tmp68 * tmp68
    tmp70 = tmp65 + tmp69
    tmp73 = tmp72 - tmp19
    tmp74 = tmp73 * tmp73
    tmp75 = tmp70 + tmp74
    tmp76 = tmp55 < tmp75
    tmp77 = tmp55 == tmp75
    tmp78 = tmp55 != tmp55
    tmp79 = tmp75 != tmp75
    tmp80 = tmp78 > tmp79
    tmp81 = tmp76 | tmp80
    tmp82 = tmp78 & tmp79
    tmp83 = tmp77 | tmp82
    tmp84 = tl.full([1], 2, tl.int64)
    tmp85 = tmp56 < tmp84
    tmp86 = tmp83 & tmp85
    tmp87 = tmp81 | tmp86
    tmp88 = tl.where(tmp87, tmp55, tmp75)
    tmp89 = tl.where(tmp87, tmp56, tmp84)
    tmp92 = tmp91 - tmp2
    tmp93 = tmp92 * tmp92
    tmp96 = tmp95 - tmp7
    tmp97 = tmp96 * tmp96
    tmp98 = tmp93 + tmp97
    tmp101 = tmp100 - tmp13
    tmp102 = tmp101 * tmp101
    tmp103 = tmp98 + tmp102
    tmp106 = tmp105 - tmp19
    tmp107 = tmp106 * tmp106
    tmp108 = tmp103 + tmp107
    tmp109 = tmp88 < tmp108
    tmp110 = tmp88 == tmp108
    tmp111 = tmp88 != tmp88
    tmp112 = tmp108 != tmp108
    tmp113 = tmp111 > tmp112
    tmp114 = tmp109 | tmp113
    tmp115 = tmp111 & tmp112
    tmp116 = tmp110 | tmp115
    tmp117 = tl.full([1], 3, tl.int64)
    tmp118 = tmp89 < tmp117
    tmp119 = tmp116 & tmp118
    tmp120 = tmp114 | tmp119
    tmp121 = tl.where(tmp120, tmp88, tmp108)
    tmp122 = tl.where(tmp120, tmp89, tmp117)
    tl.store(out_ptr0 + (x0), tmp122, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/ke/ckeed7ft5awwt6cgiivpt7j5svqkkbokukhvltl2gbosi67ikjtc.py
# Topologically Sorted Source Nodes: [q_data], Original ATen: [aten.index]
# Source node to ATen node mapping:
#   q_data => index
# Graph fragment:
#   %index : [num_users=1] = call_function[target=torch.ops.aten.index.Tensor](args = (%primals_2, [%argmin]), kwargs = {})
triton_poi_fused_index_1 = async_compile.triton('triton_poi_fused_index_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=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*i64', 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_index_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, '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_index_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = (xindex // 4)
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x1), xmask, eviction_policy='evict_last')
    tmp1 = tl.full([XBLOCK], 4, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tl.device_assert(((0 <= tmp4) & (tmp4 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp4 < 4")
    tmp6 = tl.load(in_ptr1 + (x0 + (4*tmp4)), xmask)
    tl.store(out_ptr0 + (x2), tmp6, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, ), (1, ), torch.int64)
        # Topologically Sorted Source Nodes: [delta, mul, dist, q_idx], Original ATen: [aten.sub, aten.mul, aten.sum, aten.argmin]
        stream0 = get_raw_stream(0)
        triton_poi_fused_argmin_mul_sub_sum_0.run(primals_2, primals_1, buf0, 4, grid=grid(4), stream=stream0)
        del primals_1
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [q_data], Original ATen: [aten.index]
        triton_poi_fused_index_1.run(buf0, primals_2, buf1, 16, grid=grid(16), stream=stream0)
        del primals_2
    return (buf1, buf0, buf0, )


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, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2])
    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.nn as nn
from typing import Tuple


class Quantizing(nn.Module):
    """
    This is quantizing layer.
    """
    __initialized: 'bool' = True

    def __init__(self, num_quantizing: 'int', quantizing_dim: 'int',
        _weight: 'torch.Tensor'=None, initialize_by_dataset: 'bool'=True,
        mean: 'float'=0.0, std: 'float'=1.0, dtype: 'torch.dtype'=None,
        device: 'torch.device'=None):
        super().__init__()
        assert num_quantizing > 0
        assert quantizing_dim > 0
        self.num_quantizing = num_quantizing
        self.quantizing_dim = quantizing_dim
        self.initialize_by_dataset = initialize_by_dataset
        self.mean, self.std = mean, std
        if _weight is None:
            self.weight = nn.Parameter(torch.empty(num_quantizing,
                quantizing_dim, dtype=dtype, device=device))
            nn.init.normal_(self.weight, mean=mean, std=std)
            if initialize_by_dataset:
                self.__initialized = False
                self.__initialized_length = 0
        else:
            assert _weight.dim() == 2
            assert _weight.size(0) == num_quantizing
            assert _weight.size(1) == quantizing_dim
            self.weight = nn.Parameter(_weight.to(device))

    def forward(self, x: 'torch.Tensor') ->Tuple[torch.Tensor]:
        """
        x   : shape is (*, E), and weight shape is (Q, E). 
        return -> ( quantized : shape is (*, E), quantized_idx : shape is (*,) )
        """
        input_size = x.shape
        h = x.view(-1, self.quantizing_dim)
        if not self.__initialized and self.initialize_by_dataset:
            getting_len = self.num_quantizing - self.__initialized_length
            init_weight = h[torch.randperm(len(h))[:getting_len]]
            _until = self.__initialized_length + init_weight.size(0)
            self.weight.data[self.__initialized_length:_until] = init_weight
            self.__initialized_length = _until
            None
            if _until >= self.num_quantizing:
                self.__initialized = True
                None
        delta = self.weight.unsqueeze(0) - h.unsqueeze(1)
        dist = torch.sum(delta * delta, dim=-1)
        q_idx = torch.argmin(dist, dim=-1)
        q_data = self.weight[q_idx]
        return q_data.view(input_size), q_idx.view(input_size[:1])

    def from_idx(self, idx: 'torch.Tensor') ->torch.Tensor:
        """
        idx: shape is (*, ). int tensor.
        return -> (*, E) float tensor
        """
        input_size = idx.shape
        i = idx.view(-1)
        q_data = self.weight[i].view(*input_size, self.quantizing_dim)
        return q_data

    def load_state_dict(self, state_dict, strict: 'bool'):
        self.__initialized = True
        return super().load_state_dict(state_dict, strict=strict)

    def __repr__(self):
        s = f'Quantizing({self.num_quantizing}, {self.quantizing_dim})'
        return s

    def isInitialized(self) ->bool:
        return self.__initialized


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


def get_init_inputs():
    return [[], {'num_quantizing': 4, 'quantizing_dim': 4}]

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
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_poi_fused_argmin_mul_sub_sum_0(in_ptr0, in_ptr1, 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 + 0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + 1)
    tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
    tmp7 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + 2)
    tmp12 = tl.broadcast_to(tmp11, [XBLOCK])
    tmp13 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp17 = tl.load(in_ptr0 + 3)
    tmp18 = tl.broadcast_to(tmp17, [XBLOCK])
    tmp19 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp23 = tl.load(in_ptr0 + 4)
    tmp24 = tl.broadcast_to(tmp23, [XBLOCK])
    tmp27 = tl.load(in_ptr0 + 5)
    tmp28 = tl.broadcast_to(tmp27, [XBLOCK])
    tmp32 = tl.load(in_ptr0 + 6)
    tmp33 = tl.broadcast_to(tmp32, [XBLOCK])
    tmp37 = tl.load(in_ptr0 + 7)
    tmp38 = tl.broadcast_to(tmp37, [XBLOCK])
    tmp57 = tl.load(in_ptr0 + 8)
    tmp58 = tl.broadcast_to(tmp57, [XBLOCK])
    tmp61 = tl.load(in_ptr0 + 9)
    tmp62 = tl.broadcast_to(tmp61, [XBLOCK])
    tmp66 = tl.load(in_ptr0 + 10)
    tmp67 = tl.broadcast_to(tmp66, [XBLOCK])
    tmp71 = tl.load(in_ptr0 + 11)
    tmp72 = tl.broadcast_to(tmp71, [XBLOCK])
    tmp90 = tl.load(in_ptr0 + 12)
    tmp91 = tl.broadcast_to(tmp90, [XBLOCK])
    tmp94 = tl.load(in_ptr0 + 13)
    tmp95 = tl.broadcast_to(tmp94, [XBLOCK])
    tmp99 = tl.load(in_ptr0 + 14)
    tmp100 = tl.broadcast_to(tmp99, [XBLOCK])
    tmp104 = tl.load(in_ptr0 + 15)
    tmp105 = tl.broadcast_to(tmp104, [XBLOCK])
    tmp3 = tmp1 - tmp2
    tmp4 = tmp3 * tmp3
    tmp8 = tmp6 - tmp7
    tmp9 = tmp8 * tmp8
    tmp10 = tmp4 + tmp9
    tmp14 = tmp12 - tmp13
    tmp15 = tmp14 * tmp14
    tmp16 = tmp10 + tmp15
    tmp20 = tmp18 - tmp19
    tmp21 = tmp20 * tmp20
    tmp22 = tmp16 + tmp21
    tmp25 = tmp24 - tmp2
    tmp26 = tmp25 * tmp25
    tmp29 = tmp28 - tmp7
    tmp30 = tmp29 * tmp29
    tmp31 = tmp26 + tmp30
    tmp34 = tmp33 - tmp13
    tmp35 = tmp34 * tmp34
    tmp36 = tmp31 + tmp35
    tmp39 = tmp38 - tmp19
    tmp40 = tmp39 * tmp39
    tmp41 = tmp36 + tmp40
    tmp42 = tmp22 < tmp41
    tmp43 = tmp22 == tmp41
    tmp44 = tmp22 != tmp22
    tmp45 = tmp41 != tmp41
    tmp46 = tmp44 > tmp45
    tmp47 = tmp42 | tmp46
    tmp48 = tmp44 & tmp45
    tmp49 = tmp43 | tmp48
    tmp50 = tl.full([1], 0, tl.int64)
    tmp51 = tl.full([1], 1, tl.int64)
    tmp52 = tmp50 < tmp51
    tmp53 = tmp49 & tmp52
    tmp54 = tmp47 | tmp53
    tmp55 = tl.where(tmp54, tmp22, tmp41)
    tmp56 = tl.where(tmp54, tmp50, tmp51)
    tmp59 = tmp58 - tmp2
    tmp60 = tmp59 * tmp59
    tmp63 = tmp62 - tmp7
    tmp64 = tmp63 * tmp63
    tmp65 = tmp60 + tmp64
    tmp68 = tmp67 - tmp13
    tmp69 = tmp68 * tmp68
    tmp70 = tmp65 + tmp69
    tmp73 = tmp72 - tmp19
    tmp74 = tmp73 * tmp73
    tmp75 = tmp70 + tmp74
    tmp76 = tmp55 < tmp75
    tmp77 = tmp55 == tmp75
    tmp78 = tmp55 != tmp55
    tmp79 = tmp75 != tmp75
    tmp80 = tmp78 > tmp79
    tmp81 = tmp76 | tmp80
    tmp82 = tmp78 & tmp79
    tmp83 = tmp77 | tmp82
    tmp84 = tl.full([1], 2, tl.int64)
    tmp85 = tmp56 < tmp84
    tmp86 = tmp83 & tmp85
    tmp87 = tmp81 | tmp86
    tmp88 = tl.where(tmp87, tmp55, tmp75)
    tmp89 = tl.where(tmp87, tmp56, tmp84)
    tmp92 = tmp91 - tmp2
    tmp93 = tmp92 * tmp92
    tmp96 = tmp95 - tmp7
    tmp97 = tmp96 * tmp96
    tmp98 = tmp93 + tmp97
    tmp101 = tmp100 - tmp13
    tmp102 = tmp101 * tmp101
    tmp103 = tmp98 + tmp102
    tmp106 = tmp105 - tmp19
    tmp107 = tmp106 * tmp106
    tmp108 = tmp103 + tmp107
    tmp109 = tmp88 < tmp108
    tmp110 = tmp88 == tmp108
    tmp111 = tmp88 != tmp88
    tmp112 = tmp108 != tmp108
    tmp113 = tmp111 > tmp112
    tmp114 = tmp109 | tmp113
    tmp115 = tmp111 & tmp112
    tmp116 = tmp110 | tmp115
    tmp117 = tl.full([1], 3, tl.int64)
    tmp118 = tmp89 < tmp117
    tmp119 = tmp116 & tmp118
    tmp120 = tmp114 | tmp119
    tl.where(tmp120, tmp88, tmp108)
    tmp122 = tl.where(tmp120, tmp89, tmp117)
    tl.store(out_ptr0 + x0, tmp122, xmask)


@triton.jit
def triton_poi_fused_index_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp1 = tl.full([XBLOCK], 4, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tl.device_assert((0 <= tmp4) & (tmp4 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp4 < 4')
    tmp6 = tl.load(in_ptr1 + (x0 + 4 * tmp4), xmask)
    tl.store(out_ptr0 + x2, tmp6, xmask)


def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4,), (1,), torch.int64)
        get_raw_stream(0)
        triton_poi_fused_argmin_mul_sub_sum_0[grid(4)](primals_2, primals_1,
            buf0, 4, XBLOCK=4, num_warps=1, num_stages=1)
        del primals_1
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_index_1[grid(16)](buf0, primals_2, buf1, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
        del primals_2
    return buf1, buf0, buf0


class QuantizingNew(nn.Module):
    """
    This is quantizing layer.
    """
    __initialized: 'bool' = True

    def __init__(self, num_quantizing: 'int', quantizing_dim: 'int',
        _weight: 'torch.Tensor'=None, initialize_by_dataset: 'bool'=True,
        mean: 'float'=0.0, std: 'float'=1.0, dtype: 'torch.dtype'=None,
        device: 'torch.device'=None):
        super().__init__()
        assert num_quantizing > 0
        assert quantizing_dim > 0
        self.num_quantizing = num_quantizing
        self.quantizing_dim = quantizing_dim
        self.initialize_by_dataset = initialize_by_dataset
        self.mean, self.std = mean, std
        if _weight is None:
            self.weight = nn.Parameter(torch.empty(num_quantizing,
                quantizing_dim, dtype=dtype, device=device))
            nn.init.normal_(self.weight, mean=mean, std=std)
            if initialize_by_dataset:
                self.__initialized = False
                self.__initialized_length = 0
        else:
            assert _weight.dim() == 2
            assert _weight.size(0) == num_quantizing
            assert _weight.size(1) == quantizing_dim
            self.weight = nn.Parameter(_weight.to(device))

    def from_idx(self, idx: 'torch.Tensor') ->torch.Tensor:
        """
        idx: shape is (*, ). int tensor.
        return -> (*, E) float tensor
        """
        input_size = idx.shape
        i = idx.view(-1)
        q_data = self.weight[i].view(*input_size, self.quantizing_dim)
        return q_data

    def load_state_dict(self, state_dict, strict: 'bool'):
        self.__initialized = True
        return super().load_state_dict(state_dict, strict=strict)

    def __repr__(self):
        s = f'Quantizing({self.num_quantizing}, {self.quantizing_dim})'
        return s

    def isInitialized(self) ->bool:
        return self.__initialized

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