axolotl-ai-cloud / axolotl

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

Merge lora adaptor leads to saving the model in FP32 though base model is of FP16/BF16 #1510

Open amitagh opened 4 months ago

amitagh commented 4 months ago

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

Expected Behavior

After merge the final merged model should have been of same precision as the base model but it is FP32 this leads to size of the merged model almost doubling as compared to size of the base model.

Current behaviour

After merge the final merged model should have been of same precision as the base model but it is FP32 this leads to size of the merged model almost doubling as compared to size of the base model.

Steps to reproduce

Generate a lora adaptor.

Below is the config i used for Gemma 2B Pretraining with Lora. after pt i try to merge the adaptor generated with base model. In merged models config.json i see torch.dtype as FP32. Thus the size of merged model is 10 GB when base model is of 5GB

Config yaml

base_model: google/gemma-2b
model_type: AutoModelForCausalLM
tokenizer_type: AutoTokenizer

load_in_8bit: false
load_in_4bit: true
strict: false

datasets:
  - path: /content/test_txt_data-10exmpl.json
    type: completion
    field: text
dataset_prepared_path:
val_set_size: 0
output_dir: ./qlora-out

adapter: qlora
lora_model_dir:

sequence_len: 600
sample_packing: true
pad_to_sequence_len: true

lora_r: 64
lora_alpha: 128
lora_dropout: 0.05
lora_target_modules: 
  - q_proj
  - v_proj
  - k_proj
  - o_proj
  - gate_proj
  - down_proj
  - up_proj
#lora_modules_to_save:
#  - embed_tokens
#  - lm_head
lora_target_linear: true
lora_fan_in_fan_out:

gradient_accumulation_steps: 1
micro_batch_size: 1
num_epochs: 1
optimizer: adamw_bnb_8bit
lr_scheduler: cosine
learning_rate: 0.0002

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

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

warmup_ratio: 0.1
evals_per_epoch: 1
eval_table_size:
eval_max_new_tokens: 128
eval_sample_packing: False
saves_per_epoch: 1
debug:
deepspeed:
weight_decay: 0.0
fsdp:
fsdp_config:
special_tokens:

save_safetensors: True

Possible solution

No response

Which Operating Systems are you using?

Python Version

3.10

axolotl branch-commit

latest

Acknowledgements

amitagh commented 4 months ago

code mistake. not an issue.

amitagh commented 4 months ago

This is an issue still there. earlier i thought this is an issue with my script but it is not. axolotl is saving in FP32 at the end of pretraining with lora. Both merged model and adaptor is stored in FP32 precision though base model is in FP16.