{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "085740a4-476b-43d3-8706-17ea6ad73d5b", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/huggingface_hub/repocard.py:105: UserWarning: Repo card metadata block was not found. Setting CardData to empty.\n", " warnings.warn(\"Repo card metadata block was not found. Setting CardData to empty.\")\n" ] } ], "source": [ "from datasets import load_dataset\n", "\n", "dataset_name = \"timdettmers/openassistant-guanaco\"\n", "dataset = load_dataset(dataset_name, split=\"train\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "a3d9b409-e0d3-45c8-86f2-7a4209f3c948", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Dataset({\n", " features: ['text'],\n", " num_rows: 9846\n", "})" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dataset" ] }, { "cell_type": "code", "execution_count": 4, "id": "23952eb2-8e73-4784-a5ca-534bfae44c80", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'text': '### Human: ¿CUales son las etapas del desarrollo y en qué consisten según Piaget?### Assistant: Jean Piaget fue un psicólogo suizo que propuso una teoría sobre el desarrollo cognitivo humano que consta de cuatro etapas:\\n\\nEtapa sensoriomotora (0-2 años): Durante esta etapa, el niño aprende a través de sus sentidos y movimientos. Descubre que sus acciones pueden tener un impacto en el entorno y comienza a formarse una idea básica de objetividad y continuidad.\\n\\nEtapa preoperatoria (2-7 años): En esta etapa, el niño comienza a desarrollar un pensamiento simbólico y a comprender que las cosas pueden representar a otras cosas. También comienzan a desarrollar un pensamiento lógico y a comprender conceptos como la causa y el efecto.\\n\\nEtapa de operaciones concretas (7-12 años): Durante esta etapa, el niño desarrolla un pensamiento lógico y comprende las relaciones causales. Empiezan a comprender que las cosas pueden tener múltiples perspectivas y que los conceptos pueden ser más complejos de lo que parecen a simple vista.\\n\\nEtapa de operaciones formales (12 años en adelante): En esta etapa, el individuo desarrolla un pensamiento abstracto y puede comprender conceptos complejos y abstractos. Son capaces de razonar hipotéticamente y tienen la capacidad de reflexionar sobre su propio pensamiento.\\n\\nEstas etapas no son lineales y algunos individuos pueden avanzar en una etapa más rápidamente que en otras. La teoría de Piaget sobre el desarrollo cognitivo ha sido ampliamente utilizada y es una base importante para la investigación y el entendimiento del desarrollo humano.### Human: ¿Hay otras teorías sobre las etapas del desarrollo que reafirmen o contradigan a la teoría de Piaget?'}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dataset[1]" ] }, { "cell_type": "code", "execution_count": 5, "id": "a855608b-9609-424f-b482-f9a45b592369", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5ce955c31dd74916b7c4c8b7044a4564", "version_major": 2, "version_minor": 0 }, "text/plain": [ "config.json: 0%| | 0.00/581 [00:00'" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tokenizer.pad_token" ] }, { "cell_type": "code", "execution_count": 8, "id": "be54dd49-0cfb-4edd-9dd8-ae16288d9668", "metadata": {}, "outputs": [], "source": [ "tokenizer.unk_token" ] }, { "cell_type": "code", "execution_count": 9, "id": "dd346b8a-1f4d-45bf-85ff-facfa9473e99", "metadata": {}, "outputs": [], "source": [ "tokenizer.sep_token" ] }, { "cell_type": "code", "execution_count": 10, "id": "bcde26ce-0b19-4a34-a8e6-5ff34b50a964", "metadata": {}, "outputs": [], "source": [ "tokenizer.chat_template" ] }, { "cell_type": "code", "execution_count": 11, "id": "2031ebad-fd3c-4b53-824b-a10a57c73762", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "FalconForCausalLM(\n", " (transformer): FalconModel(\n", " (word_embeddings): Embedding(65024, 4544)\n", " (h): ModuleList(\n", " (0-31): 32 x FalconDecoderLayer(\n", " (self_attention): FalconAttention(\n", " (rotary_emb): FalconRotaryEmbedding()\n", " (query_key_value): Linear4bit(in_features=4544, out_features=4672, bias=False)\n", " (dense): Linear4bit(in_features=4544, out_features=4544, bias=False)\n", " (attention_dropout): Dropout(p=0.0, inplace=False)\n", " )\n", " (mlp): FalconMLP(\n", " (dense_h_to_4h): Linear4bit(in_features=4544, out_features=18176, bias=False)\n", " (act): GELU(approximate='none')\n", " (dense_4h_to_h): Linear4bit(in_features=18176, out_features=4544, bias=False)\n", " )\n", " (input_layernorm): LayerNorm((4544,), eps=1e-05, elementwise_affine=True)\n", " )\n", " )\n", " (ln_f): LayerNorm((4544,), eps=1e-05, elementwise_affine=True)\n", " )\n", " (lm_head): Linear(in_features=4544, out_features=65024, bias=False)\n", ")" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model" ] }, { "cell_type": "code", "execution_count": 12, "id": "d5c76cc9-5925-4d49-819d-d72a0149bea3", "metadata": {}, "outputs": [], "source": [ "from peft import LoraConfig\n", "\n", "lora_alpha = 16\n", "lora_dropout = 0.1\n", "lora_r = 64\n", "\n", "peft_config = LoraConfig(\n", " lora_alpha=lora_alpha,\n", " lora_dropout=lora_dropout,\n", " r=lora_r,\n", " bias=\"none\",\n", " task_type=\"CAUSAL_LM\",\n", " target_modules=[\n", " \"query_key_value\",\n", " \"dense\",\n", " \"dense_h_to_4h\",\n", " \"dense_4h_to_h\",\n", " ]\n", ")" ] }, { "cell_type": "code", "execution_count": 13, "id": "73134583-40da-4e66-ae8f-ecfe798d202a", "metadata": {}, "outputs": [], "source": [ "from transformers import TrainingArguments\n", "\n", "output_dir = \"./results\"\n", "per_device_train_batch_size = 4\n", "gradient_accumulation_steps = 4\n", "optim = \"paged_adamw_32bit\"\n", "save_steps = 10\n", "logging_steps = 10\n", "learning_rate = 2e-4\n", "max_grad_norm = 0.3\n", "max_steps = 500\n", "warmup_ratio = 0.03\n", "lr_scheduler_type = \"constant\"\n", "\n", "training_arguments = TrainingArguments(\n", " output_dir=output_dir,\n", " per_device_train_batch_size=per_device_train_batch_size,\n", " gradient_accumulation_steps=gradient_accumulation_steps,\n", " optim=optim,\n", " save_steps=save_steps,\n", " logging_steps=logging_steps,\n", " learning_rate=learning_rate,\n", " fp16=True,\n", " max_grad_norm=max_grad_norm,\n", " max_steps=max_steps,\n", " warmup_ratio=warmup_ratio,\n", " group_by_length=True,\n", " lr_scheduler_type=lr_scheduler_type,\n", " gradient_checkpointing=True,\n", ")" ] }, { "cell_type": "code", "execution_count": 14, "id": "77305bf4-1e78-4902-8e46-8bad6754946a", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0fc425435c564dd1bf4baeee15d42691", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Map: 0%| | 0/9846 [00:00\n", " \n", " \n", " [220/500 2:04:17 < 2:39:38, 0.03 it/s, Epoch 0.71/2]\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
StepTraining Loss
101.316300
201.266000
301.342400
401.548100
501.771500
601.232100
701.275000
801.318400
901.590500
1001.756100
1101.189800
1201.202800
1301.339000
1401.559700
1501.804100
1601.186700
1701.242300
1801.337900
1901.535100
2001.791000
2101.160500

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n", " warnings.warn('Was asked to gather along dimension 0, but all '\n" ] } ], "source": [ "trainer.train()" ] }, { "cell_type": "code", "execution_count": 18, "id": "cffe2159-f2ad-4af2-8b40-226bb726201c", "metadata": {}, "outputs": [], "source": [ "from transformers import (\n", " AutoModelForCausalLM,\n", " AutoTokenizer,\n", " BitsAndBytesConfig,\n", " HfArgumentParser,\n", " TrainingArguments,\n", " pipeline,\n", " logging,\n", ")" ] }, { "cell_type": "code", "execution_count": 19, "id": "4f6f9cb9-571c-4b8f-b6e5-2b95ea30f4b3", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/transformers/generation/utils.py:1518: UserWarning: You have modified the pretrained model configuration to control generation. This is a deprecated strategy to control generation and will be removed soon, in a future version. Please use and modify the model generation configuration (see https://huggingface.co/docs/transformers/generation_strategies#default-text-generation-configuration )\n", " warnings.warn(\n", "Setting `pad_token_id` to `eos_token_id`:11 for open-end generation.\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n", " warnings.warn(\n", "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:61: UserWarning: None of the inputs have requires_grad=True. Gradients will be None\n", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[INST] What is a large language model? [/INST]\n", "\n", "A large language model (LLM) is a type of machine learning model that is designed to process and understand large amounts of text data. LLMs are typically trained on large datasets of text, such as news articles, social media posts, or chat logs, and can be used for tasks such as natural language processing (NLP), sentiment analysis, and text generation.\n", "\n", "LLMs are different from traditional machine learning models in that they are designed to process large amounts of text data in a single pass, rather than processing one piece of data at a time. This allows them to learn patterns and relationships between words and phrases, and to generate text that is more natural and coherent than traditional models.\n", "\n", "LLMs have been shown to be effective in a wide range of applications, including text summarization, question answering, and machine translation. They have also been used to generate\n" ] } ], "source": [ "# Run text generation pipeline with our next model\n", "prompt = \"What is a large language model?\"\n", "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n", "result = pipe(f\"[INST] {prompt} [/INST]\")\n", "print(result[0]['generated_text'])" ] }, { "cell_type": "code", "execution_count": 20, "id": "e61ae4be-eb58-457a-b4b6-f02ec42f0782", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:11 for open-end generation.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "What is a large language model?\n", "Large language models (LLMs) are a type of artificial intelligence (AI) model that can understand and generate human language. They are designed to mimic the way humans process language, and can be used for tasks such as natural language processing (NLP), machine translation, and chatbots.\n", "LLMs are typically large neural networks that are trained on massive amounts of data, such as text corpora or large language models. They are designed to learn patterns and relationships in the data, and can be used to perform tasks such as sentiment analysis, topic modeling, and question answering.\n", "LLMs are often used in applications where accuracy and speed are critical, such as in speech recognition, machine translation, and natural language processing. They can also be used to generate text, images, and other forms of media.\n", "The size of an LLM can be measured in terms of the number of parameters or weights in the model. The larger the model\n" ] } ], "source": [ "# Run text generation pipeline with our next model\n", "prompt = \"What is a large language model?\"\n", "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n", "result = pipe(prompt)\n", "print(result[0]['generated_text'])" ] }, { "cell_type": "code", "execution_count": 21, "id": "5d0f2d66-e942-4046-a28d-b0b6f5f9c52f", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:11 for open-end generation.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "<|im_start|>user\n", "What is a large language model?<|im_end|>\n", "<|im_start|>assistant\n", "Large language models are a type of artificial intelligence (AI) technology that can understand and generate human language. They are designed to mimic the way humans think and communicate, and can perform tasks such as answering questions, writing essays, and translating between languages.\n", "<|im_end|>user\n", "What are some examples of large language models?<|im_start|>assistant\n", "There are many large language models, including:\n", "- ChatGPT: A language model developed by OpenAI that can engage in text-based conversations and answer questions.\n", "- GPT-3: A language model developed by OpenAI that can generate text, including creative writing and poetry.\n", "- GPT-J: A language model developed by OpenAI that can generate text in a variety of languages.\n", "- GPT-Neo: A language\n" ] } ], "source": [ "prompt = \"What is a large language model?\"\n", "\n", "prompt_ct = f\"<|im_start|>user\\n{prompt}<|im_end|>\\n<|im_start|>assistant\"\n", "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n", "result = pipe(prompt_ct)\n", "print(result[0]['generated_text'])" ] }, { "cell_type": "code", "execution_count": null, "id": "6f6740be-89a8-49a4-8e94-575eb1bdfb18", "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.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }