{ "cells": [ { "cell_type": "markdown", "id": "96318fea-4fd8-430c-849c-f710c5c137fb", "metadata": {}, "source": [ "Orignial Code\n", "\n", "* https://colab.research.google.com/drive/1OQKVceFY_rx4Y74fXlvxyPGAkeyY3Rp9?usp=sharing#scrollTo=QM3wab7on7jH\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "549d6e9d-4c67-4cff-b2e3-d9e8a8c83890", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/ec2-user/SageMaker/Kor-LLM-On-SageMaker/alpaca-lora\n" ] } ], "source": [ "%cd alpaca-lora" ] }, { "cell_type": "code", "execution_count": 1, "id": "5f4a0d0d-fd6b-4b16-ad3b-c81857d6a075", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "fatal: destination path 'alpaca-lora' already exists and is not an empty directory.\n", "/home/ec2-user/SageMaker/Kor-LLM-On-SageMaker/alpaca-lora\n" ] } ], "source": [ "# !git clone -q https://github.com/kairess/alpaca-lora.git\n", "# %cd alpaca-lora\n", "# !pip install -r requirements.txt -q\n", "# !pip uninstall peft -y -q \n", "# !pip install -q git+https://github.com/huggingface/peft.git@e536616888d51b453ed354a6f1e243fecb02ea08" ] }, { "cell_type": "code", "execution_count": 1, "id": "c8236c8f-c89d-4461-99d5-2b123806503a", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "test\n" ] } ], "source": [ "print(\"test\")" ] }, { "cell_type": "code", "execution_count": 9, "id": "9fb20dd2-e6df-4325-ac83-6c3df4731ae4", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "49620" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(dataset)" ] }, { "cell_type": "code", "execution_count": 7, "id": "f2cdc8f5-e7ee-4357-bb50-45442ff9426d", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "[{'instruction': '건강을 유지하기 위한 세 가지 팁을 알려주세요.',\n", " 'input': '',\n", " 'output': '세 가지 팁은 아침식사를 꼭 챙기며, 충분한 수면을 취하고, 적극적으로 운동을 하는 것입니다.'},\n", " {'instruction': '세 가지 기본 색은 무엇인가요?',\n", " 'input': '',\n", " 'output': '기본 색은 빨강, 파랑, 노랑입니다.'},\n", " {'instruction': '원자의 구조를 설명하세요.',\n", " 'input': '',\n", " 'output': '원자는 양성자, 중성자, 전자로 구성되어 있으며, 양성자와 중성자는 원자핵 안에 있고 전자는 주변에 있습니다.'},\n", " {'instruction': '대기 오염을 어떻게 줄일 수 있나요?',\n", " 'input': '',\n", " 'output': '대기 오염을 줄이기 위해 자동차 대신 대중교통을 이용하고, 미세먼지 배출량을 줄이기 위해 차량 정기 검사를 받아야 합니다. 또한 에너지 절약을 위해 전기를 아끼고, 나무를 심어 대기 오염을 줄일 수 있습니다.'},\n", " {'instruction': '어려운 결정을 내려야 했던 때를 설명하세요.',\n", " 'input': '',\n", " 'output': '제가 어려운 결정을 내려야 했던 때는 대학원 졸업 후 직장을 찾아야 했던 때입니다. 다양한 선택지가 있었지만 나의 관심사와 비전에 가장 부합하는 경력을 뽑는데 어려움이 있었습니다. 이 때 여러 사람들의 조언과 현재 상황에 대한 깊은 고민 끝에 적절한 선택을 내리게 되었습니다.'},\n", " {'instruction': '홀수 중 하나를 밝히세요.',\n", " 'input': '트위터, 인스타그램, 텔레그램',\n", " 'output': '텔레그램입니다.'},\n", " {'instruction': '다음 분수가 1/4에 해당하는 이유를 설명하세요.',\n", " 'input': '4/16',\n", " 'output': '분모와 분자를 모두 4로 나눌 수 있기 때문에 1/4에 해당합니다.'},\n", " {'instruction': '중요한 진로 결정을 내려야 하는 주인공의 이야기를 3인칭 내레이션으로 단편 소설을 쓰세요.',\n", " 'input': '',\n", " 'output': '안나는 여러 대학교의 입학 가능성이 있었으나, 제발스러운 직업들을 향해 유혹 당하는 경향이 있어 본인이 가진 진로와 관심사에 맞도록 철저히 검토한 결과, 건축학과를 준비하는 과정에 들어갑니다. 딱 이 시점에서, 안나는 과거의 잘못된 선택 때문에 확고한 결정을 내리기 매우 힘들다는 것에 고통을 겪게 됩니다. 결국, 그녀는 과거로 돌아가 선택을 고쳐보는 것은 불가능하다는 것을 깨닫고 자신의 판단에 근거하여 더 깊이 고민하며 계속 나아가기로 결정합니다.'},\n", " {'instruction': '집의 3D 모델을 렌더링합니다.',\n", " 'input': '',\n", " 'output': '집의 3D 모델링 결과물 입니다. (이미지 첨부)'},\n", " {'instruction': '이 문장에 철자와 문법 오류가 있는지 평가하세요.',\n", " 'input': '그는 식사를 마치고 식당을 나섰습니다.',\n", " 'output': '그 문장에는 철자나 문법에 대한 오류가 없습니다.'}]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "!wget -q https://github.com/Beomi/KoAlpaca/raw/main/ko_alpaca_data.json\n", "\n", "import json\n", "\n", "with open('ko_alpaca_data.json', 'r') as f:\n", " dataset = json.load(f)\n", "\n", "dataset[:10]" ] }, { "cell_type": "code", "execution_count": 3, "id": "7bf7c1d1-492b-4963-b9f4-42809b3265c0", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "\n", "prompt_template = {\n", " \"description\": \"Alpaca-LoRA Custom 템플릿\",\n", " \"prompt_input\": (\n", " \"Below is an instruction that describes a task, paired with an input that provides further context.\\n\"\n", " \"아래는 작업을 설명하는 명령어와 추가적 맥락을 제공하는 입력이 짝을 이루는 예제입니다.\\n\\n\"\n", " \"Write a response that appropriately completes the request.\\n요청을 적절히 완료하는 응답을 작성하세요.\\n\\n\"\n", " \"### Instruction(명령어):\\n{instruction}\\n\\n### Input(입력):\\n{input}\\n\\n### Response:\\n\"\n", " ),\n", " \"prompt_no_input\": (\n", " \"Below is an instruction that describes a task.\\n\"\n", " \"아래는 작업을 설명하는 명령어입니다.\\n\\n\"\n", " \"Write a response that appropriately completes the request.\\n명령어에 따른 요청을 적절히 완료하는 응답을 작성하세요.\\n\\n\"\n", " \"### Instruction(명령어):\\n{instruction}\\n\\n### Response:\\n\"\n", " ),\n", " \"response_split\": \"### Response:\",\n", "}\n", "\n", "with open('templates/custom.json', 'w', encoding='utf-8') as f:\n", " json.dump(prompt_template, f, ensure_ascii=False)" ] }, { "cell_type": "code", "execution_count": 4, "id": "a29d125a-0686-45fb-90cc-2aa7001bde01", "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "===================================BUG REPORT===================================\n", "Welcome to bitsandbytes. For bug reports, please run\n", "\n", "python -m bitsandbytes\n", "\n", " and submit this information together with your error trace to: https://github.com/TimDettmers/bitsandbytes/issues\n", "================================================================================\n", "bin /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda110_nocublaslt.so\n", "/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/bitsandbytes/cuda_setup/main.py:145: UserWarning: /home/ec2-user/anaconda3/envs/python3 did not contain ['libcudart.so', 'libcudart.so.11.0', 'libcudart.so.12.0'] as expected! Searching further paths...\n", " warn(msg)\n", "/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/bitsandbytes/cuda_setup/main.py:145: UserWarning: WARNING: The following directories listed in your path were found to be non-existent: {PosixPath('/opt/amazon/efa/lib')}\n", " warn(msg)\n", "CUDA SETUP: CUDA runtime path found: /usr/local/cuda-11.0/lib64/libcudart.so\n", "CUDA SETUP: Highest compute capability among GPUs detected: 7.0\n", "CUDA SETUP: Detected CUDA version 110\n", "/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/bitsandbytes/cuda_setup/main.py:145: UserWarning: WARNING: Compute capability < 7.5 detected! Only slow 8-bit matmul is supported for your GPU!\n", " warn(msg)\n", "CUDA SETUP: Loading binary /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda110_nocublaslt.so...\n", "Training Alpaca-LoRA model with params:\n", "base_model: decapoda-research/llama-7b-hf\n", "data_path: ko_alpaca_data.json\n", "output_dir: ./output\n", "batch_size: 512\n", "micro_batch_size: 16\n", "num_epochs: 1\n", "learning_rate: 0.0005\n", "cutoff_len: 256\n", "val_set_size: 2000\n", "lora_r: 8\n", "lora_alpha: 16\n", "lora_dropout: 0.05\n", "lora_target_modules: ['q_proj', 'v_proj']\n", "train_on_inputs: True\n", "add_eos_token: False\n", "group_by_length: False\n", "wandb_project: \n", "wandb_run_name: \n", "wandb_watch: \n", "wandb_log_model: \n", "resume_from_checkpoint: False\n", "prompt template: custom\n", "\n", "Downloading (…)lve/main/config.json: 100%|█████| 427/427 [00:00<00:00, 3.05MB/s]\n", "Downloading (…)model.bin.index.json: 100%|██| 25.5k/25.5k [00:00<00:00, 113MB/s]\n", "Downloading shards: 0%| | 0/33 [00:00