Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapter weights are cast in float16 unexpectedly after load_adapter #1090

Closed
2 of 4 tasks
hiyouga opened this issue Nov 7, 2023 · 1 comment
Closed
2 of 4 tasks

Comments

@hiyouga
Copy link
Contributor

hiyouga commented Nov 7, 2023

System Info

Ubuntu + NVIDIA V100

transformers 4.34.1
peft 0.6.0

Who can help?

@pacman100 @younesbelkada

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder
  • My own task or dataset (give details below)

Reproduction

from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

tok = AutoTokenizer.from_pretrained("llama2-7b")
model = AutoModelForCausalLM.from_pretrained("llama2-7b", torch_dtype="auto", device_map="auto")

adapter_model = PeftModel.from_pretrained(model, "lora_weight", is_trainable=True)
for name, param in adapter_model.named_parameters():
    print(name, param.dtype) 

"""
base_model.model.model.layers.31.self_attn.v_proj.weight torch.float16
base_model.model.model.layers.31.self_attn.v_proj.lora_A.default.weight torch.float32 (correct)
base_model.model.model.layers.31.self_attn.v_proj.lora_B.default.weight torch.float32
"""

adapter_model.load_adapter("another_lora_weight", "reward", is_trainable=True)
for name, param in adapter_model.named_parameters():
    print(name, param.dtype)

"""
base_model.model.model.layers.31.self_attn.v_proj.weight torch.float16
base_model.model.model.layers.31.self_attn.v_proj.lora_A.default.weight torch.float16 (incorrect)
base_model.model.model.layers.31.self_attn.v_proj.lora_A.reward.weight torch.float16
base_model.model.model.layers.31.self_attn.v_proj.lora_B.default.weight torch.float16
base_model.model.model.layers.31.self_attn.v_proj.lora_B.reward.weight torch.float16
"""

Besides, add_adapter also triggers a similar problem for peft 0.6.0.

Expected behavior

The data type of adapter weights after load_adapter should remain float32

Copy link

github-actions bot commented Dec 7, 2023

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

@hiyouga hiyouga closed this as not planned Won't fix, can't repro, duplicate, stale Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant