id int64 0 190k | prompt stringlengths 21 13.4M | docstring stringlengths 1 12k ⌀ |
|---|---|---|
23,849 | import time
import torch
from torch import nn
from nndct_shared.utils import common
from pytorch_nndct.utils import logging
from pytorch_nndct.utils import torch_utils
class MetricName(object):
MACs = 'MACs'
FLOPs = 'FLOPs'
TrainableParams = 'trainable'
NonTrainableParams = 'non-trainable'
def _accumulate_metri... | null |
23,850 | import time
import torch
from torch import nn
from nndct_shared.utils import common
from pytorch_nndct.utils import logging
from pytorch_nndct.utils import torch_utils
class MetricName(object):
MACs = 'MACs'
FLOPs = 'FLOPs'
TrainableParams = 'trainable'
NonTrainableParams = 'non-trainable'
def _accumulate_metri... | null |
23,851 | import time
import torch
from torch import nn
from nndct_shared.utils import common
from pytorch_nndct.utils import logging
from pytorch_nndct.utils import torch_utils
class MetricName(object):
MACs = 'MACs'
FLOPs = 'FLOPs'
TrainableParams = 'trainable'
NonTrainableParams = 'non-trainable'
def _accumulate_metri... | null |
23,852 | import time
import torch
from torch import nn
from nndct_shared.utils import common
from pytorch_nndct.utils import logging
from pytorch_nndct.utils import torch_utils
class MetricName(object):
MACs = 'MACs'
FLOPs = 'FLOPs'
TrainableParams = 'trainable'
NonTrainableParams = 'non-trainable'
def _accumulate_metri... | null |
23,853 | import time
import torch
from torch import nn
from nndct_shared.utils import common
from pytorch_nndct.utils import logging
from pytorch_nndct.utils import torch_utils
class MetricName(object):
MACs = 'MACs'
FLOPs = 'FLOPs'
TrainableParams = 'trainable'
NonTrainableParams = 'non-trainable'
def _accumulate_metri... | null |
23,854 | import time
import torch
from torch import nn
from nndct_shared.utils import common
from pytorch_nndct.utils import logging
from pytorch_nndct.utils import torch_utils
class MetricName(object):
MACs = 'MACs'
FLOPs = 'FLOPs'
TrainableParams = 'trainable'
NonTrainableParams = 'non-trainable'
def _accumulate_metri... | null |
23,855 | import time
import torch
from torch import nn
from nndct_shared.utils import common
from pytorch_nndct.utils import logging
from pytorch_nndct.utils import torch_utils
class MetricName(object):
MACs = 'MACs'
FLOPs = 'FLOPs'
TrainableParams = 'trainable'
NonTrainableParams = 'non-trainable'
def _accumulate_metri... | null |
23,856 | import time
import torch
from torch import nn
from nndct_shared.utils import common
from pytorch_nndct.utils import logging
from pytorch_nndct.utils import torch_utils
class MetricName(object):
MACs = 'MACs'
FLOPs = 'FLOPs'
TrainableParams = 'trainable'
NonTrainableParams = 'non-trainable'
def _accumulate_metri... | null |
23,857 | import time
import torch
from torch import nn
from nndct_shared.utils import common
from pytorch_nndct.utils import logging
from pytorch_nndct.utils import torch_utils
class MetricName(object):
def _accumulate_metric_value(module, metric_name, value):
import logging as _logging
from logging import DEBUG
from logging i... | null |
23,858 | import time
import torch
from torch import nn
from nndct_shared.utils import common
from pytorch_nndct.utils import logging
from pytorch_nndct.utils import torch_utils
def prepare_for_inference(model, inputs):
def run_model_forward(model, inputs, eval_mode=True):
model, inputs = prepare_for_inference(model, inputs)
... | null |
23,859 | import time
import torch
from torch import nn
from nndct_shared.utils import common
from pytorch_nndct.utils import logging
from pytorch_nndct.utils import torch_utils
def prepare_for_inference(model, inputs):
model = torch_utils.strip_parallel(model)
if torch.cuda.is_available():
model.cuda()
if isinstance... | Stat the complexity of the given model. Currently includes macs and params. MACs: multiply–accumulate operations that performs a += b x c Flops = 2*MACs + BiasAdd Params: total number of parameters of a model. Args: model: An `nn.Module` object. inputs: A list or tuple of inputs used to run forward passes on the model.... |
23,860 | from setuptools import setup
from setuptools import find_packages
from setuptools.command.build_ext import build_ext
import os
import shutil
PROJECT_NAME = 'tf1_nndct'
def clean():
try:
for dir_name in ['build', 'dist', PROJECT_NAME + '.egg-info']:
if os.path.exists(dir_name):
shutil.rmtree(dir_nam... | null |
23,861 | import tensorflow as tf
from typing import List, Mapping
from tf1_nndct.optimization.constant import OpType
from queue import Queue
import numpy as np
class NodeGroupUnion(object):
def __init__(self) -> None:
self._parents = []
self._nodes = []
self._node_idx_map = {}
def add_node(self, node: str) -> No... | null |
23,862 | import tensorflow as tf
from typing import List, Mapping
from tf1_nndct.optimization.constant import OpType
from queue import Queue
import numpy as np
def find_weight_nodes(node: tf.compat.v1.NodeDef, node_def_map: Mapping[str, tf.compat.v1.NodeDef]) -> List[tf.compat.v1.NodeDef]:
weight_nodes = []
if len(node.inpu... | null |
23,863 | import tensorflow as tf
from typing import List, Mapping
from tf1_nndct.optimization.constant import OpType
from queue import Queue
import numpy as np
class OpType(object):
Conv2D = "Conv2D"
QuantizedConv2D = "QuantizedConv2D"
DepthwiseConv2dNative = "DepthwiseConv2dNative"
Add = "Add"
AddV2 = "AddV2"
Bia... | null |
23,864 | import tensorflow as tf
from typing import List, Mapping
from tf1_nndct.optimization.constant import OpType
from queue import Queue
import numpy as np
def is_matmul(node_def: tf.compat.v1.GraphDef) -> bool:
return node_def.op in [OpType.MatMul, OpType.QuantizedMatMul, OpType.BatchMatMul, OpType.SparseMatMul]
def is_c... | null |
23,865 | import tensorflow as tf
from typing import List, Mapping
from tf1_nndct.optimization.constant import OpType
from queue import Queue
import numpy as np
def get_input_node_name(input_name: str) -> str:
def topo_sort(graph_def: tf.compat.v1.GraphDef) -> List[tf.compat.v1.NodeDef]:
reverse_map = {}
num_inputs = {}
r... | null |
23,866 | import tensorflow as tf
from tensorflow.core.framework.tensor_pb2 import TensorProto
from tf1_nndct.optimization.utils import group_conv_nodes, find_weight_nodes, is_matmul, \
is_conv, is_depthwise_conv, is_concat, is_weighted_node, calculate_flops, get_input_node_name, \
topo_sort, find_ancestor_target_nodes
from ... | null |
23,867 | from typing import List
import cv2
import numpy as np
import sys
import math
import xir
import vitis_ai_library
import struct
point_cloud_range = [0, -39.68, -3, 69.12, 39.68, 1]
voxel_size = [0.16, 0.16, 4]
def get_grid_size():
grid_size1=[]
for i in range(3):
grid_size1.append(round(( point_cloud_range[i+3]-... | null |
23,868 | from typing import List
import cv2
import numpy as np
import sys
import math
import xir
import vitis_ai_library
import struct
anchor_sizes =[ [1.6, 3.9, 1.56 ], [0.6, 1.76, 1.73] , [0.6, 0.8, 1.73] ]
anchor_strides =[0.32, 0.32, 0.0]
anchor_offsets =[ [0.16, -39.52, -1.78], [0.16, -39.52, -1.465], [0.16, -39.5... | null |
23,869 | from typing import List
import cv2
import numpy as np
import sys
import math
import xir
import vitis_ai_library
import struct
point_cloud_range = [0, -39.68, -3, 69.12, 39.68, 1]
voxel_size = [0.16, 0.16, 4]
anchor_area_threshold=1
global g_anchors_bv
def sparse_sum_for_anchors_mask(coors, voxel_num, shape):
ret = ... | null |
23,870 | from typing import List
import cv2
import numpy as np
import sys
import math
import xir
import vitis_ai_library
import struct
point_cloud_range = [0, -39.68, -3, 69.12, 39.68, 1]
voxel_size = [0.16, 0.16, 4]
max_voxels = 12000
max_points = 100
global grid_size
def preprocess_one_data(bin_path, width, height , in_scale... | null |
23,871 | from typing import List
import cv2
import numpy as np
import sys
import math
import xir
import vitis_ai_library
import struct
def sigmoid_array(x):
return 1 / (1 + np.exp(-x)) | null |
23,872 | from typing import List
import cv2
import numpy as np
import sys
import math
import xir
import vitis_ai_library
import struct
The provided code snippet includes necessary dependencies for implementing the `corner_to_standup_nd` function. Write a Python function `def corner_to_standup_nd(boxes_corner)` to solve the fol... | for i in range(ndim): standup_boxes.append(torch.min(boxes_corner[:, :, i], dim=1)[0]) for i in range(ndim): standup_boxes.append(torch.max(boxes_corner[:, :, i], dim=1)[0]) for i in range(boxes_corner.shape[0]): standup_boxes.append( np.min(boxes_corner[i] )[0]) standup_boxes.append( np.max(boxes_corner[i] )[0]) |
23,873 | from typing import List
import cv2
import numpy as np
import sys
import math
import xir
import vitis_ai_library
import struct
def nms_jit(dets, scores, thresh, eps=1.0):
x1 = dets[:, 0]
y1 = dets[:, 1]
x2 = dets[:, 2]
y2 = dets[:, 3]
areas = (x2 - x1 + eps) * (y2 - y1 + eps)
order = scores.args... | null |
23,874 | from typing import List
import cv2
import numpy as np
import sys
import math
import xir
import vitis_ai_library
import struct
def get_box_decode( idx, box, anchors):
o = [0]*7
za = anchors[ idx ][2] + anchors[ idx ][5]/2
diagonal = math.sqrt( pow(anchors[ idx ][4], 2.0) + math.pow(anchors[ idx ][3], 2.0))
... | null |
23,875 | from typing import List
import cv2
import numpy as np
import sys
import math
import xir
import vitis_ai_library
import struct
def get_max(inv):
if inv[0] > inv[1]:
return 0 if inv[0] > inv[2] else 2
else:
return 1 if inv[1] > inv[2] else 2 | null |
23,876 | from typing import List
import cv2
import numpy as np
import sys
import math
import xir
import vitis_ai_library
import struct
def my_test():
a=math.sqrt(10)
print ("a", a)
return | null |
23,877 | import cv2
import numpy as np
import os
import xir
import argparse
import vitis_ai_library
def get_imagefiles(image_path, batchsize):
def preprocess_tf2_custom_op(imgfiles, begidx, input_tensor_buffers):
def postprocess_tf2_custom_op(imgfiles, begidx, output_tensor_buffers):
def app(image_path, model):
g = xir.Gra... | null |
23,878 | from typing import List
import cv2
import numpy as np
import sys
import math
import xir
import vitis_ai_library
def resize_shortest_edge(image, smallest_side):
H, W = image.shape[:2]
if H >= W:
nW = smallest_side
nH = int(float(H)/W * smallest_side)
else:
nH = smallest_side
n... | null |
23,879 | from typing import List
import cv2
import numpy as np
import sys
import math
import xir
import vitis_ai_library
def TopK(datain, size, filePath):
cnt = [i for i in range(size)]
pair = zip(datain, cnt)
pair = sorted(pair, reverse=True)
softmax_new, cnt_new = zip(*pair)
fp = open(filePath, "r")
d... | null |
23,880 | import json
import tools_extra_ops as tools
def main(args):
print(
json.dumps(
tools.xdputil_status(), sort_keys=True, indent=4, separators=(",", ":")
)
)
def help(subparsers):
parser = subparsers.add_parser("status", help="")
parser.set_defaults(func=main) | null |
23,881 | import xir
import os
import sys
import os
from typing import List
import tools_extra_ops as tools
import hashlib
import json
import numpy as np
def node_label(i, sg):
return '''{0}: {1}'''.format(i, sg.get_name()) | null |
23,882 | import xir
import os
import sys
import os
from typing import List
import tools_extra_ops as tools
import hashlib
import json
import numpy as np
def find_subgraph_id(g, tensor, sgs):
op = g.get_tensor_producer(tensor)
s = g.get_leaf_subgraph(op)
index = -1
while not s == g.get_root_subgraph():
t... | null |
23,883 | import xir
import os
import sys
import os
from typing import List
import tools_extra_ops as tools
import hashlib
import json
import numpy as np
def xmodel_main(args):
if args.png:
png(args)
elif args.svg:
svg(args)
elif args.txt:
txt(args)
elif args.list:
glist(args.xmode... | null |
23,884 | from typing import List
import numpy as np
import xir
import vart
import tools_extra_ops as tools
import os
def fillin_inputs(file_path_list: List["string"], tensor: "ndarray"):
input_shape = tuple(tensor.shape[1:])
for i in range(tensor.shape[0]):
tensor[i, ...] = np.fromfile(file_path_list[i % len(fil... | null |
23,885 | from typing import List
import numpy as np
import xir
import vart
import tools_extra_ops as tools
import os
def main(args):
# get subgraph
graph = xir.Graph.deserialize(args.xmodel)
assert graph is not None, "'graph' should not be None."
subgraph = graph.get_root_subgraph()
assert (subgraph is not N... | null |
23,886 | import numpy as np
import tools_extra_ops as tools
def mem_main(args):
if args.read:
mem_read(args)
elif args.write:
mem_write(args)
def help(subparsers):
parser = subparsers.add_parser(
"mem",
description="mem ",
help="<-r|-w> <addr> <size> <output_file|input_file>"... | null |
23,887 | import os
import struct
def validate_file(file_name):
if file_name is None:
return "file name should not be null."
if not os.path.exists(file_name):
return file_name + " file doesn't exist."
if not os.path.isfile(file_name):
return file_name + " is not a file."
if os.path.getsiz... | null |
23,888 | import os
import struct
def main(args):
# validation check for input golden file
valid = validate_file(args.golden_file)
if valid is not None:
print("golden file check:", valid)
return
# validation check for input dump file
valid = validate_file(args.dump_file)
if valid is not No... | null |
23,889 | from typing import List
from tools_extra_ops import test_dpu_runner_mt
import xir
The provided code snippet includes necessary dependencies for implementing the `get_child_subgraph_dpu` function. Write a Python function `def get_child_subgraph_dpu(graph: "Graph") -> List["Subgraph"]` to solve the following problem:
ob... | obtain subgrah |
23,890 | from typing import List
from tools_extra_ops import test_dpu_runner_mt
import xir
def dpu_runner_mt(children, args, graph):
if test_dpu_runner_mt(
children[args.subgraph_index] if args.subgraph_index >= 0
and args.subgraph_index < len(children) else graph.get_root_subgraph(),
ar... | null |
23,891 | from typing import List
from tools_extra_ops import test_dpu_runner_mt
import xir
def main(args):
import os
import threading
for f in args.input_files:
if not os.path.exists(f):
print(f, " does not exist")
return
for f in args.output_files:
if not os.path.exists(f... | null |
23,892 | import json
import tools_extra_ops as tools
def main(args):
def help(subparsers):
parser = subparsers.add_parser("query", help="No input parameters")
parser.set_defaults(func=main) | null |
23,893 | import os
from typing import List
import xir
import vart
import tools_extra_ops as tools
def main(args):
if args.ref_dir is None:
args.ref_dir = os.getcwd() + "/ref"
if os.path.exists(args.ref_dir) and not os.path.isdir(args.ref_dir):
print(args.ref_dir + " should be a directory.")
retur... | null |
23,894 | import os
import xir_extra_ops
def jit(graph):
graph.set_attr("need_preprocess", True)
graph.set_attr("mean", [104.0, 117.0, 123.0])
graph.set_attr("scale", [1.0, 1.0, 1.0])
graph.set_attr("is_rgb_input", False)
graph.set_attr("color1", [
128, 232, 70, 156, 153, 153, 30, 0, 35, 152, 180, 60... | null |
23,895 | import xir_extra_ops
def jit(graph):
graph.set_attr("need_preprocess", True)
graph.set_attr("mean", [127.5, 127.5, 127.5])
graph.set_attr("scale", [0.0078431, 0.0078431, 0.0078431])
graph.set_attr("is_rgb_input", False)
xir_extra_ops.set_postprocessor(
graph,
"libxmodel_postprocesso... | null |
23,896 | import xir_extra_ops
def jit(graph):
graph.set_attr("need_preprocess", True)
graph.set_attr("mean", [105.0, 117.0, 123.0])
graph.set_attr("scale", [1.0, 1.0, 1.0])
graph.set_attr("is_rgb_input", False)
graph.set_attr("ratio", 8)
graph.set_attr("ipm_left", 5.0)
graph.set_attr("ipm_right", 75... | null |
23,897 | import xir_extra_ops
def jit(graph):
graph.set_attr("need_preprocess", True)
graph.set_attr("mean", [128.0, 128.0, 128.0])
graph.set_attr("scale", [0.0078125, 0.0078125, 0.0078125])
graph.set_attr("is_rgb_input", False)
xir_extra_ops.set_postprocessor(
graph,
"libxmodel_postprocesso... | null |
23,898 | import os
import xir_extra_ops
def jit(graph):
graph.set_attr("xmodel_preprocessor", "libxmodel_preprocessor_efficientnet.so.3")
graph.set_attr("need_preprocess", True)
graph.set_attr("mean", [127.0, 127.0, 127.0])
graph.set_attr("scale", [0.0078125, 0.0078125, 0.0078125])
graph.set_attr("is_rgb_in... | null |
23,899 | import os
import xir_extra_ops
def jit(graph):
graph.set_attr("xmodel_preprocessor", "libxmodel_preprocessor_vgg.so.3")
graph.set_attr("need_preprocess", True)
graph.set_attr("mean", [103.94, 116.78, 123.68])
graph.set_attr("scale", [1.0, 1.0, 1.0])
graph.set_attr("is_rgb_input", True)
graph.se... | null |
23,900 | import xir_extra_ops
def jit(graph):
graph.set_attr("need_preprocess", True)
graph.set_attr("mean", [0.0, 0.0, 0.0])
graph.set_attr("scale", [0.00390625, 0.00390625, 0.00390625])
graph.set_attr("is_rgb_input", True)
graph.set_attr("num_classes", 20)
graph.set_attr("anchorCnt", 3)
graph.set_... | null |
23,902 | import os
import xir_extra_ops
def jit(graph):
graph.set_attr("xmodel_preprocessor", "libxmodel_preprocessor_efficientnet.so.3")
graph.set_attr("need_preprocess", True)
graph.set_attr("mean", [127.0, 127.0, 127.0])
graph.set_attr("scale", [0.0078125, 0.0078125, 0.0078125])
graph.set_attr("is_rgb_in... | null |
23,903 | import xir_extra_ops
def jit(graph):
graph.set_attr("need_preprocess", True)
graph.set_attr("mean", [128.0, 128.0, 128.0])
graph.set_attr("scale", [0.0078125, 0.0078125, 0.0078125])
graph.set_attr("is_rgb_input", True)
xir_extra_ops.set_postprocessor(
graph,
"libxmodel_postprocessor... | null |
23,904 | import xir_extra_ops
import json
prior_box_param1 = {
"layer_width": 60,
"layer_height": 45,
"variances": [0.1, 0.1, 0.2, 0.2],
"min_sizes": [21.0],
"max_sizes": [45.0],
"aspect_ratios": [2.0],
"offset": 0.5,
"step_width": 8.0,
"step_height": 8.0,
"flip": True,
"clip": False
... | null |
23,905 | import xir_extra_ops
def jit(graph):
graph.set_attr("need_preprocess", True)
graph.set_attr("mean", [128.0, 128.0, 128.0])
graph.set_attr("scale", [0.0078125, 0.0078125, 0.0078125])
graph.set_attr("is_rgb_input", False)
xir_extra_ops.set_postprocessor(
graph,
"libxmodel_postprocess... | null |
23,906 | import xir_extra_ops
list0 = [
"unknown", "jing", "hu", "jin", "yu", "ji", "jin", "meng", "liao", "ji",
"hei", "su", "zhe", "wan", "min", "gan", "lu", "yu", "e", "xiang", "yue",
"gui", "qiong", "chuan", "gui", "yun", "zang", "shan", "gan", "qing",
"ning", "xin"
]
list1 = [
"unknown", "A", "B", "C", ... | null |
23,907 | import os
import xir_extra_ops
def jit(graph):
graph.set_attr("need_preprocess", True)
graph.set_attr("mean", [128.0, 128.0, 128.0])
graph.set_attr("scale", [1.0, 1.0, 1.0])
graph.set_attr("is_rgb_input", False)
conf_op = graph.get_op("pixel-conv-tiled_fixed_")
graph.create_op(
"pixel-c... | null |
23,908 | import numpy as np
import logging
import copy
from enum import Enum
import onnx
import onnx.numpy_helper
from onnx import TensorProto
from onnx import onnx_pb as onnx_proto
from .quant_utils import pos2scale, scale2pos
class QuantPosManager(object):
def __init__(self, model):
self.model = model
def get_... | Adjust the quantize info to meet the compiler constraints. |
23,909 | from .operators.activation import QDQRemovableActivation, QLinearActivation
from onnxruntime.quantization.operators.argmax import QArgMax
from onnxruntime.quantization.operators.attention import AttentionQuant
from onnxruntime.quantization.operators.base_operator import QuantOperatorBase
from onnxruntime.quantization.o... | null |
23,910 | from .operators.activation import QDQRemovableActivation, QLinearActivation
from onnxruntime.quantization.operators.argmax import QArgMax
from onnxruntime.quantization.operators.attention import AttentionQuant
from onnxruntime.quantization.operators.base_operator import QuantOperatorBase
from onnxruntime.quantization.o... | null |
23,911 | from .operators.activation import QDQRemovableActivation, QLinearActivation
from onnxruntime.quantization.operators.argmax import QArgMax
from onnxruntime.quantization.operators.attention import AttentionQuant
from onnxruntime.quantization.operators.base_operator import QuantOperatorBase
from onnxruntime.quantization.o... | null |
23,912 | import logging
import tempfile
from pathlib import Path
import onnx
import onnx.helper as helper
from onnxruntime.quantization.calibrate import CalibrationDataReader, CalibrationMethod, create_calibrator
from .onnx_quantizer import VitisAIONNXQuantizer
from onnxruntime.quantization.quantize import quantize_static as or... | null |
23,913 | import logging
import tempfile
from enum import Enum
from pathlib import Path
import numpy as np
import onnx
import os
import sys
from onnx import external_data_helper
from onnx import onnx_pb as onnx_proto
import onnx.helper as helper
from onnx import shape_inference, TensorProto
import onnxruntime as ort
from onnxrun... | null |
23,914 | import logging
import tempfile
from enum import Enum
from pathlib import Path
import numpy as np
import onnx
import os
import sys
from onnx import external_data_helper
from onnx import onnx_pb as onnx_proto
import onnx.helper as helper
from onnx import shape_inference, TensorProto
import onnxruntime as ort
from onnxrun... | null |
23,915 | import logging
import tempfile
from enum import Enum
from pathlib import Path
import numpy as np
import onnx
import os
import sys
from onnx import external_data_helper
from onnx import onnx_pb as onnx_proto
import onnx.helper as helper
from onnx import shape_inference, TensorProto
import onnxruntime as ort
from onnxrun... | null |
23,916 | import logging
import tempfile
from enum import Enum
from pathlib import Path
import numpy as np
import onnx
import os
import sys
from onnx import external_data_helper
from onnx import onnx_pb as onnx_proto
import onnx.helper as helper
from onnx import shape_inference, TensorProto
import onnxruntime as ort
from onnxrun... | null |
23,917 | import logging
import tempfile
from enum import Enum
from pathlib import Path
import numpy as np
import onnx
import os
import sys
from onnx import external_data_helper
from onnx import onnx_pb as onnx_proto
import onnx.helper as helper
from onnx import shape_inference, TensorProto
import onnxruntime as ort
from onnxrun... | Dump model weights and outputs. e.g: model_path = 'resnet50-v1-13.quant.onnx' model = onnx.load(model_path) input_data = np.random.rand(1, 3, 224, 224).astype(np.float32) dump_model(model, input_data) |
23,918 | import logging
import tempfile
from enum import Enum
from pathlib import Path
import numpy as np
import onnx
import os
import sys
from onnx import external_data_helper
from onnx import onnx_pb as onnx_proto
import onnx.helper as helper
from onnx import shape_inference, TensorProto
import onnxruntime as ort
from onnxrun... | Traverse the floating-point model to find the names of all conv outputs. |
23,919 | import logging
import tempfile
from enum import Enum
from pathlib import Path
import numpy as np
import onnx
import os
import sys
from onnx import external_data_helper
from onnx import onnx_pb as onnx_proto
import onnx.helper as helper
from onnx import shape_inference, TensorProto
import onnxruntime as ort
from onnxrun... | Find the corresponding pairs that form conv-relu through the output of conv, and return two dictionaries: conv-relu and relu-conv |
23,920 | import logging
import tempfile
from enum import Enum
from pathlib import Path
import numpy as np
import onnx
import os
import sys
from onnx import external_data_helper
from onnx import onnx_pb as onnx_proto
import onnx.helper as helper
from onnx import shape_inference, TensorProto
import onnxruntime as ort
from onnxrun... | Return two lists, one for 'dq' and one for 'q'. |
23,921 | import logging
import tempfile
from enum import Enum
from pathlib import Path
import numpy as np
import onnx
import os
import sys
from onnx import external_data_helper
from onnx import onnx_pb as onnx_proto
import onnx.helper as helper
from onnx import shape_inference, TensorProto
import onnxruntime as ort
from onnxrun... | Delete nodes according to the nodes in the list |
23,922 | import logging
import tempfile
from enum import Enum
from pathlib import Path
import numpy as np
import onnx
import os
import sys
from onnx import external_data_helper
from onnx import onnx_pb as onnx_proto
import onnx.helper as helper
from onnx import shape_inference, TensorProto
import onnxruntime as ort
from onnxrun... | Modify the input of ReLU to the output of annotate op, and delete QDQ |
23,923 | import logging
import tempfile
from enum import Enum
from pathlib import Path
import numpy as np
import onnx
import os
import sys
from onnx import external_data_helper
from onnx import onnx_pb as onnx_proto
import onnx.helper as helper
from onnx import shape_inference, TensorProto
import onnxruntime as ort
from onnxrun... | :param data: data to quantize :param qType: data type to quantize to. Supported types UINT8 and INT8 :param symmetric: whether symmetric quantization is used or not. This is applied to INT8. :return: minimum, maximum, zero point, scale, and quantized weights To pack weights, we compute a linear transformation - when da... |
23,924 | import numpy as np
from onnxruntime_extensions import onnx_op, PyCustomOpDef
def vai_quantize(x, scale, zero_point, **kwargs):
# The custom op implementation.
bit_width = int(kwargs["bit_width"])
q_min = -2**(bit_width - 1)
q_max = 2**(bit_width - 1) - 1
result = np.round(x / scale) + zero_point
... | null |
23,925 | import numpy as np
from onnxruntime_extensions import onnx_op, PyCustomOpDef
def vai_dquantize(x, scale, zero_point, **kwargs):
bit_width = int(kwargs["bit_width"])
q_min = -2**(bit_width - 1)
q_max = 2**(bit_width - 1) - 1
result = np.clip(x, q_min, q_max)
result = (result - zero_point) * scale
... | null |
23,926 | import numpy as np
from onnxruntime_extensions import onnx_op, PyCustomOpDef
def vai_dquantize(x, scale, zero_point, **kwargs):
bit_width = int(kwargs["bit_width"])
q_min = -2**(bit_width - 1)
q_max = 2**(bit_width - 1) - 1
result = np.round(x / scale) + zero_point
result = np.clip(result, q_min, q... | null |
23,927 | import os
import argparse
import onnx
from google.protobuf import text_format
def run_main():
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
parser = argparse.ArgumentParser()
parser.add_argument("--input_model",
type=str,
default="",
help... | null |
23,928 | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import onnx
import os
import argparse
from vai_q_onnx.optimizations import convert_transforms_pipeline
def remove_qdq(model):
"""Remove QDQ operators."""
convert_pipeline = convert_tra... | null |
23,929 | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import onnx
import os
import argparse
from vai_q_onnx.optimizations import convert_transforms_pipeline
from vai_q_onnx.utils import model_utils
def convert_qdq_to_qop(model):
def run_main():
... | null |
23,930 | import onnx
import enum
import copy
from google.protobuf import text_format
The provided code snippet includes necessary dependencies for implementing the `get_tensor_value` function. Write a Python function `def get_tensor_value(initializer)` to solve the following problem:
Convert TensorProto to numpy array.
Here i... | Convert TensorProto to numpy array. |
23,931 | import onnx
import enum
import copy
from google.protobuf import text_format
The provided code snippet includes necessary dependencies for implementing the `generate_initializer` function. Write a Python function `def generate_initializer(tensor_array, dtype, name)` to solve the following problem:
Generate initializers... | Generate initializers from numpy array. |
23,932 | import onnx
import enum
import copy
from google.protobuf import text_format
The provided code snippet includes necessary dependencies for implementing the `save_model` function. Write a Python function `def save_model(model, path, as_text=False)` to solve the following problem:
Save onnx model to disk.
Here is the fu... | Save onnx model to disk. |
23,933 | import onnx
import enum
import copy
from google.protobuf import text_format
class SharedNodesHelper(object):
class NodeType(enum.Enum):
NODE = 1
INITIALIZER = 2
INPUT = 3
def _node_type(node):
"""Returns whether the node is a node or initializer."""
if isinstance(node, on... | null |
23,934 | from __future__ import print_function
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
from torch.optim.lr_scheduler import StepLR
def train(args, model, device, train_loader, optimizer, epoch):
model.train()... | null |
23,935 | import torch
from onnxruntime.quantization.calibrate import CalibrationDataReader
from torch.utils.data import DataLoader, Dataset
from torchvision import transforms
from torchvision.datasets import CIFAR10
import onnx
import onnxruntime
from onnxruntime.quantization import CalibrationDataReader, QuantType, QuantFormat... | null |
23,936 | import torch
from onnxruntime.quantization.calibrate import CalibrationDataReader
from torch.utils.data import DataLoader, Dataset
from torchvision import transforms
from torchvision.datasets import CIFAR10
import onnx
import onnxruntime
from onnxruntime.quantization import CalibrationDataReader, QuantType, QuantFormat... | null |
23,937 | from pathlib import Path
def get_directories():
current_dir = Path(__file__).resolve().parent
# models directory for resnet sample
models_dir = current_dir / "models"
models_dir.mkdir(parents=True, exist_ok=True)
# data directory for resnet sample
data_dir = current_dir / "data"
data_dir.... | null |
23,938 | import argparse
import random
import tarfile
import urllib.request
import torch
import torch.nn as nn
import torchvision
import torchvision.transforms as transforms
from resnet_utils import get_directories
from torchvision.models import ResNet50_Weights, resnet50
def get_args():
parser = argparse.ArgumentParser()
... | null |
23,939 | import argparse
import random
import tarfile
import urllib.request
import torch
import torch.nn as nn
import torchvision
import torchvision.transforms as transforms
from resnet_utils import get_directories
from torchvision.models import ResNet50_Weights, resnet50
def tensor_data_to_device(data, device: str):
if de... | null |
23,940 | import argparse
import random
import tarfile
import urllib.request
import torch
import torch.nn as nn
import torchvision
import torchvision.transforms as transforms
from resnet_utils import get_directories
from torchvision.models import ResNet50_Weights, resnet50
def load_resnet_model():
weights = ResNet50_Weights.... | null |
23,942 | import torch
from onnxruntime.quantization.calibrate import CalibrationDataReader
from torch.utils.data import DataLoader, Dataset
from torchvision import transforms
from torchvision.datasets import CIFAR10
import onnx
import onnxruntime
from onnxruntime.quantization import CalibrationDataReader, QuantType, QuantFormat... | null |
23,949 | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import abc
import copy
import json
import numpy as np
import os
from typing import List
from nndct_shared.base.key_names import FrameworkType
from nndct_shared.pruning import errors
from nndct_shared.pruning imp... | null |
23,950 | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import abc
import collections
import os
import pickle
from nndct_shared.pruning import logging
from nndct_shared.pruning import pruning_lib
from nndct_shared.utils import io, logging
from typing import Mapping, ... | null |
23,952 | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import logging as _logging
import os as _os
import sys as _sys
import time as _time
import traceback as _traceback
from logging import DEBUG
from logging import ERROR
from logging import FATAL
from logging impor... | null |
23,969 | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from typing import List, Mapping, Any, Union, Tuple
import collections
from nndct_shared.base.key_names import NNDCT_OP as OpTypes
from nndct_shared.nndct_graph.base_node import Node
from nndct_shared.metaclass ... | null |
23,973 | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from typing import List, Mapping, Any, Union, Tuple
import collections
from nndct_shared.base.key_names import NNDCT_OP as OpTypes
from nndct_shared.nndct_graph.base_node import Node
from nndct_shared.metaclass ... | null |
23,976 | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from typing import List, Mapping, Any, Union, Tuple
import collections
from nndct_shared.base.key_names import NNDCT_OP as OpTypes
from nndct_shared.nndct_graph.base_node import Node
from nndct_shared.metaclass ... | null |
23,985 | import copy
from collections import defaultdict, deque, namedtuple
from typing import List
from nndct_shared.quantization import BaseQuantizer
from nndct_shared.base import NNDCT_OP
from nndct_shared.nndct_graph import Graph, Node, Tensor, GraphSearcher
from nndct_shared.nndct_graph import operator_definition as base_o... | null |
23,987 | import math
import itertools
from typing import List, Dict, Any, NoReturn, Tuple
import numpy as np
from functools import partial
from nndct_shared.base import NNDCT_OP, NNDCT_KEYS
from nndct_shared.nndct_graph import Tensor, Node
from .xgraph import XGraph
from nndct_shared.utils import calculate_op_scale, DataXopErro... | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.