Text Generation
Transformers
PyTorch
PEFT
English
llama
decapoda-research-7b-hf
prompt answering
text-generation-inference
8-bit precision
Instructions to use Sandiago21/llama-7b-hf-prompt-answering with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Sandiago21/llama-7b-hf-prompt-answering with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Sandiago21/llama-7b-hf-prompt-answering")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Sandiago21/llama-7b-hf-prompt-answering") model = AutoModelForCausalLM.from_pretrained("Sandiago21/llama-7b-hf-prompt-answering", device_map="auto") - PEFT
How to use Sandiago21/llama-7b-hf-prompt-answering with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Sandiago21/llama-7b-hf-prompt-answering with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Sandiago21/llama-7b-hf-prompt-answering" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sandiago21/llama-7b-hf-prompt-answering", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Sandiago21/llama-7b-hf-prompt-answering
- SGLang
How to use Sandiago21/llama-7b-hf-prompt-answering with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Sandiago21/llama-7b-hf-prompt-answering" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sandiago21/llama-7b-hf-prompt-answering", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Sandiago21/llama-7b-hf-prompt-answering" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sandiago21/llama-7b-hf-prompt-answering", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Sandiago21/llama-7b-hf-prompt-answering with Docker Model Runner:
docker model run hf.co/Sandiago21/llama-7b-hf-prompt-answering
Commit ·
7e6e14e
1
Parent(s): e47fa78
commit notebook
Browse files
notebooks/HuggingFace-Inference.ipynb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "markdown",
|
| 5 |
-
"id": "
|
| 6 |
"metadata": {},
|
| 7 |
"source": [
|
| 8 |
"## Import Packages"
|
|
@@ -10,54 +10,10 @@
|
|
| 10 |
},
|
| 11 |
{
|
| 12 |
"cell_type": "code",
|
| 13 |
-
"execution_count":
|
| 14 |
-
"id": "
|
| 15 |
"metadata": {},
|
| 16 |
-
"outputs": [
|
| 17 |
-
{
|
| 18 |
-
"name": "stderr",
|
| 19 |
-
"output_type": "stream",
|
| 20 |
-
"text": [
|
| 21 |
-
"2023-06-09 21:59:52.885485: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX512F AVX512_VNNI FMA\n",
|
| 22 |
-
"To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
|
| 23 |
-
"2023-06-09 21:59:53.039141: I tensorflow/core/util/port.cc:104] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
|
| 24 |
-
"2023-06-09 21:59:53.827918: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/nvidia/lib:/usr/local/nvidia/lib64\n",
|
| 25 |
-
"2023-06-09 21:59:53.828006: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/nvidia/lib:/usr/local/nvidia/lib64\n",
|
| 26 |
-
"2023-06-09 21:59:53.828014: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.\n"
|
| 27 |
-
]
|
| 28 |
-
},
|
| 29 |
-
{
|
| 30 |
-
"name": "stdout",
|
| 31 |
-
"output_type": "stream",
|
| 32 |
-
"text": [
|
| 33 |
-
"\n",
|
| 34 |
-
"===================================BUG REPORT===================================\n",
|
| 35 |
-
"Welcome to bitsandbytes. For bug reports, please run\n",
|
| 36 |
-
"\n",
|
| 37 |
-
"python -m bitsandbytes\n",
|
| 38 |
-
"\n",
|
| 39 |
-
" and submit this information together with your error trace to: https://github.com/TimDettmers/bitsandbytes/issues\n",
|
| 40 |
-
"================================================================================\n",
|
| 41 |
-
"bin /opt/conda/envs/media-reco-env-3-8/lib/python3.8/site-packages/bitsandbytes/libbitsandbytes_cuda113_nocublaslt.so\n",
|
| 42 |
-
"CUDA SETUP: CUDA runtime path found: /opt/conda/envs/media-reco-env-3-8/lib/libcudart.so\n",
|
| 43 |
-
"CUDA SETUP: Highest compute capability among GPUs detected: 7.0\n",
|
| 44 |
-
"CUDA SETUP: Detected CUDA version 113\n",
|
| 45 |
-
"CUDA SETUP: Loading binary /opt/conda/envs/media-reco-env-3-8/lib/python3.8/site-packages/bitsandbytes/libbitsandbytes_cuda113_nocublaslt.so...\n"
|
| 46 |
-
]
|
| 47 |
-
},
|
| 48 |
-
{
|
| 49 |
-
"name": "stderr",
|
| 50 |
-
"output_type": "stream",
|
| 51 |
-
"text": [
|
| 52 |
-
"/opt/conda/envs/media-reco-env-3-8/lib/python3.8/site-packages/bitsandbytes/cuda_setup/main.py:149: UserWarning: Found duplicate ['libcudart.so', 'libcudart.so.11.0', 'libcudart.so.12.0'] files: {PosixPath('/opt/conda/envs/media-reco-env-3-8/lib/libcudart.so'), PosixPath('/opt/conda/envs/media-reco-env-3-8/lib/libcudart.so.11.0')}.. We'll flip a coin and try one of these, in order to fail forward.\n",
|
| 53 |
-
"Either way, this might cause trouble in the future:\n",
|
| 54 |
-
"If you get `CUDA error: invalid device function` errors, the above might be the cause and the solution is to make sure only one ['libcudart.so', 'libcudart.so.11.0', 'libcudart.so.12.0'] in the paths that we search based on your env.\n",
|
| 55 |
-
" warn(msg)\n",
|
| 56 |
-
"/opt/conda/envs/media-reco-env-3-8/lib/python3.8/site-packages/bitsandbytes/cuda_setup/main.py:149: UserWarning: WARNING: Compute capability < 7.5 detected! Only slow 8-bit matmul is supported for your GPU!\n",
|
| 57 |
-
" warn(msg)\n"
|
| 58 |
-
]
|
| 59 |
-
}
|
| 60 |
-
],
|
| 61 |
"source": [
|
| 62 |
"import os\n",
|
| 63 |
"os.chdir(\"..\")\n",
|
|
@@ -69,7 +25,7 @@
|
|
| 69 |
},
|
| 70 |
{
|
| 71 |
"cell_type": "markdown",
|
| 72 |
-
"id": "
|
| 73 |
"metadata": {},
|
| 74 |
"source": [
|
| 75 |
"## Utilities"
|
|
@@ -77,7 +33,7 @@
|
|
| 77 |
},
|
| 78 |
{
|
| 79 |
"cell_type": "code",
|
| 80 |
-
"execution_count":
|
| 81 |
"id": "9837afb7",
|
| 82 |
"metadata": {},
|
| 83 |
"outputs": [],
|
|
@@ -104,7 +60,7 @@
|
|
| 104 |
},
|
| 105 |
{
|
| 106 |
"cell_type": "markdown",
|
| 107 |
-
"id": "
|
| 108 |
"metadata": {},
|
| 109 |
"source": [
|
| 110 |
"## Configs"
|
|
@@ -112,8 +68,8 @@
|
|
| 112 |
},
|
| 113 |
{
|
| 114 |
"cell_type": "code",
|
| 115 |
-
"execution_count":
|
| 116 |
-
"id": "
|
| 117 |
"metadata": {},
|
| 118 |
"outputs": [],
|
| 119 |
"source": [
|
|
@@ -124,7 +80,7 @@
|
|
| 124 |
},
|
| 125 |
{
|
| 126 |
"cell_type": "markdown",
|
| 127 |
-
"id": "
|
| 128 |
"metadata": {},
|
| 129 |
"source": [
|
| 130 |
"## Load Model & Tokenizer"
|
|
@@ -132,32 +88,10 @@
|
|
| 132 |
},
|
| 133 |
{
|
| 134 |
"cell_type": "code",
|
| 135 |
-
"execution_count":
|
| 136 |
"id": "1cb5103c",
|
| 137 |
"metadata": {},
|
| 138 |
-
"outputs": [
|
| 139 |
-
{
|
| 140 |
-
"name": "stderr",
|
| 141 |
-
"output_type": "stream",
|
| 142 |
-
"text": [
|
| 143 |
-
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n"
|
| 144 |
-
]
|
| 145 |
-
},
|
| 146 |
-
{
|
| 147 |
-
"data": {
|
| 148 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 149 |
-
"model_id": "f11486f431fd48799d91ef69e586e410",
|
| 150 |
-
"version_major": 2,
|
| 151 |
-
"version_minor": 0
|
| 152 |
-
},
|
| 153 |
-
"text/plain": [
|
| 154 |
-
"Loading checkpoint shards: 0%| | 0/33 [00:00<?, ?it/s]"
|
| 155 |
-
]
|
| 156 |
-
},
|
| 157 |
-
"metadata": {},
|
| 158 |
-
"output_type": "display_data"
|
| 159 |
-
}
|
| 160 |
-
],
|
| 161 |
"source": [
|
| 162 |
"config = PeftConfig.from_pretrained(MODEL_NAME)\n",
|
| 163 |
"\n",
|
|
@@ -177,7 +111,7 @@
|
|
| 177 |
},
|
| 178 |
{
|
| 179 |
"cell_type": "markdown",
|
| 180 |
-
"id": "
|
| 181 |
"metadata": {},
|
| 182 |
"source": [
|
| 183 |
"## Generation Examples"
|
|
@@ -185,7 +119,7 @@
|
|
| 185 |
},
|
| 186 |
{
|
| 187 |
"cell_type": "code",
|
| 188 |
-
"execution_count":
|
| 189 |
"id": "10372ae3",
|
| 190 |
"metadata": {},
|
| 191 |
"outputs": [],
|
|
@@ -202,7 +136,7 @@
|
|
| 202 |
},
|
| 203 |
{
|
| 204 |
"cell_type": "markdown",
|
| 205 |
-
"id": "
|
| 206 |
"metadata": {},
|
| 207 |
"source": [
|
| 208 |
"### Example 1"
|
|
@@ -210,25 +144,10 @@
|
|
| 210 |
},
|
| 211 |
{
|
| 212 |
"cell_type": "code",
|
| 213 |
-
"execution_count":
|
| 214 |
"id": "a84a4f9e",
|
| 215 |
"metadata": {},
|
| 216 |
-
"outputs": [
|
| 217 |
-
{
|
| 218 |
-
"name": "stdout",
|
| 219 |
-
"output_type": "stream",
|
| 220 |
-
"text": [
|
| 221 |
-
"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n",
|
| 222 |
-
"\n",
|
| 223 |
-
"### Instruction:\n",
|
| 224 |
-
"I have two pieces of apples and 3 pieces of oranges. How many pieces of fruits do I have?\n",
|
| 225 |
-
"\n",
|
| 226 |
-
"### Response:\n",
|
| 227 |
-
"I have two pieces of apples and 3 pieces of oranges. How many pieces of fruits do I have?\n",
|
| 228 |
-
"I have two pieces of\n"
|
| 229 |
-
]
|
| 230 |
-
}
|
| 231 |
-
],
|
| 232 |
"source": [
|
| 233 |
"instruction = \"I have two pieces of apples and 3 pieces of oranges. How many pieces of fruits do I have?\"\n",
|
| 234 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
@@ -251,7 +170,7 @@
|
|
| 251 |
},
|
| 252 |
{
|
| 253 |
"cell_type": "markdown",
|
| 254 |
-
"id": "
|
| 255 |
"metadata": {},
|
| 256 |
"source": [
|
| 257 |
"### Example 2"
|
|
@@ -259,25 +178,10 @@
|
|
| 259 |
},
|
| 260 |
{
|
| 261 |
"cell_type": "code",
|
| 262 |
-
"execution_count":
|
| 263 |
"id": "65117ac7",
|
| 264 |
"metadata": {},
|
| 265 |
-
"outputs": [
|
| 266 |
-
{
|
| 267 |
-
"name": "stdout",
|
| 268 |
-
"output_type": "stream",
|
| 269 |
-
"text": [
|
| 270 |
-
"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n",
|
| 271 |
-
"\n",
|
| 272 |
-
"### Instruction:\n",
|
| 273 |
-
"What is the capital city of Greece and with which countries does Greece border?\n",
|
| 274 |
-
"\n",
|
| 275 |
-
"### Response:\n",
|
| 276 |
-
"The capital city of Greece is Athens and it borders Turkey, Bulgaria, Macedonia, Albania, and the Aegean Sea.\n",
|
| 277 |
-
"\n"
|
| 278 |
-
]
|
| 279 |
-
}
|
| 280 |
-
],
|
| 281 |
"source": [
|
| 282 |
"instruction = \"What is the capital city of Greece and with which countries does Greece border?\"\n",
|
| 283 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
@@ -300,7 +204,7 @@
|
|
| 300 |
},
|
| 301 |
{
|
| 302 |
"cell_type": "markdown",
|
| 303 |
-
"id": "
|
| 304 |
"metadata": {},
|
| 305 |
"source": [
|
| 306 |
"### Example 3"
|
|
@@ -308,24 +212,10 @@
|
|
| 308 |
},
|
| 309 |
{
|
| 310 |
"cell_type": "code",
|
| 311 |
-
"execution_count":
|
| 312 |
"id": "2ff7a5e5",
|
| 313 |
"metadata": {},
|
| 314 |
-
"outputs": [
|
| 315 |
-
{
|
| 316 |
-
"name": "stdout",
|
| 317 |
-
"output_type": "stream",
|
| 318 |
-
"text": [
|
| 319 |
-
"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n",
|
| 320 |
-
"\n",
|
| 321 |
-
"### Instruction:\n",
|
| 322 |
-
"How can I cook Adobo?\n",
|
| 323 |
-
"\n",
|
| 324 |
-
"### Response:\n",
|
| 325 |
-
"You can cook Adobo by adding garlic, soy sauce, vinegar, bay leaves, peppercorns, and water\n"
|
| 326 |
-
]
|
| 327 |
-
}
|
| 328 |
-
],
|
| 329 |
"source": [
|
| 330 |
"instruction = \"How can I cook Adobo?\"\n",
|
| 331 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
@@ -348,7 +238,7 @@
|
|
| 348 |
},
|
| 349 |
{
|
| 350 |
"cell_type": "markdown",
|
| 351 |
-
"id": "
|
| 352 |
"metadata": {},
|
| 353 |
"source": [
|
| 354 |
"### Example 4"
|
|
@@ -356,24 +246,10 @@
|
|
| 356 |
},
|
| 357 |
{
|
| 358 |
"cell_type": "code",
|
| 359 |
-
"execution_count":
|
| 360 |
-
"id": "
|
| 361 |
"metadata": {},
|
| 362 |
-
"outputs": [
|
| 363 |
-
{
|
| 364 |
-
"name": "stdout",
|
| 365 |
-
"output_type": "stream",
|
| 366 |
-
"text": [
|
| 367 |
-
"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n",
|
| 368 |
-
"\n",
|
| 369 |
-
"### Instruction:\n",
|
| 370 |
-
"Which are the tags of the following article: 'A year ago, Russia invaded Ukraine in a major escalation of the Russo-Ukrainian War, which had begun in 2014. The invasion has resulted in thousands of deaths, and instigated Europe's largest refugee crisis since World War II.'?\n",
|
| 371 |
-
"\n",
|
| 372 |
-
"### Response:\n",
|
| 373 |
-
"The tags of the following article: 'A year ago, Russia invaded Ukraine in a major escalation of the Russo-Ukrainian\n"
|
| 374 |
-
]
|
| 375 |
-
}
|
| 376 |
-
],
|
| 377 |
"source": [
|
| 378 |
"instruction = \"Which are the tags of the following article: 'A year ago, Russia invaded Ukraine in a major escalation of the Russo-Ukrainian War, which had begun in 2014. The invasion has resulted in thousands of deaths, and instigated Europe's largest refugee crisis since World War II.'?\"\n",
|
| 379 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
@@ -396,7 +272,7 @@
|
|
| 396 |
},
|
| 397 |
{
|
| 398 |
"cell_type": "markdown",
|
| 399 |
-
"id": "
|
| 400 |
"metadata": {},
|
| 401 |
"source": [
|
| 402 |
"## Let's Load the Fine-Tuned version"
|
|
@@ -404,7 +280,7 @@
|
|
| 404 |
},
|
| 405 |
{
|
| 406 |
"cell_type": "code",
|
| 407 |
-
"execution_count":
|
| 408 |
"id": "9cba7db1",
|
| 409 |
"metadata": {},
|
| 410 |
"outputs": [],
|
|
@@ -414,7 +290,7 @@
|
|
| 414 |
},
|
| 415 |
{
|
| 416 |
"cell_type": "markdown",
|
| 417 |
-
"id": "
|
| 418 |
"metadata": {},
|
| 419 |
"source": [
|
| 420 |
"### Example 1"
|
|
@@ -422,26 +298,10 @@
|
|
| 422 |
},
|
| 423 |
{
|
| 424 |
"cell_type": "code",
|
| 425 |
-
"execution_count":
|
| 426 |
"id": "af3a477a",
|
| 427 |
"metadata": {},
|
| 428 |
-
"outputs": [
|
| 429 |
-
{
|
| 430 |
-
"name": "stdout",
|
| 431 |
-
"output_type": "stream",
|
| 432 |
-
"text": [
|
| 433 |
-
"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n",
|
| 434 |
-
"\n",
|
| 435 |
-
"### Instruction:\n",
|
| 436 |
-
"I have two pieces of apples and 3 pieces of oranges. How many pieces of fruits do I have?\n",
|
| 437 |
-
"\n",
|
| 438 |
-
"### Response:\n",
|
| 439 |
-
"If you have 2 pieces of apples and 3 pieces of oranges, then you have 5 pieces of fruits.\n",
|
| 440 |
-
"\n",
|
| 441 |
-
"###\n"
|
| 442 |
-
]
|
| 443 |
-
}
|
| 444 |
-
],
|
| 445 |
"source": [
|
| 446 |
"instruction = \"I have two pieces of apples and 3 pieces of oranges. How many pieces of fruits do I have?\"\n",
|
| 447 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
@@ -464,7 +324,7 @@
|
|
| 464 |
},
|
| 465 |
{
|
| 466 |
"cell_type": "markdown",
|
| 467 |
-
"id": "
|
| 468 |
"metadata": {},
|
| 469 |
"source": [
|
| 470 |
"### Example 2"
|
|
@@ -472,24 +332,10 @@
|
|
| 472 |
},
|
| 473 |
{
|
| 474 |
"cell_type": "code",
|
| 475 |
-
"execution_count":
|
| 476 |
-
"id": "
|
| 477 |
"metadata": {},
|
| 478 |
-
"outputs": [
|
| 479 |
-
{
|
| 480 |
-
"name": "stdout",
|
| 481 |
-
"output_type": "stream",
|
| 482 |
-
"text": [
|
| 483 |
-
"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n",
|
| 484 |
-
"\n",
|
| 485 |
-
"### Instruction:\n",
|
| 486 |
-
"What is the capital city of Greece and with which countries does Greece border?\n",
|
| 487 |
-
"\n",
|
| 488 |
-
"### Response:\n",
|
| 489 |
-
"Greece borders Albania, Bulgaria, Turkey, Macedonia, and the Aegean Sea. The capital of Greece is Athens.\n"
|
| 490 |
-
]
|
| 491 |
-
}
|
| 492 |
-
],
|
| 493 |
"source": [
|
| 494 |
"instruction = \"What is the capital city of Greece and with which countries does Greece border?\"\n",
|
| 495 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
@@ -512,7 +358,7 @@
|
|
| 512 |
},
|
| 513 |
{
|
| 514 |
"cell_type": "markdown",
|
| 515 |
-
"id": "
|
| 516 |
"metadata": {},
|
| 517 |
"source": [
|
| 518 |
"### Example 3"
|
|
@@ -520,30 +366,10 @@
|
|
| 520 |
},
|
| 521 |
{
|
| 522 |
"cell_type": "code",
|
| 523 |
-
"execution_count":
|
| 524 |
-
"id": "
|
| 525 |
"metadata": {},
|
| 526 |
-
"outputs": [
|
| 527 |
-
{
|
| 528 |
-
"name": "stdout",
|
| 529 |
-
"output_type": "stream",
|
| 530 |
-
"text": [
|
| 531 |
-
"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n",
|
| 532 |
-
"\n",
|
| 533 |
-
"### Instruction:\n",
|
| 534 |
-
"How can I cook Adobo?\n",
|
| 535 |
-
"\n",
|
| 536 |
-
"### Response:\n",
|
| 537 |
-
"Here's a recipe for adobo:\n",
|
| 538 |
-
"\n",
|
| 539 |
-
"\\begin{code}\n",
|
| 540 |
-
"\n",
|
| 541 |
-
"\\begin{pre}\n",
|
| 542 |
-
"\n",
|
| 543 |
-
"\\end{code\n"
|
| 544 |
-
]
|
| 545 |
-
}
|
| 546 |
-
],
|
| 547 |
"source": [
|
| 548 |
"instruction = \"How can I cook Adobo?\"\n",
|
| 549 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
@@ -566,7 +392,7 @@
|
|
| 566 |
},
|
| 567 |
{
|
| 568 |
"cell_type": "markdown",
|
| 569 |
-
"id": "
|
| 570 |
"metadata": {},
|
| 571 |
"source": [
|
| 572 |
"### Example 4"
|
|
@@ -574,26 +400,10 @@
|
|
| 574 |
},
|
| 575 |
{
|
| 576 |
"cell_type": "code",
|
| 577 |
-
"execution_count":
|
| 578 |
-
"id": "
|
| 579 |
"metadata": {},
|
| 580 |
-
"outputs": [
|
| 581 |
-
{
|
| 582 |
-
"name": "stdout",
|
| 583 |
-
"output_type": "stream",
|
| 584 |
-
"text": [
|
| 585 |
-
"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n",
|
| 586 |
-
"\n",
|
| 587 |
-
"### Instruction:\n",
|
| 588 |
-
"Which are the tags of the following article: 'A year ago, Russia invaded Ukraine in a major escalation of the Russo-Ukrainian War, which had begun in 2014. The invasion has resulted in thousands of deaths, and instigated Europe's largest refugee crisis since World War II.'?\n",
|
| 589 |
-
"\n",
|
| 590 |
-
"### Response:\n",
|
| 591 |
-
"\n",
|
| 592 |
-
"### Instruction:\n",
|
| 593 |
-
"Which are the tags of the following article: 'A year ago, Russia invaded Ukraine in a major escal\n"
|
| 594 |
-
]
|
| 595 |
-
}
|
| 596 |
-
],
|
| 597 |
"source": [
|
| 598 |
"instruction = \"Which are the tags of the following article: 'A year ago, Russia invaded Ukraine in a major escalation of the Russo-Ukrainian War, which had begun in 2014. The invasion has resulted in thousands of deaths, and instigated Europe's largest refugee crisis since World War II.'?\"\n",
|
| 599 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "markdown",
|
| 5 |
+
"id": "15908f0e",
|
| 6 |
"metadata": {},
|
| 7 |
"source": [
|
| 8 |
"## Import Packages"
|
|
|
|
| 10 |
},
|
| 11 |
{
|
| 12 |
"cell_type": "code",
|
| 13 |
+
"execution_count": null,
|
| 14 |
+
"id": "94f0ccef",
|
| 15 |
"metadata": {},
|
| 16 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
"source": [
|
| 18 |
"import os\n",
|
| 19 |
"os.chdir(\"..\")\n",
|
|
|
|
| 25 |
},
|
| 26 |
{
|
| 27 |
"cell_type": "markdown",
|
| 28 |
+
"id": "58b927f4",
|
| 29 |
"metadata": {},
|
| 30 |
"source": [
|
| 31 |
"## Utilities"
|
|
|
|
| 33 |
},
|
| 34 |
{
|
| 35 |
"cell_type": "code",
|
| 36 |
+
"execution_count": null,
|
| 37 |
"id": "9837afb7",
|
| 38 |
"metadata": {},
|
| 39 |
"outputs": [],
|
|
|
|
| 60 |
},
|
| 61 |
{
|
| 62 |
"cell_type": "markdown",
|
| 63 |
+
"id": "b37f5f57",
|
| 64 |
"metadata": {},
|
| 65 |
"source": [
|
| 66 |
"## Configs"
|
|
|
|
| 68 |
},
|
| 69 |
{
|
| 70 |
"cell_type": "code",
|
| 71 |
+
"execution_count": null,
|
| 72 |
+
"id": "b53f6c18",
|
| 73 |
"metadata": {},
|
| 74 |
"outputs": [],
|
| 75 |
"source": [
|
|
|
|
| 80 |
},
|
| 81 |
{
|
| 82 |
"cell_type": "markdown",
|
| 83 |
+
"id": "ec8111a9",
|
| 84 |
"metadata": {},
|
| 85 |
"source": [
|
| 86 |
"## Load Model & Tokenizer"
|
|
|
|
| 88 |
},
|
| 89 |
{
|
| 90 |
"cell_type": "code",
|
| 91 |
+
"execution_count": null,
|
| 92 |
"id": "1cb5103c",
|
| 93 |
"metadata": {},
|
| 94 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
"source": [
|
| 96 |
"config = PeftConfig.from_pretrained(MODEL_NAME)\n",
|
| 97 |
"\n",
|
|
|
|
| 111 |
},
|
| 112 |
{
|
| 113 |
"cell_type": "markdown",
|
| 114 |
+
"id": "d265647e",
|
| 115 |
"metadata": {},
|
| 116 |
"source": [
|
| 117 |
"## Generation Examples"
|
|
|
|
| 119 |
},
|
| 120 |
{
|
| 121 |
"cell_type": "code",
|
| 122 |
+
"execution_count": null,
|
| 123 |
"id": "10372ae3",
|
| 124 |
"metadata": {},
|
| 125 |
"outputs": [],
|
|
|
|
| 136 |
},
|
| 137 |
{
|
| 138 |
"cell_type": "markdown",
|
| 139 |
+
"id": "1f6e7df1",
|
| 140 |
"metadata": {},
|
| 141 |
"source": [
|
| 142 |
"### Example 1"
|
|
|
|
| 144 |
},
|
| 145 |
{
|
| 146 |
"cell_type": "code",
|
| 147 |
+
"execution_count": null,
|
| 148 |
"id": "a84a4f9e",
|
| 149 |
"metadata": {},
|
| 150 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
"source": [
|
| 152 |
"instruction = \"I have two pieces of apples and 3 pieces of oranges. How many pieces of fruits do I have?\"\n",
|
| 153 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
|
|
| 170 |
},
|
| 171 |
{
|
| 172 |
"cell_type": "markdown",
|
| 173 |
+
"id": "8143ca1f",
|
| 174 |
"metadata": {},
|
| 175 |
"source": [
|
| 176 |
"### Example 2"
|
|
|
|
| 178 |
},
|
| 179 |
{
|
| 180 |
"cell_type": "code",
|
| 181 |
+
"execution_count": null,
|
| 182 |
"id": "65117ac7",
|
| 183 |
"metadata": {},
|
| 184 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
"source": [
|
| 186 |
"instruction = \"What is the capital city of Greece and with which countries does Greece border?\"\n",
|
| 187 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
|
|
| 204 |
},
|
| 205 |
{
|
| 206 |
"cell_type": "markdown",
|
| 207 |
+
"id": "447f75f9",
|
| 208 |
"metadata": {},
|
| 209 |
"source": [
|
| 210 |
"### Example 3"
|
|
|
|
| 212 |
},
|
| 213 |
{
|
| 214 |
"cell_type": "code",
|
| 215 |
+
"execution_count": null,
|
| 216 |
"id": "2ff7a5e5",
|
| 217 |
"metadata": {},
|
| 218 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
"source": [
|
| 220 |
"instruction = \"How can I cook Adobo?\"\n",
|
| 221 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
|
|
| 238 |
},
|
| 239 |
{
|
| 240 |
"cell_type": "markdown",
|
| 241 |
+
"id": "c0f1fc51",
|
| 242 |
"metadata": {},
|
| 243 |
"source": [
|
| 244 |
"### Example 4"
|
|
|
|
| 246 |
},
|
| 247 |
{
|
| 248 |
"cell_type": "code",
|
| 249 |
+
"execution_count": null,
|
| 250 |
+
"id": "4073cb6d",
|
| 251 |
"metadata": {},
|
| 252 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
"source": [
|
| 254 |
"instruction = \"Which are the tags of the following article: 'A year ago, Russia invaded Ukraine in a major escalation of the Russo-Ukrainian War, which had begun in 2014. The invasion has resulted in thousands of deaths, and instigated Europe's largest refugee crisis since World War II.'?\"\n",
|
| 255 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
|
|
| 272 |
},
|
| 273 |
{
|
| 274 |
"cell_type": "markdown",
|
| 275 |
+
"id": "df08ac5a",
|
| 276 |
"metadata": {},
|
| 277 |
"source": [
|
| 278 |
"## Let's Load the Fine-Tuned version"
|
|
|
|
| 280 |
},
|
| 281 |
{
|
| 282 |
"cell_type": "code",
|
| 283 |
+
"execution_count": null,
|
| 284 |
"id": "9cba7db1",
|
| 285 |
"metadata": {},
|
| 286 |
"outputs": [],
|
|
|
|
| 290 |
},
|
| 291 |
{
|
| 292 |
"cell_type": "markdown",
|
| 293 |
+
"id": "5bc70c31",
|
| 294 |
"metadata": {},
|
| 295 |
"source": [
|
| 296 |
"### Example 1"
|
|
|
|
| 298 |
},
|
| 299 |
{
|
| 300 |
"cell_type": "code",
|
| 301 |
+
"execution_count": null,
|
| 302 |
"id": "af3a477a",
|
| 303 |
"metadata": {},
|
| 304 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
"source": [
|
| 306 |
"instruction = \"I have two pieces of apples and 3 pieces of oranges. How many pieces of fruits do I have?\"\n",
|
| 307 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
|
|
| 324 |
},
|
| 325 |
{
|
| 326 |
"cell_type": "markdown",
|
| 327 |
+
"id": "622b3c0a",
|
| 328 |
"metadata": {},
|
| 329 |
"source": [
|
| 330 |
"### Example 2"
|
|
|
|
| 332 |
},
|
| 333 |
{
|
| 334 |
"cell_type": "code",
|
| 335 |
+
"execution_count": null,
|
| 336 |
+
"id": "eab112ae",
|
| 337 |
"metadata": {},
|
| 338 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
"source": [
|
| 340 |
"instruction = \"What is the capital city of Greece and with which countries does Greece border?\"\n",
|
| 341 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
|
|
| 358 |
},
|
| 359 |
{
|
| 360 |
"cell_type": "markdown",
|
| 361 |
+
"id": "fb0e6d9e",
|
| 362 |
"metadata": {},
|
| 363 |
"source": [
|
| 364 |
"### Example 3"
|
|
|
|
| 366 |
},
|
| 367 |
{
|
| 368 |
"cell_type": "code",
|
| 369 |
+
"execution_count": null,
|
| 370 |
+
"id": "df571d56",
|
| 371 |
"metadata": {},
|
| 372 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
"source": [
|
| 374 |
"instruction = \"How can I cook Adobo?\"\n",
|
| 375 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|
|
|
|
| 392 |
},
|
| 393 |
{
|
| 394 |
"cell_type": "markdown",
|
| 395 |
+
"id": "8d3aa375",
|
| 396 |
"metadata": {},
|
| 397 |
"source": [
|
| 398 |
"### Example 4"
|
|
|
|
| 400 |
},
|
| 401 |
{
|
| 402 |
"cell_type": "code",
|
| 403 |
+
"execution_count": null,
|
| 404 |
+
"id": "4975198b",
|
| 405 |
"metadata": {},
|
| 406 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
"source": [
|
| 408 |
"instruction = \"Which are the tags of the following article: 'A year ago, Russia invaded Ukraine in a major escalation of the Russo-Ukrainian War, which had begun in 2014. The invasion has resulted in thousands of deaths, and instigated Europe's largest refugee crisis since World War II.'?\"\n",
|
| 409 |
"input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.\n",
|