pytorch / torchtune

A Native-PyTorch Library for LLM Fine-tuning
https://pytorch.org/torchtune/main/
BSD 3-Clause "New" or "Revised" License
3.58k stars 293 forks source link

Finetuning LLama 2 Code Instruct without using Hugging Face #826

Open sgupta1007 opened 2 months ago

sgupta1007 commented 2 months ago

I tried to finetune CodeLlama 7b Instruct by downloading weights through official repository

Folder Structure of Folder Containing CodeLlama Instruct Weights image

params.json contents image

Torch Tune Command in google colab to Run FineTuning Job Using qLoRa tune run lora_finetune_single_device --config llama2/7B_qlora_single_device checkpointer.checkpoint_dir=/llama/CodeLlama-7b-Instruct/ tokenizer.path=lama/CodeLlama-7b-Instruct/tokenizer.model checkpointer.output_dir=/content/drive/llama/ checkpointer.checkpoint_files=[consolidated.00.pth] dtype=fp 32

Issues Faced 1 num_attention_heads not found when i rename params.json to config.json 2 For unaltered codellama weighs folder i faced .config.json not found issue

How to address num_attention_heads issue ?

kartikayk commented 2 months ago

@sgupta1007 Thanks for filing this issue! Good question. So there are a couple of things going on here:

Hope this helps!

SalmanMohammadi commented 2 months ago

I picked this up, hope it's not poor ettiquette :) https://github.com/pytorch/torchtune/pull/847

SalmanMohammadi commented 2 months ago

Happy to say this is implemented @sgupta1007 :) Feel free to try and update if there's any issues, otherwise, would it be appropriate to close this issue?

sgupta1007 commented 2 months ago

@SalmanMohammadi I am still getting the error

Torchtune command and error are given below

Torchtune modified Command

!tune run lora_finetune_single_device --config llama2/7B_qlora_single_device checkpointer=torchtune.utils.FullModelMetaCheckpointer checkpointer.checkpoint_dir=/codellama-main/llama/CodeLlama-7b-Instruct/ tokenizer.path=/codellama-main/llama/CodeLlama-7b-Instruct/tokenizer.model checkpointer.output_dir=/llm/ checkpointer.checkpoint_files=[consolidated.00.pth] dtype=fp32 model=torchtune.models.llama2.code_llama2_7b

Error

ModuleNotFoundError("No module named 'torchtune.models.llama2.code_llama2_7b'")
Are you sure that 'code_llama2_7b' is importable from module 'torchtune.models.llama2'?
SalmanMohammadi commented 2 months ago

Could you try the following command?

!tune run lora_finetune_single_device --config code_llama2/7B_qlora_single_device checkpointer=torchtune.utils.FullModelMetaCheckpointer checkpointer.checkpoint_dir=/codellama-main/llama/CodeLlama-7b-Instruct/ tokenizer.path=/codellama-main/llama/CodeLlama-7b-Instruct/tokenizer.model checkpointer.output_dir=/llm/ checkpointer.checkpoint_files=[consolidated.00.pth] dtype=fp32

code_llama2 models and recipe configs are under their own folder, rather than under llama2/. I hadn't tried it with the ...MetaCheckpointer but hopefully it works. See my colab here for my examples.

sgupta1007 commented 2 months ago

@SalmanMohammadi This command gave me new eror FileNotFoundError: [Errno 2] No such file or directory: '/content/code_llama2/7B_qlora_single_device'

SalmanMohammadi commented 2 months ago

My apologies, code_llama2 isn't in the release yet! You can follow the process here to install from source to get it working. Let me know how you get on.