inflaton commited on
Commit
1323386
1 Parent(s): 9685567

updated notebooks/00_fine-tune-with-colab.ipynb

Browse files
llama-factory/config/llama3_8b_lora_sft.yaml ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### model
2
+ model_name_or_path: gradientai/Llama-3-8B-Instruct-Gradient-1048k
3
+
4
+ ### method
5
+ stage: sft
6
+ do_train: true
7
+ finetuning_type: lora
8
+ lora_target: all
9
+ quantization_bit: 4 # use 4-bit QLoRA
10
+ loraplus_lr_ratio: 16.0 # use LoRA+ with lambda=16.0
11
+ # use_unsloth: true # use UnslothAI's LoRA optimization for 2x faster training
12
+
13
+ ### dataset
14
+ dataset: alpaca_mac
15
+ template: llama3
16
+ cutoff_len: 1024
17
+ max_samples: 500
18
+ overwrite_cache: true
19
+ preprocessing_num_workers: 16
20
+
21
+ ### output
22
+ # output_dir: saves/llama3-8b/lora/sft
23
+ output_dir: /Workspace/Users/donghao.huang@mastercard.com/lf-saves/llama3-8b/lora/sft/
24
+ logging_steps: 10
25
+ save_steps: 100
26
+ plot_loss: true
27
+ overwrite_output_dir: true
28
+ # resume_from_checkpoint: true
29
+
30
+ ### train
31
+ per_device_train_batch_size: 1
32
+ gradient_accumulation_steps: 8
33
+ learning_rate: 1.0e-4
34
+ num_train_epochs: 6.0
35
+ lr_scheduler_type: cosine
36
+ warmup_ratio: 0.1
37
+ bf16: true
38
+ ddp_timeout: 180000000
39
+
40
+ ### eval
41
+ val_size: 0.01
42
+ per_device_eval_batch_size: 1
43
+ eval_strategy: steps
44
+ eval_steps: 560
45
+
46
+ report_to: none
notebooks/00_fine-tune-with-colab.ipynb CHANGED
@@ -1 +1 @@
1
- {"cells":[{"cell_type":"code","execution_count":1,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{},"inputWidgets":{},"nuid":"0ea8b46b-839b-445b-8043-ccdf4e920ace","showTitle":false,"title":""},"id":"YLH80COBzi_F","executionInfo":{"status":"ok","timestamp":1719461574942,"user_tz":-480,"elapsed":409,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"}}},"outputs":[],"source":["%load_ext autoreload\n","%autoreload 2"]},{"cell_type":"code","source":["from google.colab import drive\n","drive.mount('/content/drive')"],"metadata":{"id":"63B5exAuzq4M","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1719461625346,"user_tz":-480,"elapsed":23887,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"}},"outputId":"1aefabf5-2c1f-4c5c-ad0f-8d1ae01c9a2e"},"execution_count":3,"outputs":[{"output_type":"stream","name":"stdout","text":["Mounted at /content/drive\n"]}]},{"cell_type":"code","source":["workding_dir = \"/content/drive/MyDrive/logical-reasoning/\""],"metadata":{"id":"zFulf0bg0H-9","executionInfo":{"status":"ok","timestamp":1719461634865,"user_tz":-480,"elapsed":368,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"}}},"execution_count":4,"outputs":[]},{"cell_type":"code","execution_count":12,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{},"inputWidgets":{},"nuid":"6d394937-6c99-4a7c-9d32-7600a280032f","showTitle":false,"title":""},"id":"Rzln0ffbzi_H","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1719461838556,"user_tz":-480,"elapsed":464,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"}},"outputId":"afd15981-c0e5-41dc-a35a-10d44c8ec2ef"},"outputs":[{"output_type":"stream","name":"stdout","text":["workding dir: /content/drive/MyDrive/logical-reasoning/\n"]}],"source":["import os\n","import sys\n","from pathlib import Path\n","\n","os.chdir(workding_dir)\n","sys.path.append(workding_dir)\n","print(\"workding dir:\", workding_dir)"]},{"cell_type":"code","source":["%%capture\n","# Installs Unsloth, Xformers (Flash Attention) and all other packages!\n","!pip install \"unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git\"\n","!pip install --no-deps xformers \"trl<0.9.0\" peft accelerate bitsandbytes"],"metadata":{"id":"blBRUfev1ccE","executionInfo":{"status":"ok","timestamp":1719461924756,"user_tz":-480,"elapsed":42986,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"}}},"execution_count":13,"outputs":[]},{"cell_type":"code","source":["%%capture\n","!pip install -r requirements.txt"],"metadata":{"id":"zUqv4IUmU6Yv","executionInfo":{"status":"ok","timestamp":1719462011306,"user_tz":-480,"elapsed":86552,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"}}},"execution_count":14,"outputs":[]},{"cell_type":"code","execution_count":15,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{},"inputWidgets":{},"nuid":"9f67ec60-2f24-411c-84eb-0dd664b44775","showTitle":false,"title":""},"id":"DIUiweYYzi_I","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1719462011879,"user_tz":-480,"elapsed":589,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"}},"outputId":"e16e9247-9077-4b0c-f8ea-17059f05a1c4"},"outputs":[{"output_type":"stream","name":"stdout","text":["loading env vars from: /content/drive/.shortcut-targets-by-id/1E09lTnfbsjtTgQg65dQ3y9D2R6l8waxR/logical-reasoning/.env.example\n"]},{"output_type":"execute_result","data":{"text/plain":["True"]},"metadata":{},"execution_count":15}],"source":["from dotenv import find_dotenv, load_dotenv\n","\n","found_dotenv = find_dotenv(\".env\")\n","\n","if len(found_dotenv) == 0:\n"," found_dotenv = find_dotenv(\".env.example\")\n","print(f\"loading env vars from: {found_dotenv}\")\n","load_dotenv(found_dotenv, override=True)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"4hQO8gkFzi_K","colab":{"base_uri":"https://localhost:8080/"},"outputId":"15a23f01-c8ac-40d3-d005-7717a842186c"},"outputs":[{"output_type":"stream","name":"stdout","text":["Current Directory:\n","/content/drive/.shortcut-targets-by-id/1E09lTnfbsjtTgQg65dQ3y9D2R6l8waxR/logical-reasoning\n","Thu Jun 27 04:24:26 2024 \n","+---------------------------------------------------------------------------------------+\n","| NVIDIA-SMI 535.104.05 Driver Version: 535.104.05 CUDA Version: 12.2 |\n","|-----------------------------------------+----------------------+----------------------+\n","| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n","| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n","| | | MIG M. |\n","|=========================================+======================+======================|\n","| 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 |\n","| N/A 70C P8 10W / 70W | 0MiB / 15360MiB | 0% Default |\n","| | | N/A |\n","+-----------------------------------------+----------------------+----------------------+\n"," \n","+---------------------------------------------------------------------------------------+\n","| Processes: |\n","| GPU GI CI PID Type Process name GPU Memory |\n","| ID ID Usage |\n","|=======================================================================================|\n","| No running processes found |\n","+---------------------------------------------------------------------------------------+\n","Linux 6b69c97a1ffc 6.1.85+ #1 SMP PREEMPT_DYNAMIC Fri May 24 14:06:39 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux\n","PRETTY_NAME=\"Ubuntu 22.04.3 LTS\"\n","NAME=\"Ubuntu\"\n","VERSION_ID=\"22.04\"\n","VERSION=\"22.04.3 LTS (Jammy Jellyfish)\"\n","VERSION_CODENAME=jammy\n","ID=ubuntu\n","ID_LIKE=debian\n","HOME_URL=\"https://www.ubuntu.com/\"\n","SUPPORT_URL=\"https://help.ubuntu.com/\"\n","BUG_REPORT_URL=\"https://bugs.launchpad.net/ubuntu/\"\n","PRIVACY_POLICY_URL=\"https://www.ubuntu.com/legal/terms-and-policies/privacy-policy\"\n","UBUNTU_CODENAME=jammy\n","Architecture: x86_64\n"," CPU op-mode(s): 32-bit, 64-bit\n"," Address sizes: 46 bits physical, 48 bits virtual\n"," Byte Order: Little Endian\n","CPU(s): 2\n"," On-line CPU(s) list: 0,1\n","Vendor ID: GenuineIntel\n"," Model name: Intel(R) Xeon(R) CPU @ 2.20GHz\n"," CPU family: 6\n"," Model: 79\n"," Thread(s) per core: 2\n"," Core(s) per socket: 1\n"," Socket(s): 1\n"," Stepping: 0\n"," BogoMIPS: 4399.99\n"," Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 cl\n"," flush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc re\n"," p_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3\n"," fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand\n"," hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp \n"," fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx sm\n"," ap xsaveopt arat md_clear arch_capabilities\n","Virtualization features: \n"," Hypervisor vendor: KVM\n"," Virtualization type: full\n","Caches (sum of all): \n"," L1d: 32 KiB (1 instance)\n"," L1i: 32 KiB (1 instance)\n"," L2: 256 KiB (1 instance)\n"," L3: 55 MiB (1 instance)\n","NUMA: \n"," NUMA node(s): 1\n"," NUMA node0 CPU(s): 0,1\n","Vulnerabilities: \n"," Gather data sampling: Not affected\n"," Itlb multihit: Not affected\n"," L1tf: Mitigation; PTE Inversion\n"," Mds: Vulnerable; SMT Host state unknown\n"," Meltdown: Vulnerable\n"," Mmio stale data: Vulnerable\n"," Reg file data sampling: Not affected\n"," Retbleed: Vulnerable\n"," Spec rstack overflow: Not affected\n"," Spec store bypass: Vulnerable\n"," Spectre v1: Vulnerable: __user pointer sanitization and usercopy barriers only; no swa\n"," pgs barriers\n"," Spectre v2: Vulnerable; IBPB: disabled; STIBP: disabled; PBRSB-eIBRS: Not affected; BH\n"," I: Vulnerable (Syscall hardening enabled)\n"," Srbds: Not affected\n"," Tsx async abort: Vulnerable\n","MemTotal: 13290460 kB\n","Evaluating unsloth/Qwen2-0.5B-Instruct\n","loading env vars from: /content/drive/.shortcut-targets-by-id/1E09lTnfbsjtTgQg65dQ3y9D2R6l8waxR/logical-reasoning/.env.example\n","Adding /content/drive/.shortcut-targets-by-id/1E09lTnfbsjtTgQg65dQ3y9D2R6l8waxR/logical-reasoning to sys.path\n","🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.\n","2024-06-27 04:24:32.329265: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n","2024-06-27 04:24:32.329314: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n","2024-06-27 04:24:32.330767: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n","2024-06-27 04:24:32.338138: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n","To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n","2024-06-27 04:24:33.393488: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n","[nltk_data] Downloading package wordnet to /root/nltk_data...\n","[nltk_data] Package wordnet is already up-to-date!\n","[nltk_data] Downloading package punkt to /root/nltk_data...\n","[nltk_data] Package punkt is already up-to-date!\n","[nltk_data] Downloading package omw-1.4 to /root/nltk_data...\n","[nltk_data] Package omw-1.4 is already up-to-date!\n","loading /content/drive/.shortcut-targets-by-id/1E09lTnfbsjtTgQg65dQ3y9D2R6l8waxR/logical-reasoning/llm_toolkit/translation_engine.py\n","unsloth/Qwen2-0.5B-Instruct True 2048 10 None datasets/mac/mac.tsv results/mac-results-colab.csv True False False False\n","(1) GPU = Tesla T4. Max memory = 14.748 GB.\n","0.0 GB of memory reserved.\n","loading model: unsloth/Qwen2-0.5B-Instruct\n","config.json: 100% 1.19k/1.19k [00:00<00:00, 5.05MB/s]\n","==((====))== Unsloth: Fast Qwen2 patching release 2024.6\n"," \\\\ /| GPU: Tesla T4. Max memory: 14.748 GB. Platform = Linux.\n","O^O/ \\_/ \\ Pytorch: 2.3.0+cu121. CUDA = 7.5. CUDA Toolkit = 12.1.\n","\\ / Bfloat16 = FALSE. Xformers = 0.0.26.post1. FA = False.\n"," \"-____-\" Free Apache license: http://github.com/unslothai/unsloth\n","model.safetensors: 100% 457M/457M [00:01<00:00, 266MB/s]\n","generation_config.json: 100% 242/242 [00:00<00:00, 1.97MB/s]\n","Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n","Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n","(2) GPU = Tesla T4. Max memory = 14.748 GB.\n","0.633 GB of memory reserved.\n","loading train/test data files\n","Map: 100% 4528/4528 [00:00<00:00, 13797.27 examples/s]\n","Map: 100% 1133/1133 [00:00<00:00, 14515.11 examples/s]\n","DatasetDict({\n"," train: Dataset({\n"," features: ['chinese', 'english', 'text', 'prompt'],\n"," num_rows: 4528\n"," })\n"," test: Dataset({\n"," features: ['chinese', 'english', 'text', 'prompt'],\n"," num_rows: 1133\n"," })\n","})\n","Evaluating base model: unsloth/Qwen2-0.5B-Instruct\n"," 0% 0/1133 [00:00<?, ?it/s]--------\n","step 1: I am a Senior Officer with the 15th Army Corps stationed in the capital city of the Republic of China. I have served under the leadership of General Chiang Kai-shek for over forty years and am now serving as a Senior Officer in the army. I am known by my colleagues as \"The Man from the South\".<|im_end|>\n","--------\n","step 2: I am a Senior Officer with the 15th Army Corps stationed in the capital city of the Republic of China. I have served under the leadership of General Chiang Kai-shek for over forty years and am now serving as a Senior Officer in the army. I am known by my colleagues as \"The Man from the South\".\n","--------\n","step 3: I am a Senior Officer with the 15th Army Corps stationed in the capital city of the Republic of China. I have served under the leadership of General Chiang Kai-shek for over forty years and am now serving as a Senior Officer in the army. I am known by my colleagues as \"The Man from the South\".\n"," 3% 29/1133 [01:40<40:33, 2.20s/it]"]}],"source":["%%time\n","\n","!chmod +x ./scripts/eval-mac.sh\n","!./scripts/eval-mac.sh unsloth/Qwen2-0.5B-Instruct"]}],"metadata":{"accelerator":"GPU","application/vnd.databricks.v1+notebook":{"dashboards":[],"environmentMetadata":null,"language":"python","notebookMetadata":{"pythonIndentUnit":4},"notebookName":"07_MAC_+_Qwen2-7B-Instructi_Unsloth_train","widgets":{}},"colab":{"gpuType":"T4","provenance":[]},"kernelspec":{"display_name":"Python 3","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.14"}},"nbformat":4,"nbformat_minor":0}
 
1
+ {"cells":[{"cell_type":"code","execution_count":null,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{},"inputWidgets":{},"nuid":"0ea8b46b-839b-445b-8043-ccdf4e920ace","showTitle":false,"title":""},"executionInfo":{"elapsed":409,"status":"ok","timestamp":1719461574942,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"},"user_tz":-480},"id":"YLH80COBzi_F"},"outputs":[],"source":["%load_ext autoreload\n","%autoreload 2"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":23887,"status":"ok","timestamp":1719461625346,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"},"user_tz":-480},"id":"63B5exAuzq4M","outputId":"1aefabf5-2c1f-4c5c-ad0f-8d1ae01c9a2e"},"outputs":[],"source":["from google.colab import drive\n","drive.mount('/content/drive')"]},{"cell_type":"code","execution_count":null,"metadata":{"executionInfo":{"elapsed":368,"status":"ok","timestamp":1719461634865,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"},"user_tz":-480},"id":"zFulf0bg0H-9"},"outputs":[],"source":["workding_dir = \"/content/drive/MyDrive/logical-reasoning/\""]},{"cell_type":"code","execution_count":null,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{},"inputWidgets":{},"nuid":"6d394937-6c99-4a7c-9d32-7600a280032f","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":464,"status":"ok","timestamp":1719461838556,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"},"user_tz":-480},"id":"Rzln0ffbzi_H","outputId":"afd15981-c0e5-41dc-a35a-10d44c8ec2ef"},"outputs":[],"source":["import os\n","import sys\n","from pathlib import Path\n","\n","os.chdir(workding_dir)\n","sys.path.append(workding_dir)\n","print(\"workding dir:\", workding_dir)"]},{"cell_type":"code","execution_count":null,"metadata":{"executionInfo":{"elapsed":42986,"status":"ok","timestamp":1719461924756,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"},"user_tz":-480},"id":"blBRUfev1ccE"},"outputs":[],"source":["%%capture\n","# Installs Unsloth, Xformers (Flash Attention) and all other packages!\n","!pip install \"unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git\"\n","!pip install --no-deps xformers \"trl<0.9.0\" peft accelerate bitsandbytes"]},{"cell_type":"code","execution_count":null,"metadata":{"executionInfo":{"elapsed":86552,"status":"ok","timestamp":1719462011306,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"},"user_tz":-480},"id":"zUqv4IUmU6Yv"},"outputs":[],"source":["%%capture\n","!pip install -r requirements.txt"]},{"cell_type":"code","execution_count":null,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{},"inputWidgets":{},"nuid":"9f67ec60-2f24-411c-84eb-0dd664b44775","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":589,"status":"ok","timestamp":1719462011879,"user":{"displayName":"Donghao Huang","userId":"00463591218503521679"},"user_tz":-480},"id":"DIUiweYYzi_I","outputId":"e16e9247-9077-4b0c-f8ea-17059f05a1c4"},"outputs":[],"source":["from dotenv import find_dotenv, load_dotenv\n","\n","found_dotenv = find_dotenv(\".env\")\n","\n","if len(found_dotenv) == 0:\n"," found_dotenv = find_dotenv(\".env.example\")\n","print(f\"loading env vars from: {found_dotenv}\")\n","load_dotenv(found_dotenv, override=True)"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"4hQO8gkFzi_K","outputId":"15a23f01-c8ac-40d3-d005-7717a842186c"},"outputs":[],"source":["%%time\n","!python --version\n","!pip show flash-attn"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["%%time\n","\n","!./scripts/tune-lf.sh config/llama3_8b_lora_sft.yaml"]}],"metadata":{"accelerator":"GPU","application/vnd.databricks.v1+notebook":{"dashboards":[],"environmentMetadata":null,"language":"python","notebookMetadata":{"pythonIndentUnit":4},"notebookName":"07_MAC_+_Qwen2-7B-Instructi_Unsloth_train","widgets":{}},"colab":{"gpuType":"T4","provenance":[]},"kernelspec":{"display_name":"Python 3","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.14"}},"nbformat":4,"nbformat_minor":0}
novel-translation/09_tune-lf-medium-py3.11.ipynb ADDED
The diff for this file is too large to render. See raw diff