Skip to content

Commit

Permalink
Show changed inputs for combined model
Browse files Browse the repository at this point in the history
  • Loading branch information
yatarkan committed Sep 9, 2024
1 parent e5ae2cc commit 1438ead
Showing 1 changed file with 28 additions and 40 deletions.
68 changes: 28 additions & 40 deletions notebooks/openvino-tokenizers/openvino-tokenizers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "0c698c94-b852-4b06-b699-7d417fb55e10",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -286,39 +286,10 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 8,
"id": "a9870da3-477f-49c5-af80-ef081f92abeb",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b1d38775dfcd4998ad989596562fb7f9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"openvino_model.xml: 0%| | 0.00/2.93M [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "45fcea39847b4659ad9b51b96dbdadf5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"openvino_model.bin: 0%| | 0.00/1.10G [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"model_dir = Path(Path(model_id).name)\n",
"\n",
Expand All @@ -344,7 +315,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 9,
"id": "fe7c0342-0e40-4f17-8340-a0ff0c99b6f1",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -372,7 +343,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 10,
"id": "58a493cc-e29d-46b5-bb6c-d28e17651d85",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -475,7 +446,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 44,
"id": "ce5fb0bf",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -514,12 +485,13 @@
"\n",
"<center><img src=\"https://github.com/openvinotoolkit/openvino_notebooks/assets/51917466/d4ece285-e445-4b76-a1ab-356427900860\"></center>\n",
"\n",
"The OpenVINO Python API allows you to avoid this by using the `share_inputs` option during inference, but it requires additional input from a developer every time the model is inferred. Combining the models and tokenizers simplifies memory management."
"The OpenVINO Python API allows you to avoid this by using the `share_inputs` option during inference, but it requires additional input from a developer every time the model is inferred. Combining the models and tokenizers simplifies memory management.\n",
"Moreover, after the combining models inputs have changed - original model has three inputs (`input_ids`, `attention_mask`, `token_type_ids`) and combined model has only one input for text input prompt."
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 45,
"id": "c044b56b-dae0-4fdb-97df-2aa555285f35",
"metadata": {},
"outputs": [],
Expand All @@ -534,15 +506,23 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 69,
"id": "c6a42d4c-1982-41b9-9612-aa19138518ac",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Logits: [[ 1.2007061 -1.4698029]]\n"
"Original OpenVINO model inputs:\n",
"<Output: names[input_ids] shape[?,?] type: i64>\n",
"<Output: names[attention_mask] shape[?,?] type: i64>\n",
"<Output: names[token_type_ids] shape[?,?] type: i64>\n",
"\n",
"Combined OpenVINO model inputs:\n",
"<Output: names[Parameter_4430] shape[?] type: string>\n",
"\n",
"Logits: [[ 1.2007061 -1.469803 ]]\n"
]
}
],
Expand All @@ -558,10 +538,18 @@
"combined_model = connect_models(ov_tokenizer, ov_model)\n",
"ov.save_model(combined_model, model_dir / \"combined_openvino_model.xml\")\n",
"\n",
"print(\"Original OpenVINO model inputs:\")\n",
"for input in ov_model.inputs:\n",
" print(input)\n",
"\n",
"print(\"\\nCombined OpenVINO model inputs:\")\n",
"for input in combined_model.inputs:\n",
" print(input)\n",
"\n",
"compiled_combined_model = core.compile_model(combined_model)\n",
"openvino_output = compiled_combined_model(text_input)\n",
"\n",
"print(f\"Logits: {openvino_output['logits']}\")"
"print(f\"\\nLogits: {openvino_output['logits']}\")"
]
},
{
Expand Down

0 comments on commit 1438ead

Please sign in to comment.