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