# Error: The model weights are not tied. Please use the \`tie\_weights\` method before using the \`infer\_auto\_device\` function, even after adding model.tie\_weights()

**URL:** <https://discuss.huggingface.co/t/error-the-model-weights-are-not-tied-please-use-the-tie-weights-method-before-using-the-infer-auto-device-function-even-after-adding-model-tie-weights/46325>\
**Category:** Beginners\
**Created:** [July 10, 2023, 7:07pm UTC](https://discuss.huggingface.co/t/error-the-model-weights-are-not-tied-please-use-the-tie-weights-method-before-using-the-infer-auto-device-function-even-after-adding-model-tie-weights/46325 "2023-07-10T19:07:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhibha](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@abhibha](https://discuss.huggingface.co/u/abhibha)\
**Post date:** [July 10, 2023, 7:07pm UTC](https://discuss.huggingface.co/t/error-the-model-weights-are-not-tied-please-use-the-tie-weights-method-before-using-the-infer-auto-device-function-even-after-adding-model-tie-weights/46325/1 "2023-07-10T19:07:48Z")

</div>

Hi,  
I am trying to use ‘[Accelerate](https://huggingface.co/docs/accelerate/usage_guides/big_modeling#sharded-checkpoints)’ for running inference on a [PMC-Llama model](https://huggingface.co/chaoyi-wu/PMC_LLAMA_7B) using a GPU and CPU.  
Here is my code,

```auto
import transformers
from accelerate import init_empty_weights
from transformers import AutoConfig, AutoModelForCausalLM

config = AutoConfig.from_pretrained("chaoyi-wu/PMC_LLAMA_7B")
with init_empty_weights():
    model = AutoModelForCausalLM.from_config(config)

from accelerate import infer_auto_device_map, init_empty_weights
model.tie_weights()
device_map = infer_auto_device_map(model)
# Getting the warning: The model weights are not tied. Please use the `tie_weights` method before using the `infer_auto_device` function.

```

I am not able to understand why I am getting this error even though I have added the statement, ‘model.tie\_weights()’  
Thank you. Any help would be highly appreciated.

---

<div class="post-metadata">

**Author:** ![Thinkcru](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/thinkcru/32/13469_2.png) [@Thinkcru](https://discuss.huggingface.co/u/Thinkcru)\
**Post date:** [July 14, 2023, 3:58am UTC](https://discuss.huggingface.co/t/error-the-model-weights-are-not-tied-please-use-the-tie-weights-method-before-using-the-infer-auto-device-function-even-after-adding-model-tie-weights/46325/2 "2023-07-14T03:58:36Z")

</div>

I had this same issue, if anything could please answer the OP question that would be super helpful!

---

<div class="post-metadata">

**Author:** ![Falah](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/falah/32/36194_2.png) [@Falah](https://discuss.huggingface.co/u/Falah)\
**Post date:** [July 14, 2023, 1:31pm UTC](https://discuss.huggingface.co/t/error-the-model-weights-are-not-tied-please-use-the-tie-weights-method-before-using-the-infer-auto-device-function-even-after-adding-model-tie-weights/46325/4 "2023-07-14T13:31:46Z")

</div>

@abhibha  
upgrading to transformers \>= 4.28.1  
!pip install transformers==4.28.1

---

<div class="post-metadata">

**Author:** ![abhibha](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@abhibha](https://discuss.huggingface.co/u/abhibha)\
**Post date:** [July 14, 2023, 9:13pm UTC](https://discuss.huggingface.co/t/error-the-model-weights-are-not-tied-please-use-the-tie-weights-method-before-using-the-infer-auto-device-function-even-after-adding-model-tie-weights/46325/5 "2023-07-14T21:13:11Z")

</div>

@Falah Thanks! I am already using transformers version - 4.30.2 . And still am getting the error.

---

<div class="post-metadata">

**Author:** ![Falah](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/falah/32/36194_2.png) [@Falah](https://discuss.huggingface.co/u/Falah)\
**Post date:** [July 15, 2023, 6:14am UTC](https://discuss.huggingface.co/t/error-the-model-weights-are-not-tied-please-use-the-tie-weights-method-before-using-the-infer-auto-device-function-even-after-adding-model-tie-weights/46325/6 "2023-07-15T06:14:25Z")

</div>

@abhibha  
u can resolve it in google colab

> **[Google Colaboratory](https://colab.research.google.com/drive/1mtbn1uw4R0AgwoqnWx5Kpd3QWZwT5TdF?usp=sharing)**

---

<div class="post-metadata">

**Author:** ![abhibha](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@abhibha](https://discuss.huggingface.co/u/abhibha)\
**Post date:** [July 22, 2023, 5:20pm UTC](https://discuss.huggingface.co/t/error-the-model-weights-are-not-tied-please-use-the-tie-weights-method-before-using-the-infer-auto-device-function-even-after-adding-model-tie-weights/46325/7 "2023-07-22T17:20:49Z")

</div>

Thanks @Falah , I tried running my code without the ‘model.tie\_weights()’ line. It still doesn’t give the warning. I tried running on google colab. Should I ignore the warning?

---

<div class="post-metadata">

**Author:** ![Falah](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/falah/32/36194_2.png) [@Falah](https://discuss.huggingface.co/u/Falah)\
**Post date:** [July 23, 2023, 10:04am UTC](https://discuss.huggingface.co/t/error-the-model-weights-are-not-tied-please-use-the-tie-weights-method-before-using-the-infer-auto-device-function-even-after-adding-model-tie-weights/46325/8 "2023-07-23T10:04:57Z")

</div>

@abhibha  
If you are sure that the warning was triggered by the presence of `model.tie_weights()`, and the warning disappears when that line is removed, then it’s likely that the warning is related to the usage of `model.tie_weights()` in your specific context.

Without knowing the specific code and the warning message you received, it’s challenging to determine the exact cause of the warning and whether it is safe to ignore. However, I can provide some general guidance:

1. **Understand the purpose of `model.tie_weights()`:**
2. **Check the documentation and version compatibility:**  
Make sure to refer to the documentation of the library or framework you are using for `model.tie_weights()`.
3. **Consider the impact on your specific use case:**  
Depending on your specific use case, tying weights may or may not be necessary. If you are achieving the desired results without using `model.tie_weights()`, and the warning disappears after removing it, it might be acceptable to leave it out. However, it’s crucial to consider the implications on your model’s performance and training process.
4. **Test and validate your results:**  
If you decide to proceed without using `model.tie_weights()`, thoroughly test your model and validate the results to ensure that it performs as expected and achieves the desired outcomes.

---

<div class="post-metadata">

**Author:** ![NitzanBar](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nitzanbar/32/24041_2.png) [@NitzanBar](https://discuss.huggingface.co/u/NitzanBar)\
**Post date:** [February 20, 2024, 8:38am UTC](https://discuss.huggingface.co/t/error-the-model-weights-are-not-tied-please-use-the-tie-weights-method-before-using-the-infer-auto-device-function-even-after-adding-model-tie-weights/46325/9 "2024-02-20T08:38:18Z")

</div>

Why post answers from chatGPT?  
This answer clearly contains no crucial information and it is not the solution to this error.

---

<div class="post-metadata">

**Author:** ![Falah](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/falah/32/36194_2.png) [@Falah](https://discuss.huggingface.co/u/Falah)\
**Post date:** [February 20, 2024, 2:02pm UTC](https://discuss.huggingface.co/t/error-the-model-weights-are-not-tied-please-use-the-tie-weights-method-before-using-the-infer-auto-device-function-even-after-adding-model-tie-weights/46325/10 "2024-02-20T14:02:29Z")

</div>

@NitzanBar  
AI Models are the only solution to all programming problems for us as system developers. because traditional methods are slow, boring, and annoying, and we do not reach results in a short time  
In your opinion, what is the solution to the problem!!! It was solved in Google Colab previously…  
I need a solution from you, please benefit from and share it
