axolotl-ai-cloud / axolotl

Go ahead and axolotl questions
https://axolotl-ai-cloud.github.io/axolotl/
Apache License 2.0
7.58k stars 822 forks source link

Fine-tuned Mistral with load_in_4bit turned out completely unusable #1336

Closed eryk-mazus closed 6 months ago

eryk-mazus commented 6 months ago

Please check that this issue hasn't been reported before.

Expected Behavior

I'm fine-tuning Mistral 7b using the dataset of 250k conversation non english conversations. I fine-tuned way smaller model (tinyllama) using axolotl on the subset of dataset, which turned out great, so there has to be something wrong with my config/fine-tuning/adapter merging. I'd be helpful for help.

Current behaviour

After merging the adapter using python3 -m axolotl.cli.merge_lora path_to_config I tried to generate output on some simple prompt. The model returns weird string of characters like WWWWWWWW, white spaces, etc.

Steps to reproduce

Here is the config that I'm using:

Config yaml

#Mistral-7b
base_model: mistralai/Mistral-7B-v0.1
model_type: MistralForCausalLM
tokenizer_type: LlamaTokenizer

load_in_8bit: false
load_in_4bit: true
strict: false

datasets:
  - path: path_to_dataset
    ds_type: json
    type: sharegpt
    conversation: chatml

dataset_prepared_path: /workspace/last_run_prepared
val_set_size: 0.05
output_dir: /workspace/out/

chat_template: chatml
default_system_message: You're helpful assistant.

special_tokens:
  eos_token: '<|im_end|>'

tokens:
    - '<|im_start|>'
    - '<|im_end|>'

sequence_len: 4096
sample_packing: false
pad_to_sequence_len: true

adapter: lora
lora_model_dir:
lora_r: 8
lora_alpha: 16
lora_dropout: 0.05
lora_target_linear: true
lora_fan_in_fan_out:
lora_modules_to_save:
 - embed_tokens
 - lm_head

wandb_project: 
wandb_entity:
wandb_watch:
wandb_name:
wandb_log_model:

gradient_accumulation_steps: 2
micro_batch_size: 8
num_epochs: 2
optimizer: adamw_bnb_8bit
lr_scheduler: cosine
learning_rate: 0.0003
cosine_min_lr_ratio: 0.1

train_on_inputs: false
group_by_length: false
bf16: true
fp16: false
tf32: false

gradient_checkpointing: true
early_stopping_patience:
resume_from_checkpoint:
local_rank:
logging_steps: 1
xformers_attention:
flash_attention: true

warmup_steps: 10

evals_per_epoch: 3
eval_max_new_tokens: 128
saves_per_epoch: 1

debug:
deepspeed: ./deepspeed_configs/zero3_bf16.json
weight_decay: 0.0
fsdp:
fsdp_config:

Possible solution

Do my lora settings make sense ? Do I set the tokens/special tokens correctly ?

Which Operating Systems are you using?

Python Version

3.10

axolotl branch-commit

main

Acknowledgements

NanoCode012 commented 6 months ago

I noticed that, you're doing load_in_4bit but training a lora instead of qlora. Perhaps a typo?

eryk-mazus commented 6 months ago

So, I thought it was just a typo that broken something, but I retrained the model with load_in_4bit: true and adapter: qlora and initially got the same garbage as before. But, what I discovered is that when I create the input as string instead of using tokenizer.apply_chat_template (same as here) the model starts to produce the correct output.

I will investigate this further, but I wanted to write it here in case someone encounters the same issue

NanoCode012 commented 6 months ago

The chat template is still a new feature, only a few are supported. if you're training a template different from base model, you'll need to set it yourself usually.