# DeepSpeed Zero 3 with LoRA - Merging adapters

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdeepspeed-zero-3-with-lora-merging-adapters%2F95730%3E%5C
**Category:** DeepSpeed\
**Created:** [July 5, 2024, 2:59pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdeepspeed-zero-3-with-lora-merging-adapters%2F95730 "2024-07-05T14:59:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![terjenf](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@terjenf](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fterjenf)%5C
**Post date:** [July 5, 2024, 2:59pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdeepspeed-zero-3-with-lora-merging-adapters%2F95730%2F1 "2024-07-05T14:59:53Z")

</div>

Hi!

I’m having troubles merging LoRA adapters trained with DeepSpeed Zero 3, using the Trainer API. The model was finetuned on a single node with 4 GPUs. I am not sure if DeepSpeed with LoRA saves the full model and/or the adapters?

The code:

```auto
tokenizer = AutoTokenizer.from_pretrained(model_id,device_map='auto',torch_dtype=torch.bfloat16)                                         
model = AutoModelForCausalLM.from_pretrained(model_id, device_map='auto', torch_dtype=torch.bfloat16)
tokenizer.pad_token = tokenizer.eos_token
model = PeftModel.from_pretrained(model, pathPeftModel)
model = model.merge_and_unload()

```

where pathPeftModel refers to the folder “checkpoint-28500”

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/9/6/963b419f1fef097366aadec59c56161b33d5c844.jpeg)

Gives following error:

```auto
  File "…/ lib/python3.11/site-packages/peft/utils/save_and_load.py", line 444, in load_peft_weights
    adapters_weights = safe_load_file(filename, device=device)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "… /lib/python3.11/site-packages/safetensors/torch.py", line 308, in load_file
    with safe_open(filename, framework="pt", device=device) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
safetensors_rust.SafetensorError: Error while deserializing header: InvalidHeaderDeserialization

```

Deepspeed config used:

```auto
compute_environment: LOCAL_MACHINE
debug: true
deepspeed_config:
  gradient_accumulation_steps: 2
  gradient_clipping: 1.0
  offload_optimizer_device: cpu
  offload_param_device: cpu
  zero3_init_flag: true
  zero3_save_16bit_model: false
  zero_stage: 3
distributed_type: DEEPSPEED
downcast_bf16: 'no'
machine_rank: 0
main_training_function: main
mixed_precision: fp16
num_machines: 1
num_processes: 4
rdzv_backend: static
same_network: true
tpu_env: []
tpu_use_cluster: false
tpu_use_sudo: false
use_cpu: false

```

---

<div class="post-metadata">

**Author:** ![tytyccj](https://avatars.discourse-cdn.com/v4/letter/t/5daacb/32.png) [@tytyccj](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ftytyccj)%5C
**Post date:** [August 16, 2024, 6:47pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdeepspeed-zero-3-with-lora-merging-adapters%2F95730%2F2 "2024-08-16T18:47:38Z")

</div>

same error, do u solve the problem?
