Skip to content

Instantly share code, notes, and snippets.

View tiandiao123's full-sized avatar

Cuiqing Li (李崔卿) tiandiao123

  • Shanghai, China
View GitHub Profile
@tiandiao123
tiandiao123 / eigen_matrix.cpp
Created April 24, 2021 22:12
eigen experiments
#include <iostream>
#include <Eigen/Dense>
#include <Eigen/StdVector>
using Eigen::MatrixXd;
using namespace std;
using namespace Eigen;
@tiandiao123
tiandiao123 / optimize_bert.py
Created July 1, 2021 22:01 — forked from icemelon/optimize_bert.py
Optimize the BERT model on CPUs
import time
import argparse
import numpy as np
import mxnet as mx
import gluonnlp as nlp
import tvm
from tvm import relay
import tvm.contrib.graph_runtime as runtime
def timer(thunk, repeat=1, number=10, dryrun=3, min_repeat_ms=1000):
# FP16 TRT command to run : TVM_TENSORRT_USE_FP16=1 python test_trt.py
# INT8 TRT command to run : TVM_TENSORRT_USE_INT8=1 TENSORRT_NUM_CALI_INT8=10 python test_trt.py
# use tvm branch: https://github.com/tiandiao123/tvm/tree/pr_trt_int8
import tvm
from tvm import relay
import numpy as np
from tvm.contrib.download import download_testdata
import os
# PyTorch imports
# FP16 TRT command to run : TVM_TENSORRT_USE_FP16=1 python test_trt.py
# INT8 TRT command to run : TVM_TENSORRT_USE_INT8=1 TENSORRT_NUM_CALI_INT8=10 python test_trt.py
# https://github.com/tiandiao123/tvm/tree/pr_trt_int8 (tvm we use)
import tvm
from tvm import relay
from tvm.contrib.download import download_testdata
from tvm.relay.op.contrib.tensorrt import partition_for_tensorrt
# PyTorch imports
# FP16 TRT command to run : TVM_TENSORRT_USE_FP16=1 python test_trt.py
# INT8 TRT command to run : TVM_TENSORRT_USE_INT8=1 TENSORRT_NUM_CALI_INT8=10 python test_trt.py
# use tvm branch: https://github.com/tiandiao123/tvm/tree/pr_trt_int8
import tvm
from tvm import relay
import os
from tvm import te
import tvm.relay as relay
from tvm.contrib.download import download_testdata
import mxnet
from mxnet.gluon.model_zoo.vision import get_model
import tvm
from tvm import relay
import tvm.contrib.graph_runtime as runtime
import numpy as np
dtype = "float32"
input_shape = (1, 3, 224, 224)
block = get_model('resnet18_v1', pretrained=True)
### here is a demo how to convert your tf2 model into tvm relay
import tensorflow as tf
from tensorflow.python.tools import saved_model_utils
from tensorflow import keras
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2
from tvm import relay
from tvm.relay.frontend.tensorflow2 import from_tensorflow
dtype_dict = {
"tf.float32": "float32",
import tvm
from tvm import relay
from tvm.relay.op.contrib.tensorrt import partition_for_tensorrt
from tvm.contrib import graph_executor
import numpy as np
# 改成你自己的tvm .so 存储路径
my_lib_saved_path = "/data00/cuiqing.li/xperf_workplace/xperf_tools/xperf_tools/xperf_pipeline/bytetuner/rh2_tvm_lab.vulgar.pipeline_1.4/deploy_batch_id_32.so"
lib = tvm.runtime.load_module(my_lib_saved_path)
import tvm
from tvm import relay
import tvm.contrib.graph_runtime as runtime
import numpy as np
from tvm.contrib.download import download_testdata
from tvm.relay.op.contrib.tensorrt import partition_for_tensorrt
# PyTorch imports
import torch
import torchvision
import torch
import torchvision
from torch.utils.mobile_optimizer import optimize_for_mobile
from caffe2.torch.fb.mobile.model_exporter.mobile_model_exporter import (
export_torch_mobile_model,
BundledInput,
MobileModelInfo,
ModelType,
OptimizationPassInput
)