Skip to content

Apply Cohere logit_scale in AyaVisionForConditionalGeneration - #50723

Open
ziywang50 wants to merge 3 commits into
huggingface:mainfrom
ziywang50:fix-composite-logits-scaling
Open

ziywang50 wants to merge 3 commits into
huggingface:mainfrom
ziywang50:fix-composite-logits-scaling

Conversation

@ziywang50

@ziywang50 ziywang50 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🤗 Transformers CI

What does this PR do?

AyaVisionForConditionalGeneration puts its own lm_head on top of the base text model, so the logit_scale multiplication that CohereForCausalLM / Cohere2ForCausalLM apply after their head is skipped. Measured on main with tiny configs against Cohere2ForCausalLM with the same text weights (details in #49937), AyaVision's logits are off by 16x (logit_scale=0.0625). Greedy decoding is unaffected, but sampling, beam scores, output_scores and the training loss use the wrong values.

This PR multiplies by text_config.logit_scale after lm_head, as the Cohere models do. modular_aya_vision.py now writes out forward; the regenerated modeling_aya_vision.py changes by one line.

LlavaNext has the same problem with Granite text backbones (8x off with logits_scaling=8), but there the scaling depends on the backbone (Granite divides by logits_scaling, HyperCLOVAX multiplies by it), so I'll handle it in a separate PR, following the per-model approach granite4_vision already uses.

There is no regression test in this PR yet; I can add one comparing the logits with Cohere2ForCausalLM on the same weights, as #50290 does for GraniteSpeech, if you'd like.

Part of #49937 (AyaVision only; LlavaNext will follow, and GraniteSpeech is handled in #50290).

I used an AI assistant (Claude) to help read the code and write this change.

Who can review?

@zucchini-nlp

@vasqu

vasqu commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Hey @ziywang50 you pinged pretty much every maintainer in the lib, I edited the pr description but pls be careful next time. Dw it happens but it creates unnecessary noise

cc @zucchini-nlp because I think you tried to ping her here

@ziywang50

Copy link
Copy Markdown
Contributor Author

Hey @ziywang50 you pinged pretty much every maintainer in the lib, I edited the pr description but pls be careful next time. Dw it happens but it creates unnecessary noise

cc @zucchini-nlp because I think you tried to ping her here

Sorry about that, and thanks for fixing it.

@zucchini-nlp
zucchini-nlp marked this pull request as ready for review November 17, 2026 02:35

@zucchini-nlp zucchini-nlp left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lets run slow CI but first pls rebase main and run make fix-repo

Comment on lines 260 to 261
inputs_embeds=inputs_embeds,
vision_feature_layer=vision_feature_layer,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LOL, this started in random model and seems to be copied now everywhere 😭

dw, not on you

@zucchini-nlp

Copy link
Copy Markdown
Member

fixes llava next as per your title but diff has no llava 🧐 @ziywang50

@ziywang50
ziywang50 force-pushed the fix-composite-logits-scaling branch from 4cca449 to a6a3a4a Compare November 17, 2026 18:54
@ziywang50

Copy link
Copy Markdown
Contributor Author

fixes llava next as per your title but diff has no llava 🧐 @ziywang50

Thanks, I rebased on main. The forward I added in the modular file still returned past_key_values=outputs.past_key_values after the rename to cache on main, which left modeling_aya_vision.py out of sync with it; I've updated it and checked that the converter reproduces the generated file.
I'll open a separate PR for LlavaNext.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh the modular is now visible again 😆

@zucchini-nlp

Copy link
Copy Markdown
Member

run-slow: aya_vision

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@ziywang50

Copy link
Copy Markdown
Contributor Author

run-slow: aya_vision

The AMD failure in test_small_model_integration_forward is expected from this
fix: the text config has logit_scale = 0.25, and the expected logits were
recorded without the scaling. On AMD the test falls back to the ("cuda", 8)
expectation. Dividing the actual logits by 0.25 gives values within 0.05 of
it for all 5 positions (atol is 0.1). The two generate tests fail on the base
commit with the same error, so they're unrelated.

Should I update the expectations to the old values × 0.25? I can't run the
XPU or the 4-bit ("cuda", 7) entries myself, so let me know if you'd rather
regenerate those. With the values 4x smaller, atol=0.1 also becomes looser.

pos AMD actual actual / 0.25 ("cuda", 8) expected diff
0 0.4199 1.6796 1.6396 0.040
1 0.1588 0.6352 0.6094 0.026
2 0.8071 3.2284 3.1992 0.029
3 2.1426 8.5704 8.5234 0.047
4 0.5547 2.2188 2.1875 0.031

Note: An AI Assistant was used to write this. I have ran and verified the data myself.

@zucchini-nlp

Copy link
Copy Markdown
Member

yeah, we should update them - at least the cuda expectations. For AMD feel free if you have the machine but don't feel forced

@ziywang50

Copy link
Copy Markdown
Contributor Author

yeah, we should update them - at least the cuda expectations. For AMD feel free if you have the machine but don't feel forced

Updated all three entries to the old values × logit_scale (0.25). Since 0.25
is a power of two, the scaled values are exact, so this also covers the XPU
and 4-bit entries I can't run. AMD falls back to ("cuda", 8), and the new
values are within ~0.012 of the AMD run. Could you re-trigger the slow CI?
Once it passes, is it okay for me to merge, or would you prefer to merge it yourself?

@ziywang50
ziywang50 force-pushed the fix-composite-logits-scaling branch 2 times, most recently from 08f921b to 46f86b0 Compare November 19, 2026 14:44
@zucchini-nlp

Copy link
Copy Markdown
Member

run-slow: aya_vision

@github-actions

Copy link
Copy Markdown
Contributor

CI (Nvidia + AMD)

Nvidia · ✅ No new failures 🎉👏 · ⚙️ Workflow · 📊 Dashboard

AMD · ✅ No new failures 🎉👏 · ⚙️ Workflow · 📊 Dashboard

Failures (2 pre-existing)

    Pre-existing failures (still failing) — 2 total:

        Same error (2):

        - aya_vision:
            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

@ziywang50

Copy link
Copy Markdown
Contributor Author

@zucchini-nlp the slow CI is green on both Nvidia and AMD now (only the two
pre-existing generate failures remain). Am I allowed to merge this, or would you merge this when you have time?

@zucchini-nlp

Copy link
Copy Markdown
Member

merging , thanks

@zucchini-nlp
zucchini-nlp added this pull request to the merge queue Nov 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 25, 2026
@ziywang50
ziywang50 force-pushed the fix-composite-logits-scaling branch from 46f86b0 to b0de651 Compare November 25, 2026 07:30
@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: aya_vision

@ziywang50

Copy link
Copy Markdown
Contributor Author

Changes approved

1 approving review by reviewers with write access.

1 workflow awaiting approval

This workflow requires approval from a maintainer. Learn more abo

The merge queue run failed in check_repository_consistency: main now uses image_outputs, but the forward override in modular_aya_vision.py still used image_hidden_states. I rebased on main and updated that one line; modeling_aya_vision.py is unchanged by the fix. Could you approve the workflow run and re-add it to the merge queue when you have a moment?

This branch has not been deployed

No deployments
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.

4 participants