Skip to content

Commit

Permalink
Update protobuf (#1307)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkraune authored Sep 25, 2023
1 parent 016835c commit f7d225a
Showing 1 changed file with 18 additions and 145 deletions.
163 changes: 18 additions & 145 deletions msmarco-ranking/src/main/python/model-exporting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,18 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"id": "nkTWbs6anELx"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: torch in /usr/local/anaconda3/lib/python3.8/site-packages (1.12.1)\n",
"Requirement already satisfied: numpy in /usr/local/anaconda3/lib/python3.8/site-packages (1.23.3)\n",
"Requirement already satisfied: transformers in /usr/local/anaconda3/lib/python3.8/site-packages (4.22.0)\n",
"Requirement already satisfied: onnx in /usr/local/anaconda3/lib/python3.8/site-packages (1.12.0)\n",
"Requirement already satisfied: onnxruntime in /usr/local/anaconda3/lib/python3.8/site-packages (1.12.1)\n",
"Requirement already satisfied: protobuf<=3.20.1,>=3.12.2 in /usr/local/anaconda3/lib/python3.8/site-packages (3.20.1)\n",
"Requirement already satisfied: typing-extensions in /usr/local/anaconda3/lib/python3.8/site-packages (from torch) (3.10.0.2)\n",
"Requirement already satisfied: huggingface-hub<1.0,>=0.9.0 in /usr/local/anaconda3/lib/python3.8/site-packages (from transformers) (0.9.1)\n",
"Requirement already satisfied: regex!=2019.12.17 in /usr/local/anaconda3/lib/python3.8/site-packages (from transformers) (2021.8.3)\n",
"Requirement already satisfied: tqdm>=4.27 in /usr/local/anaconda3/lib/python3.8/site-packages (from transformers) (4.64.0)\n",
"Requirement already satisfied: filelock in /usr/local/anaconda3/lib/python3.8/site-packages (from transformers) (3.0.12)\n",
"Requirement already satisfied: tokenizers!=0.11.3,<0.13,>=0.11.1 in /usr/local/anaconda3/lib/python3.8/site-packages (from transformers) (0.12.1)\n",
"Requirement already satisfied: requests in /usr/local/anaconda3/lib/python3.8/site-packages (from transformers) (2.26.0)\n",
"Requirement already satisfied: pyyaml>=5.1 in /usr/local/anaconda3/lib/python3.8/site-packages (from transformers) (5.4.1)\n",
"Requirement already satisfied: packaging>=20.0 in /usr/local/anaconda3/lib/python3.8/site-packages (from transformers) (21.0)\n",
"Requirement already satisfied: coloredlogs in /usr/local/anaconda3/lib/python3.8/site-packages (from onnxruntime) (15.0.1)\n",
"Requirement already satisfied: flatbuffers in /usr/local/anaconda3/lib/python3.8/site-packages (from onnxruntime) (2.0)\n",
"Requirement already satisfied: sympy in /usr/local/anaconda3/lib/python3.8/site-packages (from onnxruntime) (1.8)\n",
"Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/anaconda3/lib/python3.8/site-packages (from packaging>=20.0->transformers) (2.4.7)\n",
"Requirement already satisfied: humanfriendly>=9.1 in /usr/local/anaconda3/lib/python3.8/site-packages (from coloredlogs->onnxruntime) (10.0)\n",
"Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/anaconda3/lib/python3.8/site-packages (from requests->transformers) (2.0.4)\n",
"Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/anaconda3/lib/python3.8/site-packages (from requests->transformers) (1.26.7)\n",
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/anaconda3/lib/python3.8/site-packages (from requests->transformers) (3.2)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/anaconda3/lib/python3.8/site-packages (from requests->transformers) (2022.6.15)\n",
"Requirement already satisfied: mpmath>=0.19 in /usr/local/anaconda3/lib/python3.8/site-packages (from sympy->onnxruntime) (1.2.1)\n"
]
}
],
"outputs": [],
"source": [
"!python3 -m pip install torch numpy transformers onnx onnxruntime \"protobuf >= 3.12.2, <= 3.20.1\""
"!python3 -m pip install torch numpy transformers onnx onnxruntime \"protobuf >=4.24.2, <=4.24.2\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {
"id": "KelhzOgUnELx"
},
Expand Down Expand Up @@ -91,7 +59,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {
"id": "AId8Ne0ZnELy"
},
Expand All @@ -115,28 +83,15 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "TKg22UyonELz",
"outputId": "9527db8f-d7c7-4855-87a2-548fcabb2624"
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: The shape inference of prim::Constant type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.\n",
"WARNING: The shape inference of prim::Constant type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.\n",
"WARNING: The shape inference of prim::Constant type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.\n",
"WARNING: The shape inference of prim::Constant type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.\n",
"WARNING: The shape inference of prim::Constant type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.\n",
"WARNING: The shape inference of prim::Constant type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.\n"
]
}
],
"outputs": [],
"source": [
"encoder = MeanPoolingEncoderONNX.from_pretrained(\"sentence-transformers/msmarco-MiniLM-L-6-v3\")\n",
"encoder = encoder.eval()\n",
Expand All @@ -162,34 +117,15 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "E778RINgnEL0",
"outputId": "72381800-f9e7-4a9f-afc1-479baa7e8e65"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ignore MatMul due to non constant B: /[MatMul_143]\n",
"Ignore MatMul due to non constant B: /[MatMul_148]\n",
"Ignore MatMul due to non constant B: /[MatMul_245]\n",
"Ignore MatMul due to non constant B: /[MatMul_250]\n",
"Ignore MatMul due to non constant B: /[MatMul_347]\n",
"Ignore MatMul due to non constant B: /[MatMul_352]\n",
"Ignore MatMul due to non constant B: /[MatMul_449]\n",
"Ignore MatMul due to non constant B: /[MatMul_454]\n",
"Ignore MatMul due to non constant B: /[MatMul_551]\n",
"Ignore MatMul due to non constant B: /[MatMul_556]\n",
"Ignore MatMul due to non constant B: /[MatMul_653]\n",
"Ignore MatMul due to non constant B: /[MatMul_658]\n"
]
}
],
"outputs": [],
"source": [
"from onnxruntime.quantization import quantize_dynamic, QuantType\n",
"quantized_model = quantize_dynamic(\"sentence-msmarco-MiniLM-L-6-v3.onnx\", \n",
Expand All @@ -209,7 +145,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {
"id": "xe5hXsoAnEL1"
},
Expand All @@ -231,21 +167,11 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {
"id": "ObLoQY5tnEL2"
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: The shape inference of prim::Constant type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.\n",
"WARNING: The shape inference of prim::Constant type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.\n",
"WARNING: The shape inference of prim::Constant type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.\n"
]
}
],
"outputs": [],
"source": [
"colbert_query_encoder = VespaColBERT.from_pretrained(\"vespa-engine/col-minilm\") \n",
"input_names = [\"input_ids\", \"attention_mask\"]\n",
Expand All @@ -269,34 +195,15 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "iq6UgCbbnEL2",
"outputId": "a958b62a-6edf-46f3-ff41-f3df1b776017"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ignore MatMul due to non constant B: /[MatMul_143]\n",
"Ignore MatMul due to non constant B: /[MatMul_148]\n",
"Ignore MatMul due to non constant B: /[MatMul_245]\n",
"Ignore MatMul due to non constant B: /[MatMul_250]\n",
"Ignore MatMul due to non constant B: /[MatMul_347]\n",
"Ignore MatMul due to non constant B: /[MatMul_352]\n",
"Ignore MatMul due to non constant B: /[MatMul_449]\n",
"Ignore MatMul due to non constant B: /[MatMul_454]\n",
"Ignore MatMul due to non constant B: /[MatMul_551]\n",
"Ignore MatMul due to non constant B: /[MatMul_556]\n",
"Ignore MatMul due to non constant B: /[MatMul_653]\n",
"Ignore MatMul due to non constant B: /[MatMul_658]\n"
]
}
],
"outputs": [],
"source": [
"quantized_model = quantize_dynamic(\"vespa-colMiniLM-L-6.onnx\", \n",
" \"vespa-colMiniLM-L-6-quantized.onnx\")"
Expand All @@ -313,7 +220,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand Down Expand Up @@ -379,41 +286,7 @@
"id": "golfkyvwnEL3",
"outputId": "336c3137-e1f7-46be-d33b-b8ce25288f68"
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/local/anaconda3/lib/python3.8/site-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.23.3\n",
" warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using framework PyTorch: 1.12.1\n",
"Found input input_ids with shape: {0: 'batch', 1: 'sequence'}\n",
"Found input token_type_ids with shape: {0: 'batch', 1: 'sequence'}\n",
"Found input attention_mask with shape: {0: 'batch', 1: 'sequence'}\n",
"Found output output_0 with shape: {0: 'batch'}\n",
"Ensuring inputs are in correct order\n",
"position_ids is not present in the generated input list.\n",
"Generated inputs order: ['input_ids', 'attention_mask', 'token_type_ids']\n",
"Quantized model has been written at ms-marco-MiniLM-L-6-v2-quantized.onnx: ✔\n"
]
},
{
"data": {
"text/plain": [
"PosixPath('ms-marco-MiniLM-L-6-v2-quantized.onnx')"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"from transformers import AutoTokenizer, AutoModelForSequenceClassification\n",
"import transformers.convert_graph_to_onnx as onnx_convert\n",
Expand Down Expand Up @@ -456,7 +329,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.11.5"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down Expand Up @@ -2175,4 +2048,4 @@
},
"nbformat": 4,
"nbformat_minor": 1
}
}

0 comments on commit f7d225a

Please sign in to comment.