Fix weight tying logic between `_tied_weights_keys` and `tie_word_embeddings`
Author: molbap
Pull request: yes
Labels: name: for_v5?

# What does this PR do?


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42385). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

run-slow: mistral

This comment contains `run-slow`, running the specified jobs: 

models: ["models/mistral"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19665955144)

✅ No failing test specific to this PR 🎉 !


run-slow: mistral3

This comment contains `run-slow`, running the specified jobs: 

models: ["models/mistral3"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19667363854)

### Model CI Report

#### ❌ Failed tests

- [mistral3](https://github.com/huggingface/transformers/actions/runs/19667363854/job/56328119950):
    tests/models/mistral3/test_modeling_mistral3.py::Mistral3ModelTest::test_config



run-slow: mistral, mistral3

This comment contains `run-slow`, running the specified jobs: 

models: ["models/mistral", "models/mistral3"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19670009686)

### Model CI Report

#### ❌ Failed tests

- [mistral3](https://github.com/huggingface/transformers/actions/runs/19670009686/job/56336842185):
    tests/models/mistral3/test_modeling_mistral3.py::Mistral3ModelTest::test_config



run-slow: olmoe

This comment contains `run-slow`, running the specified jobs: 

models: ["models/olmoe"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19672753808)

✅ No failing test specific to this PR 🎉 !


run-slow: olmoe, mistral, mistral3

This comment contains `run-slow`, running the specified jobs: 

models: ["models/mistral", "models/mistral3", "models/olmoe"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19675720958)

✅ No failing test specific to this PR 🎉 !


run-slow: olmoe, mistral, mistral3, phi3, starcoder

This comment contains `run-slow`, running the specified jobs: 

models: ["models/mistral", "models/mistral3", "models/olmoe", "models/phi3"]
quantizations: []

run-slow: olmoe, mistral, mistral3, phi3, starcoder, bigbird, bigbird_pegasus

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19677553281)

⚠️ No test being reported (jobs are skipped or cancelled)!


This comment contains `run-slow`, running the specified jobs: 

models: ["models/bigbird_pegasus", "models/mistral", "models/mistral3", "models/olmoe", "models/phi3"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19678066579)

✅ No failing test specific to this PR 🎉 !


run-slow: olmoe, mistral, mistral3, phi3, starcoder, bigbird, bigbird_pegasus, whisper, internvl, llava, llava_next, llava_next_video, qwen

This comment contains `run-slow`, running the specified jobs: 

models: ["models/bigbird_pegasus", "models/internvl", "models/llava", "models/llava_next", "models/llava_next_video", "models/mistral", "models/mistral3", "models/olmoe", "models/phi3", "models/whisper"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19678522040)

✅ No failing test specific to this PR 🎉 !


> Looks good, I think we can also check when we read config.json if the tie_word_embeddings is None maybe we should put it to False?

Sounds reasonable to me, putting this

run-slow: olmoe, mistral, mistral3, phi3, starcoder, bigbird, bigbird_pegasus, whisper, internvl, llava, llava_next, llava_next_video, qwen, fsmt

This comment contains `run-slow`, running the specified jobs: 

models: ["models/bigbird_pegasus", "models/fsmt", "models/internvl", "models/llava", "models/llava_next", "models/llava_next_video", "models/mistral", "models/mistral3", "models/olmoe", "models/phi3", "models/whisper"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19685364855)

✅ No failing test specific to this PR 🎉 !


run-slow: olmoe, mistral, mistral3, phi3, starcoder, bigbird, bigbird_pegasus, whisper, internvl, llava, llava_next, llava_next_video, qwen, fsmt, video_llava, deepseek_v3

This comment contains `run-slow`, running the specified jobs: 

models: ["models/bigbird_pegasus", "models/deepseek_v3", "models/fsmt", "models/internvl", "models/llava", "models/llava_next", "models/llava_next_video", "models/mistral", "models/mistral3", "models/olmoe", "models/phi3", "models/video_llava", "models/whisper"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19701071564)

✅ No failing test specific to this PR 🎉 !


**[For maintainers]** Suggested jobs to run (before merge)

run-slow: fsmt

run-slow: olmoe, mistral, mistral3, phi3, starcoder, bigbird, bigbird_pegasus, whisper, internvl, llava, llava_next, llava_next_video, qwen, fsmt, video_llava, deepseek_v3, qwen3_vl_moe

This comment contains `run-slow`, running the specified jobs: 

models: ["models/bigbird_pegasus", "models/deepseek_v3", "models/fsmt", "models/internvl", "models/llava", "models/llava_next", "models/llava_next_video", "models/mistral", "models/mistral3", "models/olmoe", "models/phi3", "models/qwen3_vl_moe", "models/video_llava", "models/whisper"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19705206966)

✅ No failing test specific to this PR 🎉 !


**[For maintainers]** Suggested jobs to run (before merge)

run-slow: fsmt

I removed the fallback to parent config in case `tie_word_embeddings` is not found in the text. I also attempted to add a test, might be a bit overkill, let's see 

A remaining headscratcher is `tie_encoder_decoder` which is now redundant. I did a fallback that looks like 
```python
should_tie = tie_encoder_decoder if tie_word_embeddings is None else tie_word_embeddings
```
and it seems to work/keep the key as source of authority. LMK!


**[For maintainers]** Suggested jobs to run (before merge)

run-slow: fsmt, kyutai_speech_to_text, musicgen, musicgen_melody

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: fsmt, kyutai_speech_to_text, musicgen, musicgen_melody

> A remaining headscratcher is tie_encoder_decoder which is now redundant. I did a fallback that looks like

CMIIW, `tie_encoder_decoder` means tying all weights from encoder to decoder, i.e. attention and stuff isn't it? In which case 

`tie_encoder_decoder = config.tie_encoder_decoder if config.is_encoder_decoder else False`?

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: fsmt, kyutai_speech_to_text, musicgen, musicgen_melody

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: fsmt, kyutai_speech_to_text, llava_onevision, musicgen, musicgen_melody

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: fsmt, kyutai_speech_to_text, llava_next_video, llava_onevision, musicgen, musicgen_melody

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: fsmt, kyutai_speech_to_text, llava_next_video, llava_onevision, musicgen, musicgen_melody