Skip to content

fix(models): Add tie_word_embeddings parameter to AyaVisionConfig for proper weight tying - #43455

Merged
ArthurZucker merged 1 commit into
huggingface:mainfrom
harshaljanjani:fix/aya-vision-weight-tying
Jan 24, 2026
Merged

ArthurZucker merged 1 commit into
huggingface:mainfrom
harshaljanjani:fix/aya-vision-weight-tying

Conversation

@harshaljanjani

@harshaljanjani harshaljanjani commented Jan 23, 2026 •

Copy link
Copy Markdown
Contributor

What does the PR do?

Fixes weight tying between lm_head and embed_tokens by exposing tie_word_embeddings at the top-level config, following the canonical repo pattern. Upon inspecting both presets from the AyaVision collection, both presets have text_config.tie_word_embeddings set to True, but this was not being surfaced on the top-level config.

from transformers import AutoConfig

models = [
    "CohereForAI/aya-vision-32b",
    "CohereLabs/aya-vision-8b",
]
for model_id in models:
    config = AutoConfig.from_pretrained(model_id)
    print(f"{model_id} tie_word_embeddings:", config.text_config.tie_word_embeddings)

Fixes #43454.

Output:

CohereForAI/aya-vision-32b tie_word_embeddings: True
CohereLabs/aya-vision-8b tie_word_embeddings: True

Accordingly, I’ve added tie_word_embeddings to AyaVisionConfig, with its default value set to True. As a consequence, the CI failures are also fixed. Run the following command to check the previously failing tests, which should now pass after the weight tying.

!RUN_SLOW=1 pytest -v tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_batched_generate tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_batched_generate_multi_image tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_forward tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_generate_chat_template tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_generate_text_only -s

Before submitting

@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: aya_vision

@harshaljanjani
harshaljanjani marked this pull request as ready for review January 23, 2026 18:43
@harshaljanjani

Copy link
Copy Markdown
Contributor Author

Just a slight comment on this fix -- I ran this in the venv listed in the issue (NVIDIA L4).

!RUN_SLOW=1 pytest -v tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_batched_generate tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_batched_generate_multi_image tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_forward tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_generate_chat_template tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_generate_text_only -s

And it does produce perfectly comprehensible outputs after the fix, but there are negligible differences between the output shown in my environment and the expected output; I suspect this is due to minor hardware precision issues, so I haven’t added those changes to the PR yet. If those test failures show up when run in this environment as well, I’ll add them, but they no longer produce gibberish so yeah :)

Output from my environment (env specifications listed in the issue):

tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_batched_generate_multi_image FAILED
tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_forward PASSED
tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_generate_chat_template PASSED
tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_generate_text_only FAILED
=================================== FAILURES ===================================
_ AyaVisionIntegrationTest.test_small_model_integration_batched_generate_multi_image _
       AssertionError: 'Wooden path to water,\nMountains echo in stillness,\nPeaceful forest scene.' != 'Wooden path to water,\nMountains echo in stillness,\nPeaceful forest lake.'
         Wooden path to water,
         Mountains echo in stillness,
       - Peaceful forest scene.?                 ^^^^
       + Peaceful forest lake.?                 ^^^
        : Decoded output: Wooden path to water,
       Mountains echo in stillness,
       Peaceful forest scene.
       Expected output: Wooden path to water,
       Mountains echo in stillness,
       Peaceful forest lake.
tests/models/aya_vision/test_modeling_aya_vision.py:481: AssertionError
___ AyaVisionIntegrationTest.test_small_model_integration_generate_text_only ___
AssertionError: "Whis[14 chars]eeze,\nLeaves dance under moonlit sky,\nNature's quiet song." != "Whis[14 chars]eeze,\nLeaves dance under moonlit skies,\nNature's quiet song."
         Whispers on the breeze,
       - Leaves dance under moonlit sky,
       ?                              ^
       + Leaves dance under moonlit skies,
       ?                              ^^^
         Nature's quiet song.
tests/models/aya_vision/test_modeling_aya_vision.py:318: AssertionError
=========================== short test summary info ============================
FAILED tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_batched_generate_multi_image - AssertionError: 'Wooden path to water,\nMountains echo in stillness,\nPeace...
FAILED tests/models/aya_vision/test_modeling_aya_vision.py::AyaVisionIntegrationTest::test_small_model_integration_generate_text_only - AssertionError: "Whis[14 chars]eeze,\nLeaves dance under moonlit sky,\nNatu...
================== 2 failed, 3 passed, 39 warnings in 58.59s ===================

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, errors are expected from different hardwares

@ArthurZucker
ArthurZucker merged commit c76c197 into huggingface:main Jan 24, 2026
18 checks passed
@harshaljanjani
harshaljanjani deleted the fix/aya-vision-weight-tying branch January 24, 2026 18:24
@harshaljanjani

Copy link
Copy Markdown
Contributor Author

@ArthurZucker Thanks for the review! I was wondering if you might also be able to take a look at this PR whenever you have time. It’s a long standing feature request, and it’s been quite some time since I raised a PR for it since September (with a few follow-up pings); I’d really appreciate it, thank you 🙏

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

Successfully merging this pull request may close these issues.

[BUG] AyaVisionConfig fails to tie lm_head weights causing garbage text generation

2 participants