|
| 1 | +# 💫 StarCoder QLoRA 4bit Fork |
| 2 | +I followed this guide [Making LLMs even more accessible with bitsandbytes, 4-bit quantization and QLoRA |
| 3 | +](https://huggingface.co/blog/4bit-transformers-bitsandbytes) by huggingface and implement the code in this repo |
| 4 | +to load the model in 4bit int and train using the methods outlined in the paper. |
| 5 | + |
| 6 | +To make this work you're going to need the latese accelerate, transformers, and bitsandbytes libs. |
| 7 | +``` |
| 8 | +pip install -q -U bitsandbytes |
| 9 | +pip install -q -U git+https://github.com/huggingface/transformers.git |
| 10 | +pip install -q -U git+https://github.com/huggingface/peft.git |
| 11 | +pip install -q -U git+https://github.com/huggingface/accelerate.git |
| 12 | +``` |
| 13 | + |
| 14 | +The model can beloaded in 11GB of VRAM at 4bit. |
| 15 | +``` |
| 16 | +from transformers import BitsAndBytesConfig |
| 17 | +nf4_config = BitsAndBytesConfig( |
| 18 | + load_in_4bit=True, |
| 19 | + bnb_4bit_quant_type="nf4", |
| 20 | + bnb_4bit_use_double_quant=True, |
| 21 | + bnb_4bit_compute_dtype=torch.bfloat16 |
| 22 | +) |
| 23 | +
|
| 24 | +model_nf4 = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=nf4_config) |
| 25 | +``` |
| 26 | + |
| 27 | +We add a the new optimizer to TrainingArguments() |
| 28 | +``` |
| 29 | + ... |
| 30 | + optim="paged_adamw_8bit" |
| 31 | + ... |
| 32 | +``` |
| 33 | + |
| 34 | +To utilize a second GPU for faster training we change the device map: |
| 35 | +``` |
| 36 | + device_map={"": Accelerator().process_index}, |
| 37 | +``` |
| 38 | + |
| 39 | +We launch the trainer with accelerate to make use of the second GPU. |
| 40 | +``` |
| 41 | +accelerate launch /home/gpu/code/starcoder/finetune/finetune.py --model_path=bigcode/starcoder --dataset_name=ArmelR/stack-exchange-instruction --subset=data/finetune --split=train --size_valid_set 10000 --streaming --seq_length 2600 --max_steps 1000 --batch_size 1 --input_column_name=question --output_column_name=response --save_freq=100 --learning_rate 0.0001 --lora_r 16 |
| 42 | +``` |
| 43 | + |
| 44 | + |
| 45 | + |
1 | 46 | # 💫 StarCoder |
2 | 47 |
|
3 | 48 | [Paper](https://drive.google.com/file/d/1cN-b9GnWtHzQRoE7M7gAEyivY0kl4BYs/view) | [Model](https://huggingface.co/bigcode/starcoder) | [Playground](https://huggingface.co/spaces/bigcode/bigcode-playground) | [VSCode](https://marketplace.visualstudio.com/items?itemName=HuggingFace.huggingface-vscode) | [Chat](https://huggingface.co/spaces/HuggingFaceH4/starchat-playground) |
|
0 commit comments