Æȼ«¤Î¥Ç¡¼¥¿¥»¥Ã¥È¤ÇGPT¤Î¤è¤¦¤ÊÂ絬ÌϸÀ¸ì¥â¥Ç¥ë¤ò´Êñ¤Ë¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤Ç¤¤ë¥é¥¤¥Ö¥é¥ê¡ÖLit-Parrot¡×¤òGoogle Cloud Platform¤Ç»È¤Ã¤Æ¤ß¤¿
ÆÃÄê¤ÎʬÌî¤Ë¤Ä¤¤¤Æ¤ÎÃ챤òÁý¤ä¤¹¾ì¹ç¤Ê¤É¡¢Â絬ÌϸÀ¸ì¥â¥Ç¥ë¤Î½ÐÎϤòÆÃÄê¤ÎÊý¸þ¤Ë´ó¤»¤ë¾ì¹ç¤ËÍøÍѤµ¤ì¤ë¤Î¤¬¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤Ç¡¢¤³¤ì¤Ï¥â¥Ç¥ë¤ò¥¼¥í¤«¤é¹½ÃÛ¤¹¤ë¤Î¤ËÈæ¤Ù¤Æ¤Ï¤ë¤«¤Ë¾¯¤Ê¤¤¥Ç¡¼¥¿¥»¥Ã¥È¡õ¤Ï¤ë¤«¤Ë¾¯¤Ê¤¤¥³¥¹¥È¤Ç¥È¥ì¡¼¥Ë¥ó¥°¤Ç¤¤ë¼êË¡¤Ç¤¹¡£¡ÖLit-Parrot¡×¤Ï¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤ò´Êñ¤Ë¹Ô¤¨¤ë¤è¤¦¤Ë¤·¤¿¥é¥¤¥Ö¥é¥ê¤È¤Î¤³¤È¤Ê¤Î¤Ç¡¢¼ÂºÝ¤Ë»È¤Ã¤Æ¤É¤ì¤¯¤é¤¤´Êñ¤Ê¤Î¤«¤ò»î¤·¤Æ¤ß¤Þ¤·¤¿¡£
https://github.com/Lightning-AI/lit-parrot
How To Finetune GPT Like Large Language Models on a Custom Dataset - Lightning AI
https://lightning.ai/pages/blog/how-to-finetune-gpt-like-large-language-models-on-a-custom-dataset/
¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤ò¹Ô¤¦¤Ë¤¢¤¿¤Ã¤Æ¡¢32GB°Ê¾å¤Î¥á¥â¥ê¤ª¤è¤Ó12GB°Ê¾å¤ÎGPU¥á¥â¥ê¤òÅëºÜ¤·¤¿¥Þ¥·¥ó¤¬É¬ÍפǤ¹¡£º£²ó¤ÏGoogle Cloud Platform(GCP)¾å¤Ë²¾ÁÛ¥Þ¥·¥ó¤òÍÑ°Õ¤·¤Þ¤¹¡£GCP¤Î¥³¥ó¥½¡¼¥ë¤ò³«¤¡¢º¸¾å¤Î¥á¥Ë¥å¡¼¤«¤é¡ÖCompute Engine¡×¤òÁªÂò¤·¡¢¡ÖVM¥¤¥ó¥¹¥¿¥ó¥¹¡×¤ò¥¯¥ê¥Ã¥¯¤·¤Þ¤¹¡£
¡Ö¥¤¥ó¥¹¥¿¥ó¥¹¤òºîÀ®¡×¤ò¥¯¥ê¥Ã¥¯¡£
¤ï¤«¤ê¤ä¤¹¤¤Ì¾Á°¤òÉÕ¤±¤Æ¥¾¡¼¥ó¤ò¡Öasia-northeast1-a¡×¤ËÀßÄꤷ¤Þ¤¹¡£¤³¤Î¥¾¡¼¥óÁªÂò¼¡Âè¤ÇÍøÍѤǤ¤ëGPU¤¬°Û¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
Lit-Parrot¤Î¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤Ç¤Ïbfloat16¤ËÂбþ¤·¤¿GPU¤¬É¬ÍפǤ¹¡£º£²ó¤ÏNVIDIA A100 40GB¤òÁªÂò¤·¤Þ¤·¤¿¡£GPU¤ÇA100¤òÁªÂò¤¹¤ë¤È¥Þ¥·¥ó¥¿¥¤¥×¤¬¼«Æ°¤Ça2-highgpu-1g¤ËÊѤï¤ê¤Þ¤¹¡£
¥Ç¥£¥¹¥¯¤ÎÍÆÎ̤¬¾®¤µ¤¤¤Î¤ÇÊѹ¹¤·¤Þ¤¹¡£¡ÖÊѹ¹¡×¤ò¥¯¥ê¥Ã¥¯¡£
¥µ¥¤¥º¤ò50GB¤ËÊѹ¹¤·¡¢¡ÖÁªÂò¡×¤ò¥¯¥ê¥Ã¥¯¤·¤Þ¤¹¡£¤Ê¤ª¡¢GCP¤Ç¤ÏCUDA¤¬¥×¥ì¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Æ¤¤¤ë¥¤¥á¡¼¥¸¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¤¬¡¢ÍøÍѤ·¤¿¤¤CUDA¤Î¥Ð¡¼¥¸¥ç¥ó¤È°ìÃפ·¤Ê¤¤¤Î¤Ç¡¢º£²ó¤ÏCUDA¤ò¼êÆ°¤Ç¥¤¥ó¥¹¥È¡¼¥ë¤·¤Þ¤¹¡£
A100 GPU¤ÎÍøÍÑÎÁ¶â¤Ï¤«¤Ê¤ê¹â³Û¤Ê¤Î¤Ç¡¢¾¯¤·Âкö¤ò¤·¤Þ¤¹¡£¡Ö¾ÜºÙ¥ª¥×¥·¥ç¥ó¡×¤ò¥¯¥ê¥Ã¥¯¤·¤Æ³«¤¡¢¡Ö´ÉÍý¡×¤ò¥¯¥ê¥Ã¥¯¡£
¡Ö²ÄÍÑÀ¥Ý¥ê¥·¡¼¡×¤Î¡ÖVM¥×¥í¥Ó¥¸¥ç¥Ë¥ó¥°¥â¥Ç¥ë¡×¤¬É¸½à¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£¸½¾õ¤Ç¤Ï1»þ´Ö¤´¤È¤Ë4.06¥É¥ë(Ìó570±ß)¤ÎÍøÍÑÎÁ¶â¤¬¤«¤«¤ë¤È¤Î¤³¤È¡£
¤³¤ì¤ò¡Ö¥¹¥Ý¥Ã¥È¡×¤ËÊѹ¹¤¹¤ë¤È¡¢1»þ´Ö¤¢¤¿¤ê¤ÎÎÁ¶â¤¬1.22¥É¥ë(Ìó170±ß)¤Þ¤Ç²¼¤¬¤ê¤Þ¤·¤¿¡£¤â¤Á¤í¤ó¡¢¥¹¥Ý¥Ã¥È¤Ë¤¹¤ë¤³¤È¤ÇGoogle¤ÎÅÔ¹ç¤ÇÆÍÁ³¥·¥ã¥Ã¥È¥À¥¦¥ó¤µ¤ì¤ë²ÄǽÀ¤¬È¯À¸¤·¤Þ¤¹¤¬¡¢º£²ó¤Ï¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤Î¤¿¤á¤Ëû»þ´Öµ¯Æ°¤¹¤ë¤À¤±¤Ç¡¢ÅÓÃæ¤Ç½ªÎ»¤·¤¿¤È¤¤Ëº¤¤ë¤è¤¦¤Ê¥Ç¡¼¥¿¤ò°·¤ï¤Ê¤¤¤Î¤ÇÌäÂê¤Ê¤µ¤½¤¦¤Ç¤¹¡£
¤½¤Î¾¤ÎÀßÄê¤Ï½é´ü¾õÂ֤ΤޤޤǡֺîÀ®¡×¤ò¥¯¥ê¥Ã¥¯¡£
¾õÂÖÍó¤ËÎФΥÁ¥§¥Ã¥¯¥Þ¡¼¥¯¤¬Æþ¤Ã¤¿¤é¡ÖSSH¡×¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¥µ¡¼¥Ð¡¼¤ËÀܳ¤·¤Þ¤¹¡£
¥Ö¥é¥¦¥¶¤ÇSSH²èÌ̤¬³«¤¯¤Î¤Ç¡¢¤³¤³¤«¤é¥³¥Þ¥ó¥É¤òÆþÎϤ·¤Æ¤¤¤¤Þ¤¹¡£
¤Þ¤º¤Ï²¼µ¤Î¥³¡¼¥É¤Ç³Æ¥Ñ¥Ã¥±¡¼¥¸¤ò¹¹¿·¤·¤Æ¤ª¤¤Þ¤¹¡£
sudo apt update && sudo apt upgrade -y
²¼µ¤Î¥³¥Þ¥ó¥É¤Çpip¤Ègit¤ò¥¤¥ó¥¹¥È¡¼¥ë¡£
sudo apt install python3-pip git -y
GCP¤Î¥É¥¥å¥á¥ó¥È¤Î¡ÖGPU¥É¥é¥¤¥Ð¤ò¥¤¥ó¥¹¥È¡¼¥ë¤¹¤ë¡×¥Ú¡¼¥¸¤ò»²¹Í¤Ë¡¢²¼µ¤Î¥³¥Þ¥ó¥É¤ÇGPU¥É¥é¥¤¥Ð¡¼¤ª¤è¤ÓCUDA¤ò¥¤¥ó¥¹¥È¡¼¥ë¤·¤Þ¤¹¡£
curl https://raw.githubusercontent.com/GoogleCloudPlatform/compute-gpu-installation/main/linux/install_gpu_driver.py --output install_gpu_driver.py
sudo python3 install_gpu_driver.py
¤³¤ì¤Ç´Ä¶¹½Ãۤϴ°Î»¤Ç¤¹¡£²¼µ¤Î¥³¥Þ¥ó¥É¤ÇLit-Parrot¤Î¥ê¥Ý¥¸¥È¥ê¤ò¥¯¥í¡¼¥ó¤·¤Þ¤¹¡£
git clone https://github.com/Lightning-AI/lit-parrot.git
cd lit-parrot
Lit-Parrot¤Ïµ»öºîÀ®»þÅÀ¤ÇPyTorch¤Înightly¥Ð¡¼¥¸¥ç¥ó¤Ë¤·¤«ÅëºÜ¤µ¤ì¤Æ¤¤¤Ê¤¤µ¡Ç½¤òÍøÍѤ¹¤ë¤È¤Î¤³¤È¤Ê¤Î¤Ç¡¢²¼µ¤Î¥³¥Þ¥ó¥É¤ÇÄ̾ï¤Î¥é¥¤¥Ö¥é¥ê¤È¤ÏÊ̤˥¤¥ó¥¹¥È¡¼¥ë¤ò¹Ô¤¤¤Þ¤¹¡£
pip install --index-url https://download.pytorch.org/whl/nightly/cu121 --pre 'torch>=2.1.0dev'
¤½¤·¤Æ²¼µ¤Î¥³¥Þ¥ó¥É¤Ç¤½¤Î¾¤Î¥é¥¤¥Ö¥é¥ê¤ò¤Þ¤È¤á¤Æ¥¤¥ó¥¹¥È¡¼¥ë¡£
pip install -r requirements.txt
¤Þ¤¿¡¢Hugging Face¤«¤é¥â¥Ç¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤¿¤á¤Î¥é¥¤¥Ö¥é¥ê¤¬É¬ÍפʤΤÇÊÌÅÓ¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¤ª¤¤Þ¤¹¡£
pip install huggingface-hub
º£²ó¤Ï¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤Î¸µ¤Î¥â¥Ç¥ë¤È¤·¤Æ¡ÖRedPajama-INCITE¡×¤ÎBase-3B-v1¤òÍøÍѤ·¤Þ¤¹¡£RedPajama¤Ë¤Ä¤¤¤Æ¤Ï²¼µ¤Îµ»ö¤Ç²òÀ⤵¤ì¤Æ¤¤¤Þ¤¹¡£
¥ª¡¼¥×¥ó¥½¡¼¥¹¤ÎÂ絬ÌϸÀ¸ì¥â¥Ç¥ë³«È¯¥×¥í¥¸¥§¥¯¥È¡ÖRedPajama¡×¤¬ºÇ½é¤Î¥â¥Ç¥ë¡ÖRedPajama-INCITE¡×¤ò¥ê¥ê¡¼¥¹¡¢ÌµÎÁ¤Ç¾¦ÍÑÍøÍѤâ²Äǽ - GIGAZINE
²¼µ¤Î¥³¡¼¥É¤òÆþÎϤ¹¤ë¤È¼«Æ°¤Ç¥â¥Ç¥ë¤¬¥À¥¦¥ó¥í¡¼¥É¤µ¤ì¤Þ¤¹¡£
python3 scripts/download.py --repo_id togethercomputer/RedPajama-INCITE-Base-3B-v1
¥â¥Ç¥ë¤Î¥À¥¦¥ó¥í¡¼¥É¤¬´°Î»¤·¤¿¤é¡¢²¼µ¤Î¥³¥Þ¥ó¥É¤Ç¥¦¥§¥¤¥È¾ðÊó¤òLit-Parrot¤Î·Á¼°¤ËÀ°¤¨¤Þ¤¹¡£
python3 scripts/convert_hf_checkpoint.py --checkpoint_dir checkpoints/togethercomputer/RedPajama-INCITE-Base-3B-v1
¤³¤Î½èÍý¤Ë¤ÏÄ̾ï¤Î¥á¥â¥ê¤¬Ìó26GBÄøÅÙɬÍפǤ·¤¿¡£
¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤ÎÀßÄê¤ò¤¹¤ë¤¿¤á¡¢²¼µ¤Î¥³¡¼¥É¤òÆþÎϤ·¤Æprepare_alpaca.py¤ò¥Æ¥¥¹¥È¥¨¥Ç¥£¥¿¤Ç³«¤¤Þ¤¹¡£
vi scripts/prepare_alpaca.py
¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤ËÍѤ¤¤ë·±ÎýÍѤΥǡ¼¥¿¤È¤·¤Æ¡ÖDolly 2.0¡×¤Î¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤ËÍѤ¤¤é¤ì¤¿¹âÉʼÁ¥Ç¡¼¥¿¥»¥Ã¥È¡Ödatabricks-dolly-15k¡×¤òÍøÍѤ·¤Þ¤¹¡£Dolly 2.0¤Ë¤Ä¤¤¤Æ¤Ï²¼µ¤Îµ»ö¤Ç²òÀ⤵¤ì¤Æ¤¤¤Þ¤¹¡£
̵ÎÁ¤Ç¾¦ÍÑÍøÍѤâ²Äǽ¤Ê¥ª¡¼¥×¥ó¥½¡¼¥¹¤ÎÂ絬ÌϸÀ¸ì¥â¥Ç¥ë¡ÖDolly 2.0¡×¤òDatabricks¤¬È¯É½ - GIGAZINE
prepare_alpaca.py¤Ëµ½Ò¤µ¤ì¤Æ¤¤¤ëDATA_FILE¤òdatabricks-dolly-15k¤¬¥Û¥¹¥È¤µ¤ì¤Æ¤¤¤ëURL¤ËÀßÄꤷ¡¢checkpoint_dir¤òÀè¤Û¤ÉÍÑ°Õ¤·¤¿RedPajama¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ë½ñ¤´¹¤¨¤Þ¤¹¡£¤µ¤é¤Ë¡¢databricks-dolly-15k¤Ç¤ÏÆþÎÏ¡¦½ÐÎϤÎ̾Á°¤¬¡Öcontext¡×¡Öresponse¡×¤È¤Ê¤Ã¤Æ¤¤¤ë¤Î¤Ç¤½¤ì¤¾¤ì¡Öinput¡×¡Öoutput¡×¤Ë½ñ¤´¹¤¨¤ë¥³¡¼¥É¤òÄɲá£
²¼µ¤Î¥³¡¼¥É¤Çprepare_alpaca.py¤ò¼Â¹Ô¤·¤Æ¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤Î»öÁ°½àÈ÷¤ò¹Ô¤¤¤Þ¤¹¡£
python3 scripts/prepare_alpaca.py \
--destination_path data/dolly \
--checkpoint_dir checkpoints/togethercomputer/RedPajama-INCITE-Base-3B-v1
¤½¤·¤Æ²¼µ¤Î¥³¡¼¥É¤Ç¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤ò³«»Ï¤·¤Þ¤¹¡£
python3 finetune_adapter.py \
--data_dir data/dolly \
--checkpoint_dir checkpoints/togethercomputer/RedPajama-INCITE-Base-3B-v1 \
--out_dir out/adapter/dolly
A100 40GB GPU¤òÍøÍѤ·¤Æ2»þ´Ö¤Û¤É¤Ç¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤¬´°Î»¤·¤Þ¤·¤¿¡£
²¼µ¤Î¥³¡¼¥É¤òÆþÎϤ·¡¢¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¸å¤Î¥â¥Ç¥ë¤Ç¤Î±þÅú¤ò»î¤·¤Æ¤ß¤Þ¤¹¡£
python3 generate_adapter.py \
--adapter_path out/adapter/dolly/lit_model_adapter_finetuned.pth \
--checkpoint_dir checkpoints/togethercomputer/RedPajama-INCITE-Base-3B-v1 \
--prompt "[¤³¤³¤Ë¼ÁÌä¤òÆþÎÏ]"
Î㤨¤Ð¡¢¡Ö¥²¡¼¥à¡¦¥ª¥Ö¡¦¥¹¥í¡¼¥ó¥º¤Îºî¼Ô¤Ï¡©¡×¤È¤¤¤¦¼ÁÌä¤ò¤·¤Æ¤ß¤ë¤È²¼µ¤ÎÄ̤ê¡ÖGeorge R. R. Martin¡×¤È¤¤¤¦Åú¤¨¤¬Ê֤äƤ¤Þ¤·¤¿¡£
¥Õ¥¡¥¤¥ó¥Á¥å¡¼¥Ë¥ó¥°¤ËÍøÍѤ·¤¿¡Ödatabricks-dolly-15k¡×¥Ç¡¼¥¿¥»¥Ã¥È¤ÎÃæ¤Ë¥²¡¼¥à¥ª¥Ö¥¹¥í¡¼¥ó¥º¤Î¾ðÊ󤬴ޤޤì¤Æ¤ª¤ê¡¢¤³¤Î¾ðÊó¤ò³Ø½¬¤·¤ÆÊÖÅú¤òÀ¸À®¤·¤¿¤ï¤±¤Ç¤¹¡£
¤â¤Á¤í¤ó¡¢¥Ç¡¼¥¿¥»¥Ã¥È¤ÎÃæ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤Ê¤¤¾ðÊó¤òÀµ¤·¤¯Åú¤¨¤ë¤³¤È¤Ï¤Ç¤¤Þ¤»¤ó¡£»î¤·¤ËGIGAZINE¤Ë¤Ä¤¤¤ÆÀâÌÀ¤ò¤ª´ê¤¤¤·¤¿¤È¤³¤í¡¢¡Ö²»³Ú¤Ë¤Ä¤¤¤Æ¤Î·î´©¥Ç¥¸¥¿¥ë»¨»ï¡×¤ÈÊÖ»ö¤¬Ê֤äƤ¤Þ¤·¤¿¡£