Skip to content

Instantly share code, notes, and snippets.

View yujiepan-work's full-sized avatar
🤑
怎么还不发工资

Yujie Pan yujiepan-work

🤑
怎么还不发工资
View GitHub Profile
@yujiepan-work
yujiepan-work / debug_dp.py
Last active February 17, 2023 07:04
DP "not same device" crash after onnx export
import os
import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import DataLoader, Dataset
import nncf
from nncf.config import NNCFConfig
from nncf.config.structures import (BNAdaptationInitArgs,
@yujiepan-work
yujiepan-work / README-reproducing-bert-base-uncased-sst2-int8-unstructured80.md
Last active March 7, 2023 01:38
reproducing huggingface model: yujiepan/bert-base-uncased-sst2-int8-unstructured80

Joint magnitude pruning, quantization and distillation on BERT-base/SST-2

This model conducts unstructured magnitude pruning, quantization and distillation at the same time on BERT-base when finetuning on the GLUE SST2 dataset. It achieves the following results on the evaluation set:

  • Torch accuracy: 0.9128
  • OpenVINO IR accuracy: 0.9128
  • Sparsity in transformer block linear layers: 0.80

Setup

from contextlib import contextmanager
from unittest.mock import patch
from optimum.intel.openvino import OVModelForQuestionAnswering
import pandas as pd
import datasets
import evaluate
from evaluate import evaluator
from transformers import AutoTokenizer, pipeline, AutoModelForQuestionAnswering
@yujiepan-work
yujiepan-work / ovmodel_pipeline_superb_ks.py
Last active March 22, 2023 10:05
ovmodel_pipeline_superb_ks.py
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
from collections import defaultdict
import time
import numpy as np
import pandas as pd
from multiprocessing import Pool
@yujiepan-work
yujiepan-work / ovmodel_pipeline_food101.py
Last active March 22, 2023 10:03
ovmodel_pipeline_food101.py
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
from optimum.intel.openvino import OVModelForImageClassification
import pandas as pd
import numpy as np
import datasets
import evaluate # Use pip install git+https://github.com/huggingface/evaluate.git
from evaluate import evaluator
@yujiepan-work
yujiepan-work / benchmark_app_ovmodel.ipynb
Last active March 22, 2023 07:35
openvino_benchmark_app.bash
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yujiepan-work
yujiepan-work / benchmark_ffn_moe.py
Created April 26, 2023 01:47
benchmarking FFN with MoE
# %%
import torch.utils.benchmark as benchmark
import torch.nn as nn
from dataclasses import dataclass
import torch
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
class FeedForward(nn.Module):
def __init__(self, input_dim, intermediate_size):
@yujiepan-work
yujiepan-work / 0000 optimum pipeline eval.md
Last active May 15, 2023 13:40
optimum pipeline eval
  • OV_MODELS or TORCH_MODELS can be a model_id on huggingface or a local folder
  • For text tasks, there is a patch to ensure the sequence length is fixed. Can be removed if the model accepts arbitrary shape
import copy
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
from functools import partial
from pathlib import Path
import json
from dataclasses import dataclass
import typing
import torch