Upload openvino.ipynb
Browse filesyou need some dependencies to run the code.
- openvino.ipynb +153 -0
openvino.ipynb
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "1128b0b6-b3a1-4553-a284-b1206b3c5a09",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"name": "stdout",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"INFO:nncf:NNCF initialized successfully. Supported frameworks detected: torch, onnx, openvino\n"
|
14 |
+
]
|
15 |
+
},
|
16 |
+
{
|
17 |
+
"name": "stderr",
|
18 |
+
"output_type": "stream",
|
19 |
+
"text": [
|
20 |
+
"/home/anish/miniconda3/envs/pytorch_test/lib/python3.11/site-packages/transformers/utils/import_utils.py:519: FutureWarning: `is_torch_tpu_available` is deprecated and will be removed in 4.41.0. Please use the `is_torch_xla_available` instead.\n",
|
21 |
+
" warnings.warn(\n",
|
22 |
+
"/home/anish/miniconda3/envs/pytorch_test/lib/python3.11/site-packages/diffusers/utils/outputs.py:63: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.\n",
|
23 |
+
" torch.utils._pytree._register_pytree_node(\n"
|
24 |
+
]
|
25 |
+
}
|
26 |
+
],
|
27 |
+
"source": [
|
28 |
+
"from optimum.intel import OVModelForCausalLM\n",
|
29 |
+
"from transformers import AutoConfig, AutoTokenizer, BitsAndBytesConfig\n",
|
30 |
+
"import torch\n",
|
31 |
+
"import os"
|
32 |
+
]
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"cell_type": "code",
|
36 |
+
"execution_count": 2,
|
37 |
+
"id": "d0f822f2-2bac-4b7e-bf6c-1117a836eb46",
|
38 |
+
"metadata": {},
|
39 |
+
"outputs": [],
|
40 |
+
"source": [
|
41 |
+
"tokenizer = AutoTokenizer.from_pretrained(\"/home/anish/dockerx/Buildarea/LLMs/Mistral-7B-Instruct-v0.2/int4-sym-g64\")"
|
42 |
+
]
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"cell_type": "code",
|
46 |
+
"execution_count": 3,
|
47 |
+
"id": "05cf6ff2-2aba-438d-ac78-73bfc9a50139",
|
48 |
+
"metadata": {},
|
49 |
+
"outputs": [
|
50 |
+
{
|
51 |
+
"name": "stderr",
|
52 |
+
"output_type": "stream",
|
53 |
+
"text": [
|
54 |
+
"Compiling the model to CPU ...\n"
|
55 |
+
]
|
56 |
+
}
|
57 |
+
],
|
58 |
+
"source": [
|
59 |
+
"model = OVModelForCausalLM.from_pretrained(\"/home/anish/dockerx/Buildarea/LLMs/Mistral-7B-Instruct-v0.2/int4-sym-g64\")"
|
60 |
+
]
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"cell_type": "code",
|
64 |
+
"execution_count": 4,
|
65 |
+
"id": "c3769b36-2a6e-48f9-9cb7-2a3df894bee3",
|
66 |
+
"metadata": {},
|
67 |
+
"outputs": [],
|
68 |
+
"source": [
|
69 |
+
"prompt = \"do you want phull sapport saar?\""
|
70 |
+
]
|
71 |
+
},
|
72 |
+
{
|
73 |
+
"cell_type": "code",
|
74 |
+
"execution_count": 5,
|
75 |
+
"id": "05e51bb7-5610-447b-b5e9-6882b1515ed3",
|
76 |
+
"metadata": {},
|
77 |
+
"outputs": [],
|
78 |
+
"source": [
|
79 |
+
"text = \"[INST]Write me hello world in python language[\\INST]\""
|
80 |
+
]
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"cell_type": "code",
|
84 |
+
"execution_count": 6,
|
85 |
+
"id": "d50de6df-d452-4f7d-9bfb-25bb4a4137ad",
|
86 |
+
"metadata": {},
|
87 |
+
"outputs": [],
|
88 |
+
"source": [
|
89 |
+
"model_inputs = tokenizer([prompt], return_tensors=\"pt\")"
|
90 |
+
]
|
91 |
+
},
|
92 |
+
{
|
93 |
+
"cell_type": "code",
|
94 |
+
"execution_count": 7,
|
95 |
+
"id": "59651efc-f6d1-48ff-900c-fff926f36728",
|
96 |
+
"metadata": {},
|
97 |
+
"outputs": [],
|
98 |
+
"source": [
|
99 |
+
"generated_ids = model.generate(**model_inputs, max_length=1024, pad_token_id=2)"
|
100 |
+
]
|
101 |
+
},
|
102 |
+
{
|
103 |
+
"cell_type": "code",
|
104 |
+
"execution_count": 8,
|
105 |
+
"id": "0e1e29bb-0fe0-420f-9e7a-3dd8996676dc",
|
106 |
+
"metadata": {},
|
107 |
+
"outputs": [
|
108 |
+
{
|
109 |
+
"data": {
|
110 |
+
"text/plain": [
|
111 |
+
"'<s> do you want phull sapport saar?\\n\\nI\\'m not entirely sure I understand your question. Could you please clarify what you mean by \"phull sapport saar\" and what type of support you\\'re asking for? I\\'ll do my best to help you out.</s>'"
|
112 |
+
]
|
113 |
+
},
|
114 |
+
"execution_count": 8,
|
115 |
+
"metadata": {},
|
116 |
+
"output_type": "execute_result"
|
117 |
+
}
|
118 |
+
],
|
119 |
+
"source": [
|
120 |
+
"tokenizer.batch_decode(generated_ids)[0]"
|
121 |
+
]
|
122 |
+
},
|
123 |
+
{
|
124 |
+
"cell_type": "code",
|
125 |
+
"execution_count": null,
|
126 |
+
"id": "d6d2616b-ac6e-4996-95ab-4661a84bc75d",
|
127 |
+
"metadata": {},
|
128 |
+
"outputs": [],
|
129 |
+
"source": []
|
130 |
+
}
|
131 |
+
],
|
132 |
+
"metadata": {
|
133 |
+
"kernelspec": {
|
134 |
+
"display_name": "Python 3 (ipykernel)",
|
135 |
+
"language": "python",
|
136 |
+
"name": "python3"
|
137 |
+
},
|
138 |
+
"language_info": {
|
139 |
+
"codemirror_mode": {
|
140 |
+
"name": "ipython",
|
141 |
+
"version": 3
|
142 |
+
},
|
143 |
+
"file_extension": ".py",
|
144 |
+
"mimetype": "text/x-python",
|
145 |
+
"name": "python",
|
146 |
+
"nbconvert_exporter": "python",
|
147 |
+
"pygments_lexer": "ipython3",
|
148 |
+
"version": "3.11.8"
|
149 |
+
}
|
150 |
+
},
|
151 |
+
"nbformat": 4,
|
152 |
+
"nbformat_minor": 5
|
153 |
+
}
|