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

[LLAVA-NEXT] Warning: The model weights are not tied. Please use the tie_weightsmethod before using the infer_auto_device function. #30001

Closed
2 of 4 tasks
aliencaocao opened this issue Apr 2, 2024 · 8 comments

Comments

@aliencaocao
Copy link
Contributor

aliencaocao commented Apr 2, 2024

System Info

  • transformers version: 4.40.0.dev0
  • Platform: Linux-5.19.0-051900rc6-generic-x86_64-with-glibc2.35
  • Python version: 3.9.18
  • Huggingface_hub version: 0.21.1
  • Safetensors version: 0.4.2
  • Accelerate version: 0.28.0
  • Accelerate config: not found
  • PyTorch version (GPU?): 2.4.0.dev20240326+cu121 (True)
  • Tensorflow version (GPU?): not installed (NA)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Using GPU in script?: yes
  • Using distributed or parallel set-up in script?: no

Who can help?

@amyeroberts

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

from transformers import LlavaNextForConditionalGeneration
model = LlavaNextForConditionalGeneration.from_pretrained('panoyo9829/llava-v1.6-mistral-7b-bnb-4bit', low_cpu_mem_usage=True, device_map='auto')

Running this will yield a The model weights are not tied. Please use the tie_weightsmethod before using theinfer_auto_device function. warning. Inference result seems correct though, but I'm not sure if the warning should still be paid attention to.

Expected behavior

No warning

@aliencaocao aliencaocao mentioned this issue Apr 2, 2024
1 task
@amyeroberts
Copy link
Collaborator

Hi @aliencaocao, thanks for opening this issue!

I'm unable to replicate this error when running the snippet on main.

The checkpoint in the example panoyo9829/llava-v1.6-mistral-7b-bnb-4bit doesn't appear to be one compatible with a model in the transformers library.

It maps to LlavaMistralForCausalLM which isn't defined in transformers.

When running the snippet, the warning I get is about weights in the model being randomly initialized.

@aliencaocao
Copy link
Contributor Author

I can reproduce this with the original untouched fp16 model as long as I use device_map:

from transformers import LlavaNextForConditionalGeneration
model = LlavaNextForConditionalGeneration.from_pretrained('llava-hf/llava-v1.6-mistral-7b-hf', low_cpu_mem_usage=True, device_map='auto')

image
I can repro in fresh colab using latest main branch too: https://colab.research.google.com/drive/1pKm8yQ2JBfeQmFQbXgFNoozfSAckEgJu?usp=sharing

Note the notebook cannot be executed as it OOM RAM when loading fp16 weights. Notheless, the warning still came out:
image
It might be better for accelerate to resolve this issue though, since warning come from it. Feel free to close this if you think it is not a transformers issue.

@amyeroberts
Copy link
Collaborator

Thanks for sharing the details.

The error indicates that the check_tied_parameters_in_config(model) for the model is evaluating as True.

@muellerzr Any suggestion on how to handle this? The warning indicates calling model.tie_weights(), but it's not obvious how this is supposed to be done if we're loading with from_pretrained and device_map="auto"

@aliencaocao aliencaocao changed the title Warning: The model weights are not tied. Please use the tie_weightsmethod before using theinfer_auto_device function. when loading llava-next bnb 4 bit [LLAVA-NEXT] Warning: The model weights are not tied. Please use the tie_weightsmethod before using theinfer_auto_device function. Apr 4, 2024
@aliencaocao aliencaocao changed the title [LLAVA-NEXT] Warning: The model weights are not tied. Please use the tie_weightsmethod before using theinfer_auto_device function. [LLAVA-NEXT] Warning: The model weights are not tied. Please use the tie_weightsmethod before using the infer_auto_device function. Apr 4, 2024
Copy link

github-actions bot commented May 3, 2024

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.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@aliencaocao
Copy link
Contributor Author

issue still there

@LysandreJik
Copy link
Member

@SunMarc if you have a second to check this :)

@SunMarc
Copy link
Member

SunMarc commented May 3, 2024

Hi @aliencaocao, the above PR should fix this. This happens because a config attribute was not set correctly but there was no impact apart from triggering a warning message.
@amyeroberts We shouldn't get this warning at all since in from_pretained(), we make sure to call tie_weights before infer_auto_device_map. In this case, the issue was that the tie_word_embedding was incorrectly set in the config of the model.

@aliencaocao
Copy link
Contributor Author

there was no impact apart from triggering a warning message.

Glad to have that confirmation.

Thanks for the fix! Would not have noticed this as I also checked the source code and saw the tie_weights call too.

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

4 participants