{"cells":[{"cell_type":"code","source":["%load_ext autoreload\n","%autoreload 2"],"metadata":{"id":"uWKRSV6eZsCn","executionInfo":{"status":"ok","timestamp":1720679526275,"user_tz":-480,"elapsed":476,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"}}},"execution_count":1,"outputs":[]},{"cell_type":"code","execution_count":2,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"eb33b19f-1206-41ee-84e2-e6258a12eef7","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"id":"xwFh14uiZBrI","executionInfo":{"status":"ok","timestamp":1720679529344,"user_tz":-480,"elapsed":2534,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"}},"outputId":"d767799c-34c2-46a5-f052-378146a55321"},"outputs":[{"output_type":"stream","name":"stdout","text":["Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n"]}],"source":["from google.colab import drive\n","drive.mount('/content/drive')"]},{"cell_type":"code","execution_count":3,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"6d394937-6c99-4a7c-9d32-7600a280032f","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"id":"G5pNu3zgZBrL","executionInfo":{"status":"ok","timestamp":1720679529345,"user_tz":-480,"elapsed":5,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"}},"outputId":"160a554f-fb08-4aa0-bc00-0422fb7c1fac"},"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","workding_dir = \"/content/drive/MyDrive/logical-reasoning/\"\n","os.chdir(workding_dir)\n","sys.path.append(workding_dir)\n","print(\"workding dir:\", workding_dir)"]},{"cell_type":"code","execution_count":4,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"ac667aba-076e-4de6-9984-8f6a67cb09cd","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"id":"0dVRAabNZBrL","executionInfo":{"status":"ok","timestamp":1720679529345,"user_tz":-480,"elapsed":4,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"}},"outputId":"b977e116-df16-47cd-9160-a24f611da687"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["False"]},"metadata":{},"execution_count":4}],"source":["need_to_setup_env = False\n","need_to_setup_env"]},{"cell_type":"code","execution_count":5,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"72f9cf79-7b0d-4d9e-90a0-1fa5251b947f","showTitle":false,"title":""},"id":"hKUOfP2HZBrL","executionInfo":{"status":"ok","timestamp":1720679529345,"user_tz":-480,"elapsed":4,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"}}},"outputs":[],"source":["if need_to_setup_env:\n"," %pip install -r requirements.txt\n"," %cd /content/\n"," %rm -rf LLaMA-Factory\n"," !git clone https://github.com/hiyouga/LLaMA-Factory.git\n"," %cd LLaMA-Factory\n"," %ls\n"," %pip install -e .[torch,bitsandbytes]"]},{"cell_type":"code","execution_count":6,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"c06c61fd-4c6f-4099-bd3b-46188ab835d7","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"id":"txOgnjwYZBrL","executionInfo":{"status":"ok","timestamp":1720679529345,"user_tz":-480,"elapsed":4,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"}},"outputId":"c10df404-fcbf-47bc-8344-637240adb6a2"},"outputs":[{"output_type":"stream","name":"stdout","text":["workding dir: /content/drive/MyDrive/logical-reasoning/\n"]}],"source":["os.chdir(workding_dir)\n","sys.path.append(workding_dir)\n","print(\"workding dir:\", workding_dir)"]},{"cell_type":"code","execution_count":7,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"9f67ec60-2f24-411c-84eb-0dd664b44775","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"id":"hPCC-6m7ZBrM","executionInfo":{"status":"ok","timestamp":1720679529345,"user_tz":-480,"elapsed":3,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"}},"outputId":"c7aa2c96-5e99-440a-c148-201d79465ff9"},"outputs":[{"output_type":"stream","name":"stdout","text":["loading env vars from: /content/drive/MyDrive/logical-reasoning/.env\n"]},{"output_type":"execute_result","data":{"text/plain":["True"]},"metadata":{},"execution_count":7}],"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":8,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"f1597656-8042-4878-9d3b-9ebfb8dd86dc","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"id":"1M3IraVtZBrM","executionInfo":{"status":"ok","timestamp":1720679529345,"user_tz":-480,"elapsed":3,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"}},"outputId":"29ab35f6-2970-4ade-d85d-3174acf8cda0"},"outputs":[{"output_type":"stream","name":"stdout","text":["Qwen2/Qwen2-7B-Instruct None True datasets/mgtv results/mgtv-results_colab_p1.csv\n"]}],"source":["import os\n","\n","model_name = os.getenv(\"MODEL_NAME\")\n","adapter_name_or_path = os.getenv(\"ADAPTER_NAME_OR_PATH\")\n","load_in_4bit = os.getenv(\"LOAD_IN_4BIT\") == \"true\"\n","data_path = os.getenv(\"LOGICAL_REASONING_DATA_PATH\")\n","results_path = os.getenv(\"LOGICAL_REASONING_RESULTS_PATH\")\n","use_english_datasets = os.getenv(\"USE_ENGLISH_DATASETS\") == \"true\"\n","\n","print(model_name, adapter_name_or_path, load_in_4bit, data_path, results_path)"]},{"cell_type":"code","execution_count":9,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"e3ab54ba-7b6d-4817-bf2e-c5d711508b58","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"id":"mrVEz6UsZBrM","executionInfo":{"status":"ok","timestamp":1720679529345,"user_tz":-480,"elapsed":2,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"}},"outputId":"8bcff769-2573-4dae-e124-d5b5d2382d71"},"outputs":[{"output_type":"stream","name":"stdout","text":["Thu Jul 11 06:32:08 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 NVIDIA L4 Off | 00000000:00:03.0 Off | 0 |\n","| N/A 55C P8 17W / 72W | 1MiB / 23034MiB | 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"]}],"source":["!nvidia-smi"]},{"cell_type":"code","execution_count":10,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"b2a43943-9324-4839-9a47-cfa72de2244b","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"id":"UgMvt6dIZBrM","executionInfo":{"status":"ok","timestamp":1720679529907,"user_tz":-480,"elapsed":564,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"}},"outputId":"ce37581c-fd26-46c2-ad87-d933d99f68f7"},"outputs":[{"output_type":"stream","name":"stdout","text":["Python 3.10.12\n","\u001b[33mWARNING: Package(s) not found: flash-attn\u001b[0m\u001b[33m\n","\u001b[0mCPU times: user 11 ms, sys: 1.41 ms, total: 12.4 ms\n","Wall time: 609 ms\n"]}],"source":["%%time\n","!python --version\n","!pip show flash-attn"]},{"cell_type":"code","execution_count":11,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"ZuS_FsLyZBrN","executionInfo":{"status":"ok","timestamp":1720679531591,"user_tz":-480,"elapsed":1685,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"}},"outputId":"2cba0105-c505-4395-afbd-2f2fee6581d0"},"outputs":[{"output_type":"stream","name":"stdout","text":["loading /content/drive/MyDrive/logical-reasoning/llm_toolkit/logical_reasoning_utils.py\n"]}],"source":["from llm_toolkit.logical_reasoning_utils import *"]},{"cell_type":"code","execution_count":12,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":311},"id":"muFDE9DpZBrN","executionInfo":{"status":"ok","timestamp":1720679532304,"user_tz":-480,"elapsed":715,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"}},"outputId":"95672b22-99b7-41b7-f992-18b193994f66"},"outputs":[{"output_type":"stream","name":"stdout","text":["loading existing data from: llama-factory/data/alpaca_mgtv_p1.json\n"]},{"output_type":"execute_result","data":{"text/plain":[" instruction input output\n","0 你是一个逻辑游戏的主持人。游戏规则如下:\\n\\n1. 参与者会得到一个谜题。\\n2. 参与者... 不是\n","1 你是一个逻辑游戏的主持人。游戏规则如下:\\n\\n1. 参与者会得到一个谜题。\\n2. 参与者... 不是\n","2 你是一个逻辑游戏的主持人。游戏规则如下:\\n\\n1. 参与者会得到一个谜题。\\n2. 参与者... 不重要\n","3 你是一个逻辑游戏的主持人。游戏规则如下:\\n\\n1. 参与者会得到一个谜题。\\n2. 参与者... 不是\n","4 你是一个逻辑游戏的主持人。游戏规则如下:\\n\\n1. 参与者会得到一个谜题。\\n2. 参与者... 是"],"text/html":["\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","
instructioninputoutput
0你是一个逻辑游戏的主持人。游戏规则如下:\\n\\n1. 参与者会得到一个谜题。\\n2. 参与者...不是
1你是一个逻辑游戏的主持人。游戏规则如下:\\n\\n1. 参与者会得到一个谜题。\\n2. 参与者...不是
2你是一个逻辑游戏的主持人。游戏规则如下:\\n\\n1. 参与者会得到一个谜题。\\n2. 参与者...不重要
3你是一个逻辑游戏的主持人。游戏规则如下:\\n\\n1. 参与者会得到一个谜题。\\n2. 参与者...不是
4你是一个逻辑游戏的主持人。游戏规则如下:\\n\\n1. 参与者会得到一个谜题。\\n2. 参与者...
\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"df_alpaca","summary":"{\n \"name\": \"df_alpaca\",\n \"rows\": 25000,\n \"fields\": [\n {\n \"column\": \"instruction\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 20112,\n \"samples\": [\n \"\\u4f60\\u662f\\u4e00\\u4e2a\\u903b\\u8f91\\u6e38\\u620f\\u7684\\u4e3b\\u6301\\u4eba\\u3002\\u6e38\\u620f\\u89c4\\u5219\\u5982\\u4e0b\\uff1a\\n\\n1. \\u53c2\\u4e0e\\u8005\\u4f1a\\u5f97\\u5230\\u4e00\\u4e2a\\u8c1c\\u9898\\u3002\\n2. \\u53c2\\u4e0e\\u8005\\u53ef\\u4ee5\\u901a\\u8fc7\\u63d0\\u95ee\\u6765\\u83b7\\u53d6\\u7ebf\\u7d22\\uff0c\\u5c1d\\u8bd5\\u89e3\\u5f00\\u8c1c\\u9898\\u3002\\n3. \\u5bf9\\u4e8e\\u6bcf\\u4e2a\\u95ee\\u9898\\uff0c\\u4e3b\\u6301\\u4eba\\u5c06\\u6839\\u636e\\u5b9e\\u9645\\u60c5\\u51b5\\u56de\\u7b54\\u4ee5\\u4e0b\\u4e94\\u4e2a\\u9009\\u9879\\u4e4b\\u4e00\\uff1a\\u662f\\u3001\\u4e0d\\u662f\\u3001\\u4e0d\\u91cd\\u8981\\u3001\\u56de\\u7b54\\u6b63\\u786e\\u3001\\u95ee\\u6cd5\\u9519\\u8bef\\u3002\\n4. \\u56de\\u7b54\\u4e2d\\u4e0d\\u80fd\\u6dfb\\u52a0\\u4efb\\u4f55\\u5176\\u5b83\\u4fe1\\u606f\\uff0c\\u4e5f\\u4e0d\\u80fd\\u7701\\u7565\\u9009\\u9879\\u4e2d\\u7684\\u4efb\\u4f55\\u4e00\\u4e2a\\u5b57\\u3002\\u4f8b\\u5982\\uff0c\\u4e0d\\u53ef\\u4ee5\\u628a\\u201c\\u4e0d\\u662f\\u201d\\u7701\\u7565\\u6210\\u201c\\u4e0d\\u201d\\u3002\\n5. \\u53c2\\u4e0e\\u8005\\u9700\\u8981\\u6839\\u636e\\u56de\\u7b54\\u6765\\u63a8\\u7406\\uff0c\\u5e76\\u6700\\u7ec8\\u627e\\u51fa\\u8c1c\\u9898\\u7684\\u6b63\\u786e\\u7b54\\u6848\\u3002\\n\\n\\u8bf7\\u4e25\\u683c\\u6309\\u7167\\u8fd9\\u4e9b\\u89c4\\u5219\\u56de\\u7b54\\u53c2\\u4e0e\\u8005\\u63d0\\u51fa\\u7684\\u95ee\\u9898\\u3002\\n\\n\\u8c1c\\u9898: \\u5728\\u4e00\\u680b\\u8001\\u65e7\\u5c45\\u6c11\\u697c\\u7684\\u5730\\u4e0b\\u5ba4\\u3002\\u4e00\\u5929\\uff0c\\u8b66\\u65b9\\u63a5\\u5230\\u62a5\\u6848\\uff0c\\u6709\\u4eba\\u5728\\u5730\\u4e0b\\u5ba4\\u4e2d\\u53d1\\u73b0\\u4e86\\u7504\\u597d\\u5947\\u7684\\u9057\\u4f53\\u3002\\u73b0\\u573a\\u6ca1\\u6709\\u6253\\u6597\\u7684\\u75d5\\u8ff9\\uff0c\\u4e5f\\u6ca1\\u6709\\u660e\\u663e\\u7684\\u81ea\\u6740\\u5de5\\u5177\\u3002\\u6b7b\\u8005\\u88ab\\u53d1\\u73b0\\u65f6\\u5750\\u5728\\u4e00\\u628a\\u6905\\u5b50\\u4e0a\\uff0c\\u8868\\u60c5\\u5e73\\u9759\\uff0c\\u4f3c\\u4e4e\\u5728\\u6b7b\\u524d\\u5e76\\u672a\\u7ecf\\u5386\\u75db\\u82e6\\u3002\\u5730\\u4e0b\\u5ba4\\u9664\\u4e86\\u4e00\\u53f0\\u7535\\u89c6\\u548c\\u4e00\\u5f20\\u684c\\u5b50\\u5916\\uff0c\\u6ca1\\u6709\\u5176\\u4ed6\\u7269\\u54c1\\u3002\\u684c\\u4e0a\\u6709\\u4e00\\u676f\\u6c34\\uff0c\\u7535\\u89c6\\u8fd8\\u5f00\\u7740\\u3002\\u7a76\\u7adf\\u662f\\u4ec0\\u4e48\\u539f\\u56e0\\u5bfc\\u81f4\\u4e86\\u7504\\u597d\\u5947\\u7684\\u6b7b\\u4ea1\\uff1f\\n\\n\\u5b9e\\u9645\\u60c5\\u51b5: \\u7504\\u597d\\u5947\\u5176\\u5b9e\\u662f\\u4e00\\u4f4d\\u79d1\\u5e7b\\u5c0f\\u8bf4\\u4f5c\\u5bb6\\uff0c\\u60a3\\u6709\\u4e25\\u91cd\\u7684\\u5e7d\\u95ed\\u6050\\u60e7\\u75c7\\u3002\\u4ed6\\u4e3a\\u4e86\\u5bfb\\u627e\\u5199\\u4f5c\\u7684\\u7075\\u611f\\uff0c\\u5e38\\u5e38\\u72ec\\u81ea\\u4e00\\u4eba\\u6765\\u5230\\u8fd9\\u4e2a\\u5730\\u4e0b\\u5ba4\\u89c2\\u770b\\u79d1\\u5e7b\\u7535\\u5f71\\u3002\\u4e0d\\u5e78\\u7684\\u662f\\uff0c\\u6709\\u4e00\\u5929\\u4ed6\\u5728\\u89c2\\u770b\\u7535\\u5f71\\u65f6\\u7a81\\u7136\\u906d\\u9047\\u505c\\u7535\\uff0c\\u5730\\u4e0b\\u5ba4\\u4e00\\u7247\\u6f06\\u9ed1\\u3002\\u4ed6\\u7684\\u5e7d\\u95ed\\u6050\\u60e7\\u75c7\\u53d1\\u4f5c\\uff0c\\u6781\\u5ea6\\u6050\\u614c\\u4e2d\\u8bef\\u4ee5\\u4e3a\\u81ea\\u5df1\\u88ab\\u56f0\\u5728\\u4e00\\u4e2a\\u672a\\u77e5\\u7684\\u5b87\\u5b99\\u7a7a\\u95f4\\u3002\\u5728\\u8fd9\\u79cd\\u6781\\u7aef\\u6050\\u60e7\\u7684\\u72b6\\u6001\\u4e0b\\uff0c\\u4ed6\\u7a81\\u53d1\\u5fc3\\u810f\\u75c5\\uff0c\\u5e73\\u9759\\u5730\\u79bb\\u5f00\\u4e86\\u4eba\\u4e16\\u3002\\u7531\\u4e8e\\u5fc3\\u810f\\u75c5\\u53d1\\u4f5c\\u65f6\\u6ca1\\u6709\\u75db\\u82e6\\uff0c\\u6240\\u4ee5\\u4ed6\\u7684\\u8868\\u60c5\\u770b\\u8d77\\u6765\\u5f88\\u5e73\\u9759\\u3002\\u800c\\u684c\\u4e0a\\u7684\\u6c34\\u548c\\u5f00\\u7740\\u7684\\u7535\\u89c6\\uff0c\\u53ea\\u662f\\u4ed6\\u65e5\\u5e38\\u5728\\u5730\\u4e0b\\u5ba4\\u5199\\u4f5c\\u65f6\\u7684\\u4e60\\u60ef\\u3002\\n\\n\\u53c2\\u4e0e\\u8005\\u63d0\\u51fa\\u7684\\u95ee\\u9898: \\u6c34\\u6709\\u6bd2\\n\",\n \"\\u4f60\\u662f\\u4e00\\u4e2a\\u903b\\u8f91\\u6e38\\u620f\\u7684\\u4e3b\\u6301\\u4eba\\u3002\\u6e38\\u620f\\u89c4\\u5219\\u5982\\u4e0b\\uff1a\\n\\n1. \\u53c2\\u4e0e\\u8005\\u4f1a\\u5f97\\u5230\\u4e00\\u4e2a\\u8c1c\\u9898\\u3002\\n2. \\u53c2\\u4e0e\\u8005\\u53ef\\u4ee5\\u901a\\u8fc7\\u63d0\\u95ee\\u6765\\u83b7\\u53d6\\u7ebf\\u7d22\\uff0c\\u5c1d\\u8bd5\\u89e3\\u5f00\\u8c1c\\u9898\\u3002\\n3. \\u5bf9\\u4e8e\\u6bcf\\u4e2a\\u95ee\\u9898\\uff0c\\u4e3b\\u6301\\u4eba\\u5c06\\u6839\\u636e\\u5b9e\\u9645\\u60c5\\u51b5\\u56de\\u7b54\\u4ee5\\u4e0b\\u4e94\\u4e2a\\u9009\\u9879\\u4e4b\\u4e00\\uff1a\\u662f\\u3001\\u4e0d\\u662f\\u3001\\u4e0d\\u91cd\\u8981\\u3001\\u56de\\u7b54\\u6b63\\u786e\\u3001\\u95ee\\u6cd5\\u9519\\u8bef\\u3002\\n4. \\u56de\\u7b54\\u4e2d\\u4e0d\\u80fd\\u6dfb\\u52a0\\u4efb\\u4f55\\u5176\\u5b83\\u4fe1\\u606f\\uff0c\\u4e5f\\u4e0d\\u80fd\\u7701\\u7565\\u9009\\u9879\\u4e2d\\u7684\\u4efb\\u4f55\\u4e00\\u4e2a\\u5b57\\u3002\\u4f8b\\u5982\\uff0c\\u4e0d\\u53ef\\u4ee5\\u628a\\u201c\\u4e0d\\u662f\\u201d\\u7701\\u7565\\u6210\\u201c\\u4e0d\\u201d\\u3002\\n5. \\u53c2\\u4e0e\\u8005\\u9700\\u8981\\u6839\\u636e\\u56de\\u7b54\\u6765\\u63a8\\u7406\\uff0c\\u5e76\\u6700\\u7ec8\\u627e\\u51fa\\u8c1c\\u9898\\u7684\\u6b63\\u786e\\u7b54\\u6848\\u3002\\n\\n\\u8bf7\\u4e25\\u683c\\u6309\\u7167\\u8fd9\\u4e9b\\u89c4\\u5219\\u56de\\u7b54\\u53c2\\u4e0e\\u8005\\u63d0\\u51fa\\u7684\\u95ee\\u9898\\u3002\\n\\n\\u8c1c\\u9898: \\u5728\\u4e00\\u4e2a\\u5bc2\\u9759\\u7684\\u591c\\u665a\\uff0c\\u7504\\u8d3e\\u8d3e\\u5306\\u5306\\u5fd9\\u5fd9\\u5730\\u4ece\\u5c0f\\u5df7\\u5b50\\u91cc\\u8dd1\\u4e86\\u51fa\\u6765\\uff0c\\u8138\\u4e0a\\u6ee1\\u662f\\u60ca\\u6050\\u3002\\u5728\\u4ed6\\u8eab\\u540e\\uff0c\\u4e00\\u53ea\\u7a7a\\u8361\\u8361\\u7684\\u5783\\u573e\\u6876\\u7ffb\\u5012\\u5728\\u5730\\u3002\\u7504\\u8d3e\\u8d3e\\u5e76\\u975e\\u5c0f\\u5df7\\u91cc\\u7684\\u5c45\\u6c11\\uff0c\\u4e5f\\u6ca1\\u6709\\u4e0e\\u4eba\\u7ed3\\u6028\\u3002\\u7a76\\u7adf\\u662f\\u4ec0\\u4e48\\u539f\\u56e0\\u8ba9\\u4ed6\\u5982\\u6b64\\u60ca\\u614c\\u5931\\u63aa\\uff1f\\n\\n\\u5b9e\\u9645\\u60c5\\u51b5: \\u539f\\u6765\\uff0c\\u7504\\u8d3e\\u8d3e\\u662f\\u4e00\\u540d\\u6b63\\u5728\\u6f5c\\u9003\\u7684\\u5c0f\\u5077\\u3002\\u5f53\\u665a\\uff0c\\u4ed6\\u4f01\\u56fe\\u5728\\u5df7\\u5b50\\u91cc\\u5bfb\\u627e\\u53ef\\u4ee5\\u76d7\\u7a83\\u7684\\u76ee\\u6807\\uff0c\\u5374\\u4e0d\\u6599\\u5783\\u573e\\u6876\\u91cc\\u7a81\\u7136\\u7a9c\\u51fa\\u4e00\\u53ea\\u91ce\\u732b\\uff0c\\u5c06\\u4ed6\\u5413\\u4e86\\u4e00\\u8df3\\u3002\\u4ed6\\u4ee5\\u4e3a\\u662f\\u88ab\\u8b66\\u65b9\\u53d1\\u73b0\\u4e86\\uff0c\\u4e8e\\u662f\\u60ca\\u614c\\u5931\\u63aa\\u5730\\u9003\\u8dd1\\u4e86\\u3002\\u800c\\u90a3\\u53ea\\u5783\\u573e\\u6876\\uff0c\\u6b63\\u662f\\u4ed6\\u7ffb\\u627e\\u4e1c\\u897f\\u65f6\\u4e0d\\u5c0f\\u5fc3\\u5f04\\u7ffb\\u7684\\u3002\\n\\n\\u53c2\\u4e0e\\u8005\\u63d0\\u51fa\\u7684\\u95ee\\u9898: \\u4ed6\\u770b\\u5230\\u4e86\\u4e0d\\u8be5\\u770b\\u7684\\u4e1c\\u897f\\u5417\\n\",\n \"\\u4f60\\u662f\\u4e00\\u4e2a\\u903b\\u8f91\\u6e38\\u620f\\u7684\\u4e3b\\u6301\\u4eba\\u3002\\u6e38\\u620f\\u89c4\\u5219\\u5982\\u4e0b\\uff1a\\n\\n1. \\u53c2\\u4e0e\\u8005\\u4f1a\\u5f97\\u5230\\u4e00\\u4e2a\\u8c1c\\u9898\\u3002\\n2. \\u53c2\\u4e0e\\u8005\\u53ef\\u4ee5\\u901a\\u8fc7\\u63d0\\u95ee\\u6765\\u83b7\\u53d6\\u7ebf\\u7d22\\uff0c\\u5c1d\\u8bd5\\u89e3\\u5f00\\u8c1c\\u9898\\u3002\\n3. \\u5bf9\\u4e8e\\u6bcf\\u4e2a\\u95ee\\u9898\\uff0c\\u4e3b\\u6301\\u4eba\\u5c06\\u6839\\u636e\\u5b9e\\u9645\\u60c5\\u51b5\\u56de\\u7b54\\u4ee5\\u4e0b\\u4e94\\u4e2a\\u9009\\u9879\\u4e4b\\u4e00\\uff1a\\u662f\\u3001\\u4e0d\\u662f\\u3001\\u4e0d\\u91cd\\u8981\\u3001\\u56de\\u7b54\\u6b63\\u786e\\u3001\\u95ee\\u6cd5\\u9519\\u8bef\\u3002\\n4. \\u56de\\u7b54\\u4e2d\\u4e0d\\u80fd\\u6dfb\\u52a0\\u4efb\\u4f55\\u5176\\u5b83\\u4fe1\\u606f\\uff0c\\u4e5f\\u4e0d\\u80fd\\u7701\\u7565\\u9009\\u9879\\u4e2d\\u7684\\u4efb\\u4f55\\u4e00\\u4e2a\\u5b57\\u3002\\u4f8b\\u5982\\uff0c\\u4e0d\\u53ef\\u4ee5\\u628a\\u201c\\u4e0d\\u662f\\u201d\\u7701\\u7565\\u6210\\u201c\\u4e0d\\u201d\\u3002\\n5. \\u53c2\\u4e0e\\u8005\\u9700\\u8981\\u6839\\u636e\\u56de\\u7b54\\u6765\\u63a8\\u7406\\uff0c\\u5e76\\u6700\\u7ec8\\u627e\\u51fa\\u8c1c\\u9898\\u7684\\u6b63\\u786e\\u7b54\\u6848\\u3002\\n\\n\\u8bf7\\u4e25\\u683c\\u6309\\u7167\\u8fd9\\u4e9b\\u89c4\\u5219\\u56de\\u7b54\\u53c2\\u4e0e\\u8005\\u63d0\\u51fa\\u7684\\u95ee\\u9898\\u3002\\n\\n\\u8c1c\\u9898: \\u5728\\u4e00\\u4e2a\\u5bc2\\u9759\\u7684\\u591c\\u665a\\uff0c\\u7504\\u8d3e\\u8d3e\\u5306\\u5306\\u5fd9\\u5fd9\\u5730\\u4ece\\u5c0f\\u5df7\\u5b50\\u91cc\\u8dd1\\u4e86\\u51fa\\u6765\\uff0c\\u8138\\u4e0a\\u6ee1\\u662f\\u60ca\\u6050\\u3002\\u5728\\u4ed6\\u8eab\\u540e\\uff0c\\u4e00\\u53ea\\u7a7a\\u8361\\u8361\\u7684\\u5783\\u573e\\u6876\\u7ffb\\u5012\\u5728\\u5730\\u3002\\u7504\\u8d3e\\u8d3e\\u5e76\\u975e\\u5c0f\\u5df7\\u91cc\\u7684\\u5c45\\u6c11\\uff0c\\u4e5f\\u6ca1\\u6709\\u4e0e\\u4eba\\u7ed3\\u6028\\u3002\\u7a76\\u7adf\\u662f\\u4ec0\\u4e48\\u539f\\u56e0\\u8ba9\\u4ed6\\u5982\\u6b64\\u60ca\\u614c\\u5931\\u63aa\\uff1f\\n\\n\\u5b9e\\u9645\\u60c5\\u51b5: \\u539f\\u6765\\uff0c\\u7504\\u8d3e\\u8d3e\\u662f\\u4e00\\u540d\\u6b63\\u5728\\u6f5c\\u9003\\u7684\\u5c0f\\u5077\\u3002\\u5f53\\u665a\\uff0c\\u4ed6\\u4f01\\u56fe\\u5728\\u5df7\\u5b50\\u91cc\\u5bfb\\u627e\\u53ef\\u4ee5\\u76d7\\u7a83\\u7684\\u76ee\\u6807\\uff0c\\u5374\\u4e0d\\u6599\\u5783\\u573e\\u6876\\u91cc\\u7a81\\u7136\\u7a9c\\u51fa\\u4e00\\u53ea\\u91ce\\u732b\\uff0c\\u5c06\\u4ed6\\u5413\\u4e86\\u4e00\\u8df3\\u3002\\u4ed6\\u4ee5\\u4e3a\\u662f\\u88ab\\u8b66\\u65b9\\u53d1\\u73b0\\u4e86\\uff0c\\u4e8e\\u662f\\u60ca\\u614c\\u5931\\u63aa\\u5730\\u9003\\u8dd1\\u4e86\\u3002\\u800c\\u90a3\\u53ea\\u5783\\u573e\\u6876\\uff0c\\u6b63\\u662f\\u4ed6\\u7ffb\\u627e\\u4e1c\\u897f\\u65f6\\u4e0d\\u5c0f\\u5fc3\\u5f04\\u7ffb\\u7684\\u3002\\n\\n\\u53c2\\u4e0e\\u8005\\u63d0\\u51fa\\u7684\\u95ee\\u9898: \\u6d41\\u6d6a\\u732b\\u5417\\uff1f\\n\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"input\",\n \"properties\": {\n \"dtype\": \"object\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"output\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"\\u4e0d\\u91cd\\u8981\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":12}],"source":["df_alpaca = load_alpaca_data(data_path)\n","df_alpaca.head()"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"xPVpy6WpZBrN","outputId":"90893596-ad19-40c0-975e-28afc6270fe4"},"outputs":[{"output_type":"stream","name":"stdout","text":["Current Directory:\n","/content/drive/MyDrive/logical-reasoning/llama-factory\n","config/internlm2_5_7b_lora_sft_bf16.yaml:\n"," {\n"," \"model_name_or_path\": \"internlm/internlm2_5-7b-chat-1m\",\n"," \"stage\": \"sft\",\n"," \"do_train\": true,\n"," \"finetuning_type\": \"lora\",\n"," \"lora_target\": \"all\",\n"," \"loraplus_lr_ratio\": 16.0,\n"," \"upcast_layernorm\": true,\n"," \"dataset\": \"alpaca_mgtv_p1\",\n"," \"template\": \"chatml\",\n"," \"cutoff_len\": 1024,\n"," \"max_samples\": 5000,\n"," \"overwrite_cache\": true,\n"," \"preprocessing_num_workers\": 16,\n"," \"output_dir\": \"saves/internlm2_5_7b/lora/sft_bf16\",\n"," \"logging_steps\": 100,\n"," \"save_steps\": 562,\n"," \"plot_loss\": true,\n"," \"overwrite_output_dir\": true,\n"," \"per_device_train_batch_size\": 1,\n"," \"gradient_accumulation_steps\": 8,\n"," \"learning_rate\": 0.0001,\n"," \"num_train_epochs\": 6.0,\n"," \"lr_scheduler_type\": \"cosine\",\n"," \"warmup_ratio\": 0.1,\n"," \"bf16\": true,\n"," \"ddp_timeout\": 180000000,\n"," \"val_size\": 0.1,\n"," \"per_device_eval_batch_size\": 1,\n"," \"eval_strategy\": \"steps\",\n"," \"eval_steps\": 562,\n"," \"report_to\": \"none\",\n"," \"run_name\": \"internlm2_5_7b\"\n","}\n","2024-07-11 06:32:15.069882: I tensorflow/core/util/port.cc:113] 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","2024-07-11 06:32:15.119313: 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-07-11 06:32:15.119371: 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-07-11 06:32:15.120651: 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-07-11 06:32:15.127885: 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 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n","2024-07-11 06:32:16.367943: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n","07/11/2024 06:32:22 - INFO - llamafactory.hparams.parser - Process rank: 0, device: cuda:0, n_gpu: 1, distributed training: False, compute dtype: torch.bfloat16\n","[INFO|tokenization_utils_base.py:2108] 2024-07-11 06:32:22,557 >> loading file ./tokenizer.model from cache at /root/.cache/huggingface/hub/models--internlm--internlm2_5-7b-chat-1m/snapshots/8d1a709a04d71440ef3df6ebbe204672f411c8b6/./tokenizer.model\n","[INFO|tokenization_utils_base.py:2108] 2024-07-11 06:32:22,557 >> loading file added_tokens.json from cache at None\n","[INFO|tokenization_utils_base.py:2108] 2024-07-11 06:32:22,557 >> loading file special_tokens_map.json from cache at /root/.cache/huggingface/hub/models--internlm--internlm2_5-7b-chat-1m/snapshots/8d1a709a04d71440ef3df6ebbe204672f411c8b6/special_tokens_map.json\n","[INFO|tokenization_utils_base.py:2108] 2024-07-11 06:32:22,557 >> loading file tokenizer_config.json from cache at /root/.cache/huggingface/hub/models--internlm--internlm2_5-7b-chat-1m/snapshots/8d1a709a04d71440ef3df6ebbe204672f411c8b6/tokenizer_config.json\n","[INFO|tokenization_utils_base.py:2108] 2024-07-11 06:32:22,557 >> loading file tokenizer.json from cache at None\n","07/11/2024 06:32:23 - INFO - llamafactory.data.template - Replace eos token: <|im_end|>\n","07/11/2024 06:32:23 - INFO - llamafactory.data.template - Add <|im_start|> to stop words.\n","07/11/2024 06:32:23 - INFO - llamafactory.data.loader - Loading dataset alpaca_mgtv_p1.json...\n","/usr/local/lib/python3.10/dist-packages/multiprocess/popen_fork.py:66: RuntimeWarning: os.fork() was called. os.fork() is incompatible with multithreaded code, and JAX is multithreaded, so this will likely lead to a deadlock.\n"," self.pid = os.fork()\n","Converting format of dataset (num_proc=16): 100% 5000/5000 [00:00<00:00, 20501.98 examples/s]\n","Running tokenizer on dataset (num_proc=16): 100% 5000/5000 [00:02<00:00, 1948.01 examples/s]\n","input_ids:\n","[92543, 1008, 364, 60403, 68625, 70503, 68309, 69323, 60687, 60364, 60355, 68309, 69776, 68411, 60387, 402, 312, 281, 262, 69102, 60497, 60382, 89428, 63352, 60582, 60355, 364, 314, 281, 262, 69102, 60497, 70357, 73912, 60383, 69464, 75687, 60353, 69702, 84931, 63352, 60582, 60355, 364, 308, 281, 262, 68390, 68772, 68287, 60353, 74243, 60530, 68420, 74740, 68855, 68544, 72719, 68423, 68538, 60387, 60357, 60359, 68278, 60359, 82568, 60359, 68855, 69077, 60359, 60593, 60408, 69583, 60355, 364, 319, 281, 262, 68855, 60366, 68336, 68535, 68574, 69344, 68347, 60353, 71452, 81256, 68423, 68322, 78818, 60666, 60355, 69192, 60353, 73263, 60581, 60419, 68278, 60420, 81256, 60397, 60419, 60358, 60420, 60355, 364, 317, 281, 262, 69102, 60497, 68266, 68420, 68855, 60383, 76681, 60353, 60573, 68985, 75326, 63352, 80931, 69077, 69059, 60355, 402, 60836, 86910, 68374, 69776, 68855, 69102, 60497, 74743, 68287, 60355, 402, 63352, 60582, 334, 262, 60361, 63840, 60396, 78165, 60353, 68935, 79406, 70952, 60387, 69731, 71150, 88982, 82620, 60353, 71150, 61329, 60425, 60649, 68935, 69410, 71150, 60382, 60358, 62273, 60458, 61217, 60353, 71479, 60400, 72593, 69380, 79594, 90209, 60355, 60836, 75326, 71150, 82066, 79202, 68540, 60355, 402, 74740, 334, 262, 73687, 69607, 60510, 70226, 60372, 62650, 60354, 61044, 61066, 69045, 60355, 71389, 61044, 61066, 89463, 60353, 61002, 60510, 70226, 73027, 70134, 60544, 61422, 60355, 68310, 74907, 60361, 71150, 88982, 82620, 68980, 60355, 69104, 60353, 71062, 61976, 60364, 60353, 70134, 60361, 72325, 60463, 68294, 60612, 70623, 60366, 60877, 60668, 60355, 74726, 60354, 61044, 61066, 68394, 70367, 60447, 69126, 70134, 60353, 69731, 68549, 60530, 69410, 71150, 61882, 60825, 60353, 70395, 70134, 60354, 62296, 60463, 60353, 72069, 86407, 68304, 63024, 60880, 60355, 68597, 68891, 73936, 60362, 69372, 60353, 71093, 72276, 60425, 68252, 82569, 70952, 60355, 402, 69102, 60497, 74743, 68287, 334, 262, 61882, 68279, 60548, 60780, 61076, 364, 92542, 364, 92543, 525, 11353, 364, 68278, 92542]\n","inputs:\n","<|im_start|>user\n","你是一个逻辑游戏的主持人。游戏规则如下:\n","\n","1. 参与者会得到一个谜题。\n","2. 参与者可以通过提问来获取线索,尝试解开谜题。\n","3. 对于每个问题,主持人将根据实际情况回答以下五个选项之一:是、不是、不重要、回答正确、问法错误。\n","4. 回答中不能添加任何其它信息,也不能省略选项中的任何一个字。例如,不可以把“不是”省略成“不”。\n","5. 参与者需要根据回答来推理,并最终找出谜题的正确答案。\n","\n","请严格按照这些规则回答参与者提出的问题。\n","\n","谜题: 在甄家村里,有一个古老的传说:每年南瓜丰收的季节,南瓜田里总有一个最大的南瓜会不翼而飞,村民们对此现象困惑不解。请找出南瓜失踪背后的原因。\n","\n","实际情况: 真相原来与一位年迈的农夫有关。这位农夫年轻时,曾与一位美丽的姑娘相恋。他们约定在南瓜丰收的季节结婚。然而,命运弄人,姑娘在婚礼前的一场意外中离世。悲伤的农夫为了纪念心爱的姑娘,每年都会将最大的南瓜偷走,放到姑娘的墓前,以此寄托自己的哀思。这一行为延续了多年,成为了乡村里一个神秘的传说。\n","\n","参与者提出的问题: 偷的人信神吗\n","<|im_end|>\n","<|im_start|>assistant\n","不是<|im_end|>\n","label_ids:\n","[-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, 68278, 92542]\n","labels:\n","不是<|im_end|>\n","/usr/local/lib/python3.10/dist-packages/huggingface_hub/file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.\n"," warnings.warn(\n","[INFO|configuration_utils.py:733] 2024-07-11 06:32:27,506 >> loading configuration file config.json from cache at /root/.cache/huggingface/hub/models--internlm--internlm2_5-7b-chat-1m/snapshots/8d1a709a04d71440ef3df6ebbe204672f411c8b6/config.json\n","[INFO|configuration_utils.py:733] 2024-07-11 06:32:27,740 >> loading configuration file config.json from cache at /root/.cache/huggingface/hub/models--internlm--internlm2_5-7b-chat-1m/snapshots/8d1a709a04d71440ef3df6ebbe204672f411c8b6/config.json\n","[INFO|configuration_utils.py:796] 2024-07-11 06:32:27,742 >> Model config InternLM2Config {\n"," \"_name_or_path\": \"internlm/internlm2_5-7b-chat-1m\",\n"," \"architectures\": [\n"," \"InternLM2ForCausalLM\"\n"," ],\n"," \"attn_implementation\": \"eager\",\n"," \"auto_map\": {\n"," \"AutoConfig\": \"internlm/internlm2_5-7b-chat-1m--configuration_internlm2.InternLM2Config\",\n"," \"AutoModel\": \"internlm/internlm2_5-7b-chat-1m--modeling_internlm2.InternLM2ForCausalLM\",\n"," \"AutoModelForCausalLM\": \"internlm/internlm2_5-7b-chat-1m--modeling_internlm2.InternLM2ForCausalLM\"\n"," },\n"," \"bias\": false,\n"," \"bos_token_id\": 1,\n"," \"eos_token_id\": 2,\n"," \"hidden_act\": \"silu\",\n"," \"hidden_size\": 4096,\n"," \"initializer_range\": 0.02,\n"," \"intermediate_size\": 14336,\n"," \"max_position_embeddings\": 262144,\n"," \"model_type\": \"internlm2\",\n"," \"num_attention_heads\": 32,\n"," \"num_hidden_layers\": 32,\n"," \"num_key_value_heads\": 8,\n"," \"pad_token_id\": 2,\n"," \"pretraining_tp\": 1,\n"," \"rms_norm_eps\": 1e-05,\n"," \"rope_scaling\": {\n"," \"factor\": 2.5,\n"," \"type\": \"dynamic\"\n"," },\n"," \"rope_theta\": 50000000,\n"," \"tie_word_embeddings\": false,\n"," \"torch_dtype\": \"bfloat16\",\n"," \"transformers_version\": \"4.41.2\",\n"," \"use_cache\": true,\n"," \"vocab_size\": 92544\n","}\n","\n","[INFO|modeling_utils.py:3474] 2024-07-11 06:32:27,887 >> loading weights file model.safetensors from cache at /root/.cache/huggingface/hub/models--internlm--internlm2_5-7b-chat-1m/snapshots/8d1a709a04d71440ef3df6ebbe204672f411c8b6/model.safetensors.index.json\n","[INFO|modeling_utils.py:1519] 2024-07-11 06:32:27,888 >> Instantiating InternLM2ForCausalLM model under default dtype torch.bfloat16.\n","[INFO|configuration_utils.py:962] 2024-07-11 06:32:27,890 >> Generate config GenerationConfig {\n"," \"bos_token_id\": 1,\n"," \"eos_token_id\": 2,\n"," \"pad_token_id\": 2\n","}\n","\n","Loading checkpoint shards: 100% 8/8 [00:07<00:00, 1.01it/s]\n","[INFO|modeling_utils.py:4280] 2024-07-11 06:32:35,920 >> All model checkpoint weights were used when initializing InternLM2ForCausalLM.\n","\n","[INFO|modeling_utils.py:4288] 2024-07-11 06:32:35,920 >> All the weights of InternLM2ForCausalLM were initialized from the model checkpoint at internlm/internlm2_5-7b-chat-1m.\n","If your task is similar to the task the model of the checkpoint was trained on, you can already use InternLM2ForCausalLM for predictions without further training.\n","[INFO|configuration_utils.py:917] 2024-07-11 06:32:36,017 >> loading configuration file generation_config.json from cache at /root/.cache/huggingface/hub/models--internlm--internlm2_5-7b-chat-1m/snapshots/8d1a709a04d71440ef3df6ebbe204672f411c8b6/generation_config.json\n","[INFO|configuration_utils.py:962] 2024-07-11 06:32:36,017 >> Generate config GenerationConfig {\n"," \"bos_token_id\": 1,\n"," \"eos_token_id\": [\n"," 2,\n"," 92542\n"," ],\n"," \"pad_token_id\": 2\n","}\n","\n","07/11/2024 06:32:36 - INFO - llamafactory.model.model_utils.checkpointing - Upcasting layernorm weights in float32.\n","07/11/2024 06:32:36 - INFO - llamafactory.model.model_utils.checkpointing - Gradient checkpointing enabled.\n","07/11/2024 06:32:36 - INFO - llamafactory.model.model_utils.attention - Using vanilla attention implementation.\n","07/11/2024 06:32:36 - INFO - llamafactory.model.adapter - Upcasting trainable params to float32.\n","07/11/2024 06:32:36 - INFO - llamafactory.model.adapter - Fine-tuning method: LoRA\n","07/11/2024 06:32:36 - INFO - llamafactory.model.model_utils.misc - Found linear modules: wo,w2,wqkv,w1,w3\n","07/11/2024 06:32:36 - INFO - llamafactory.model.loader - trainable params: 18,874,368 || all params: 7,756,582,912 || trainable%: 0.2433\n","[INFO|trainer.py:641] 2024-07-11 06:32:36,579 >> Using auto half precision backend\n","07/11/2024 06:32:37 - INFO - llamafactory.train.trainer_utils - Using LoRA+ optimizer with loraplus lr ratio 16.00.\n","[INFO|trainer.py:2078] 2024-07-11 06:32:37,721 >> ***** Running training *****\n","[INFO|trainer.py:2079] 2024-07-11 06:32:37,721 >> Num examples = 4,500\n","[INFO|trainer.py:2080] 2024-07-11 06:32:37,721 >> Num Epochs = 6\n","[INFO|trainer.py:2081] 2024-07-11 06:32:37,721 >> Instantaneous batch size per device = 1\n","[INFO|trainer.py:2084] 2024-07-11 06:32:37,721 >> Total train batch size (w. parallel, distributed & accumulation) = 8\n","[INFO|trainer.py:2085] 2024-07-11 06:32:37,721 >> Gradient Accumulation steps = 8\n","[INFO|trainer.py:2086] 2024-07-11 06:32:37,721 >> Total optimization steps = 3,372\n","[INFO|trainer.py:2087] 2024-07-11 06:32:37,725 >> Number of trainable parameters = 18,874,368\n","{'loss': 0.4734, 'grad_norm': 2.4078445434570312, 'learning_rate': 2.958579881656805e-05, 'epoch': 0.18}\n","{'loss': 0.3667, 'grad_norm': 4.478668689727783, 'learning_rate': 5.91715976331361e-05, 'epoch': 0.36}\n","{'loss': 0.3744, 'grad_norm': 4.706894397735596, 'learning_rate': 8.875739644970414e-05, 'epoch': 0.53}\n","{'loss': 0.3797, 'grad_norm': 2.9772543907165527, 'learning_rate': 9.989699867437137e-05, 'epoch': 0.71}\n","{'loss': 0.3443, 'grad_norm': 6.316380023956299, 'learning_rate': 9.92981892269398e-05, 'epoch': 0.89}\n"," 17% 562/3372 [41:15<3:24:28, 4.37s/it][INFO|trainer.py:3719] 2024-07-11 07:13:53,558 >> ***** Running Evaluation *****\n","[INFO|trainer.py:3721] 2024-07-11 07:13:53,558 >> Num examples = 500\n","[INFO|trainer.py:3724] 2024-07-11 07:13:53,558 >> Batch size = 1\n","\n"," 0% 0/500 [00:00> Saving model checkpoint to saves/internlm2_5_7b/lora/sft_bf16/checkpoint-562\n","[INFO|configuration_utils.py:733] 2024-07-11 07:15:21,480 >> loading configuration file config.json from cache at /root/.cache/huggingface/hub/models--internlm--internlm2_5-7b-chat-1m/snapshots/8d1a709a04d71440ef3df6ebbe204672f411c8b6/config.json\n","[INFO|configuration_utils.py:796] 2024-07-11 07:15:21,481 >> Model config InternLM2Config {\n"," \"architectures\": [\n"," \"InternLM2ForCausalLM\"\n"," ],\n"," \"attn_implementation\": \"eager\",\n"," \"auto_map\": {\n"," \"AutoConfig\": \"internlm/internlm2_5-7b-chat-1m--configuration_internlm2.InternLM2Config\",\n"," \"AutoModel\": \"internlm/internlm2_5-7b-chat-1m--modeling_internlm2.InternLM2ForCausalLM\",\n"," \"AutoModelForCausalLM\": \"internlm/internlm2_5-7b-chat-1m--modeling_internlm2.InternLM2ForCausalLM\"\n"," },\n"," \"bias\": false,\n"," \"bos_token_id\": 1,\n"," \"eos_token_id\": 2,\n"," \"hidden_act\": \"silu\",\n"," \"hidden_size\": 4096,\n"," \"initializer_range\": 0.02,\n"," \"intermediate_size\": 14336,\n"," \"max_position_embeddings\": 262144,\n"," \"model_type\": \"internlm2\",\n"," \"num_attention_heads\": 32,\n"," \"num_hidden_layers\": 32,\n"," \"num_key_value_heads\": 8,\n"," \"pad_token_id\": 2,\n"," \"pretraining_tp\": 1,\n"," \"rms_norm_eps\": 1e-05,\n"," \"rope_scaling\": {\n"," \"factor\": 2.5,\n"," \"type\": \"dynamic\"\n"," },\n"," \"rope_theta\": 50000000,\n"," \"tie_word_embeddings\": false,\n"," \"torch_dtype\": \"bfloat16\",\n"," \"transformers_version\": \"4.41.2\",\n"," \"use_cache\": true,\n"," \"vocab_size\": 92544\n","}\n","\n","[INFO|tokenization_utils_base.py:2513] 2024-07-11 07:15:21,796 >> tokenizer config file saved in saves/internlm2_5_7b/lora/sft_bf16/checkpoint-562/tokenizer_config.json\n","[INFO|tokenization_utils_base.py:2522] 2024-07-11 07:15:21,800 >> Special tokens file saved in saves/internlm2_5_7b/lora/sft_bf16/checkpoint-562/special_tokens_map.json\n","{'loss': 0.3644, 'grad_norm': 3.866260051727295, 'learning_rate': 9.817128546774103e-05, 'epoch': 1.07}\n","{'loss': 0.3146, 'grad_norm': 2.369489908218384, 'learning_rate': 9.652835906663704e-05, 'epoch': 1.24}\n","{'loss': 0.3365, 'grad_norm': 4.548018932342529, 'learning_rate': 9.438700945477697e-05, 'epoch': 1.42}\n","{'loss': 0.2878, 'grad_norm': 12.139796257019043, 'learning_rate': 9.177017529516772e-05, 'epoch': 1.6}\n","{'loss': 0.3291, 'grad_norm': 0.8868021965026855, 'learning_rate': 8.870588875808164e-05, 'epoch': 1.78}\n","{'loss': 0.2604, 'grad_norm': 0.3065238893032074, 'learning_rate': 8.522697523356319e-05, 'epoch': 1.96}\n"," 33% 1124/3372 [1:23:52<2:44:13, 4.38s/it][INFO|trainer.py:3719] 2024-07-11 07:56:30,547 >> ***** Running Evaluation *****\n","[INFO|trainer.py:3721] 2024-07-11 07:56:30,547 >> Num examples = 500\n","[INFO|trainer.py:3724] 2024-07-11 07:56:30,547 >> Batch size = 1\n","\n"," 0% 0/500 [00:00> Saving model checkpoint to saves/internlm2_5_7b/lora/sft_bf16/checkpoint-1124\n","/usr/local/lib/python3.10/dist-packages/huggingface_hub/file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.\n"," warnings.warn(\n","[INFO|configuration_utils.py:733] 2024-07-11 07:57:57,792 >> loading configuration file config.json from cache at /root/.cache/huggingface/hub/models--internlm--internlm2_5-7b-chat-1m/snapshots/8d1a709a04d71440ef3df6ebbe204672f411c8b6/config.json\n","[INFO|configuration_utils.py:796] 2024-07-11 07:57:57,793 >> Model config InternLM2Config {\n"," \"architectures\": [\n"," \"InternLM2ForCausalLM\"\n"," ],\n"," \"attn_implementation\": \"eager\",\n"," \"auto_map\": {\n"," \"AutoConfig\": \"internlm/internlm2_5-7b-chat-1m--configuration_internlm2.InternLM2Config\",\n"," \"AutoModel\": \"internlm/internlm2_5-7b-chat-1m--modeling_internlm2.InternLM2ForCausalLM\",\n"," \"AutoModelForCausalLM\": \"internlm/internlm2_5-7b-chat-1m--modeling_internlm2.InternLM2ForCausalLM\"\n"," },\n"," \"bias\": false,\n"," \"bos_token_id\": 1,\n"," \"eos_token_id\": 2,\n"," \"hidden_act\": \"silu\",\n"," \"hidden_size\": 4096,\n"," \"initializer_range\": 0.02,\n"," \"intermediate_size\": 14336,\n"," \"max_position_embeddings\": 262144,\n"," \"model_type\": \"internlm2\",\n"," \"num_attention_heads\": 32,\n"," \"num_hidden_layers\": 32,\n"," \"num_key_value_heads\": 8,\n"," \"pad_token_id\": 2,\n"," \"pretraining_tp\": 1,\n"," \"rms_norm_eps\": 1e-05,\n"," \"rope_scaling\": {\n"," \"factor\": 2.5,\n"," \"type\": \"dynamic\"\n"," },\n"," \"rope_theta\": 50000000,\n"," \"tie_word_embeddings\": false,\n"," \"torch_dtype\": \"bfloat16\",\n"," \"transformers_version\": \"4.41.2\",\n"," \"use_cache\": true,\n"," \"vocab_size\": 92544\n","}\n","\n","[INFO|tokenization_utils_base.py:2513] 2024-07-11 07:57:58,080 >> tokenizer config file saved in saves/internlm2_5_7b/lora/sft_bf16/checkpoint-1124/tokenizer_config.json\n","[INFO|tokenization_utils_base.py:2522] 2024-07-11 07:57:58,083 >> Special tokens file saved in saves/internlm2_5_7b/lora/sft_bf16/checkpoint-1124/special_tokens_map.json\n","{'loss': 0.2122, 'grad_norm': 1.911468744277954, 'learning_rate': 8.137070169778812e-05, 'epoch': 2.13}\n","{'loss': 0.2322, 'grad_norm': 3.41011381149292, 'learning_rate': 7.717837750006106e-05, 'epoch': 2.31}\n","{'loss': 0.2091, 'grad_norm': 4.826447486877441, 'learning_rate': 7.269491184691924e-05, 'epoch': 2.49}\n","{'loss': 0.229, 'grad_norm': 5.958643913269043, 'learning_rate': 6.79683327236813e-05, 'epoch': 2.67}\n","{'loss': 0.2278, 'grad_norm': 0.9083921909332275, 'learning_rate': 6.304927240687181e-05, 'epoch': 2.84}\n"," 50% 1686/3372 [2:06:24<2:02:07, 4.35s/it][INFO|trainer.py:3719] 2024-07-11 08:39:02,399 >> ***** Running Evaluation *****\n","[INFO|trainer.py:3721] 2024-07-11 08:39:02,399 >> Num examples = 500\n","[INFO|trainer.py:3724] 2024-07-11 08:39:02,399 >> Batch size = 1\n","\n"," 0% 0/500 [00:00> Saving model checkpoint to saves/internlm2_5_7b/lora/sft_bf16/checkpoint-1686\n","/usr/local/lib/python3.10/dist-packages/huggingface_hub/file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.\n"," warnings.warn(\n","[INFO|configuration_utils.py:733] 2024-07-11 08:40:29,751 >> loading configuration file config.json from cache at /root/.cache/huggingface/hub/models--internlm--internlm2_5-7b-chat-1m/snapshots/8d1a709a04d71440ef3df6ebbe204672f411c8b6/config.json\n","[INFO|configuration_utils.py:796] 2024-07-11 08:40:29,752 >> Model config InternLM2Config {\n"," \"architectures\": [\n"," \"InternLM2ForCausalLM\"\n"," ],\n"," \"attn_implementation\": \"eager\",\n"," \"auto_map\": {\n"," \"AutoConfig\": \"internlm/internlm2_5-7b-chat-1m--configuration_internlm2.InternLM2Config\",\n"," \"AutoModel\": \"internlm/internlm2_5-7b-chat-1m--modeling_internlm2.InternLM2ForCausalLM\",\n"," \"AutoModelForCausalLM\": \"internlm/internlm2_5-7b-chat-1m--modeling_internlm2.InternLM2ForCausalLM\"\n"," },\n"," \"bias\": false,\n"," \"bos_token_id\": 1,\n"," \"eos_token_id\": 2,\n"," \"hidden_act\": \"silu\",\n"," \"hidden_size\": 4096,\n"," \"initializer_range\": 0.02,\n"," \"intermediate_size\": 14336,\n"," \"max_position_embeddings\": 262144,\n"," \"model_type\": \"internlm2\",\n"," \"num_attention_heads\": 32,\n"," \"num_hidden_layers\": 32,\n"," \"num_key_value_heads\": 8,\n"," \"pad_token_id\": 2,\n"," \"pretraining_tp\": 1,\n"," \"rms_norm_eps\": 1e-05,\n"," \"rope_scaling\": {\n"," \"factor\": 2.5,\n"," \"type\": \"dynamic\"\n"," },\n"," \"rope_theta\": 50000000,\n"," \"tie_word_embeddings\": false,\n"," \"torch_dtype\": \"bfloat16\",\n"," \"transformers_version\": \"4.41.2\",\n"," \"use_cache\": true,\n"," \"vocab_size\": 92544\n","}\n","\n","[INFO|tokenization_utils_base.py:2513] 2024-07-11 08:40:30,047 >> tokenizer config file saved in saves/internlm2_5_7b/lora/sft_bf16/checkpoint-1686/tokenizer_config.json\n","[INFO|tokenization_utils_base.py:2522] 2024-07-11 08:40:30,051 >> Special tokens file saved in saves/internlm2_5_7b/lora/sft_bf16/checkpoint-1686/special_tokens_map.json\n","{'loss': 0.1859, 'grad_norm': 3.2975399494171143, 'learning_rate': 5.799042507883874e-05, 'epoch': 3.02}\n","{'loss': 0.1403, 'grad_norm': 0.3952264189720154, 'learning_rate': 5.284598235472912e-05, 'epoch': 3.2}\n","{'loss': 0.156, 'grad_norm': 0.7494814991950989, 'learning_rate': 4.7671052768596945e-05, 'epoch': 3.38}\n","{'loss': 0.1221, 'grad_norm': 0.022936208173632622, 'learning_rate': 4.2521071437250546e-05, 'epoch': 3.56}\n","{'loss': 0.1278, 'grad_norm': 7.184863090515137, 'learning_rate': 3.7451206225665035e-05, 'epoch': 3.73}\n","{'loss': 0.1115, 'grad_norm': 1.4601508378982544, 'learning_rate': 3.251576677526236e-05, 'epoch': 3.91}\n"," 67% 2248/3372 [2:48:55<1:22:21, 4.40s/it][INFO|trainer.py:3719] 2024-07-11 09:21:33,658 >> ***** Running Evaluation *****\n","[INFO|trainer.py:3721] 2024-07-11 09:21:33,658 >> Num examples = 500\n","[INFO|trainer.py:3724] 2024-07-11 09:21:33,658 >> Batch size = 1\n","\n"," 0% 0/500 [00:00> Saving model checkpoint to saves/internlm2_5_7b/lora/sft_bf16/checkpoint-2248\n","/usr/local/lib/python3.10/dist-packages/huggingface_hub/file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.\n"," warnings.warn(\n","[INFO|configuration_utils.py:733] 2024-07-11 09:23:01,246 >> loading configuration file config.json from cache at /root/.cache/huggingface/hub/models--internlm--internlm2_5-7b-chat-1m/snapshots/8d1a709a04d71440ef3df6ebbe204672f411c8b6/config.json\n","[INFO|configuration_utils.py:796] 2024-07-11 09:23:01,247 >> Model config InternLM2Config {\n"," \"architectures\": [\n"," \"InternLM2ForCausalLM\"\n"," ],\n"," \"attn_implementation\": \"eager\",\n"," \"auto_map\": {\n"," \"AutoConfig\": \"internlm/internlm2_5-7b-chat-1m--configuration_internlm2.InternLM2Config\",\n"," \"AutoModel\": \"internlm/internlm2_5-7b-chat-1m--modeling_internlm2.InternLM2ForCausalLM\",\n"," \"AutoModelForCausalLM\": \"internlm/internlm2_5-7b-chat-1m--modeling_internlm2.InternLM2ForCausalLM\"\n"," },\n"," \"bias\": false,\n"," \"bos_token_id\": 1,\n"," \"eos_token_id\": 2,\n"," \"hidden_act\": \"silu\",\n"," \"hidden_size\": 4096,\n"," \"initializer_range\": 0.02,\n"," \"intermediate_size\": 14336,\n"," \"max_position_embeddings\": 262144,\n"," \"model_type\": \"internlm2\",\n"," \"num_attention_heads\": 32,\n"," \"num_hidden_layers\": 32,\n"," \"num_key_value_heads\": 8,\n"," \"pad_token_id\": 2,\n"," \"pretraining_tp\": 1,\n"," \"rms_norm_eps\": 1e-05,\n"," \"rope_scaling\": {\n"," \"factor\": 2.5,\n"," \"type\": \"dynamic\"\n"," },\n"," \"rope_theta\": 50000000,\n"," \"tie_word_embeddings\": false,\n"," \"torch_dtype\": \"bfloat16\",\n"," \"transformers_version\": \"4.41.2\",\n"," \"use_cache\": true,\n"," \"vocab_size\": 92544\n","}\n","\n","[INFO|tokenization_utils_base.py:2513] 2024-07-11 09:23:01,555 >> tokenizer config file saved in saves/internlm2_5_7b/lora/sft_bf16/checkpoint-2248/tokenizer_config.json\n","[INFO|tokenization_utils_base.py:2522] 2024-07-11 09:23:01,558 >> Special tokens file saved in saves/internlm2_5_7b/lora/sft_bf16/checkpoint-2248/special_tokens_map.json\n","{'loss': 0.1009, 'grad_norm': 7.792446613311768, 'learning_rate': 2.776762272569255e-05, 'epoch': 4.09}\n","{'loss': 0.0724, 'grad_norm': 0.030512813478708267, 'learning_rate': 2.325763736226793e-05, 'epoch': 4.27}\n","{'loss': 0.0598, 'grad_norm': 0.02794470079243183, 'learning_rate': 1.9034122755957523e-05, 'epoch': 4.44}\n"," 75% 2542/3372 [3:11:51<1:00:25, 4.37s/it]"]}],"source":["%%time\n","\n","!sh ./scripts/tune-lf.sh config/internlm2_5_7b_lora_sft_bf16.yaml"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"L370pvGTZBrN"},"outputs":[],"source":["def evaluate_model_all_epochs(model_name, adapter_path_base, num_train_epochs, start_epoch=0, load_in_4bit=True, num_of_entries=-1):\n"," os.environ[\"MODEL_NAME\"] = model_name\n"," os.environ[\"LOAD_IN_4BIT\"] = \"true\" if load_in_4bit else \"false\"\n"," for i in range(start_epoch, num_train_epochs + 1):\n"," print(f\"Epoch {i}\")\n"," if i == 0:\n"," os.unsetenv(\"ADAPTER_NAME_OR_PATH\")\n"," else:\n"," adapter_path = f\"{adapter_path_base}/checkpoint-{562 * i}\"\n"," os.environ[\"ADAPTER_NAME_OR_PATH\"] = adapter_path\n","\n"," !python llm_toolkit/eval_logical_reasoning.py {num_of_entries}"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"WUFjhxmiZBrN"},"outputs":[],"source":["%%time\n","\n","evaluate_model_all_epochs(\"internlm/internlm2_5-7b-chat-1m\", \"llama-factory/saves/internlm2_5_7b/lora/sft_bf16\", 6, start_epoch=0, load_in_4bit=False, num_of_entries=-1)"]}],"metadata":{"accelerator":"GPU","application/vnd.databricks.v1+notebook":{"dashboards":[],"environmentMetadata":null,"language":"python","notebookMetadata":{"mostRecentlyExecutedCommandWithImplicitDF":{"commandId":-1,"dataframes":["_sqldf"]},"pythonIndentUnit":4},"notebookName":"10_eval-lf-medium-py3.11","widgets":{}},"colab":{"gpuType":"L4","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.11.9"}},"nbformat":4,"nbformat_minor":0}