Added lora baseline finetune script from huggingface or anywhere #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
LoRA Fine-Tuning Script Walkthrough
This is a script fine_tune_lora.py that allows you to fine-tune a Hugging Face model using LoRA on a specified dataset.
Setup
First, you need to install the required dependencies. Since your environment is managed, it's recommended to use a virtual environment or
conda.Running the Script
You can run the script using
python fine_tune_lora.py.Arguments
--model_name_or_path: (Required) The model ID from Hugging Face (e.g.,gpt2,meta-llama/Llama-2-7b-hf).--dataset_name: (Required) The dataset name from Hugging Face (e.g.,imdb,timdettmers/openassistant-guanaco).--dataset_text_field: (Optional) The name of the column containing text data (default:text).--output_dir: (Optional) Directory to save results (default:./lora-output).--use_4bit: (Optional) Enable 4-bit quantization (requires GPU).--dataset_text_field: (Optional) The name of the column containing text data (default:text).--target_modules: (Optional) List of target modules for LoRA (default:q_projv_proj). For GPT2 usec_attn.--num_train_epochs: (Optional) Number of epochs (default: 1).Example Usage
To fine-tune
gpt2on theimdbdataset (Note:gpt2usesc_attn):To fine-tune a Llama 2 model with 4-bit quantization:
Outputs
The script will save the LoRA adapter weights and the final model configuration to the specified
output_dir.