Skip to content

Fix ProphetNet forward to handle tuple encoder_outputs #39794

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Abdennacer-Badaoui
Copy link
Member

This PR fixes a bug in ProphetNet where passing encoder_outputs as a tuple to forward() would raise:

AttributeError: 'tuple' object has no attribute 'last_hidden_state'

This happens because the forward() method assumes encoder_outputs is a BaseModelOutput when provided manually, while the docstring says it can be a tuple.

Changes:

Added a check in forward():

Convert tuple encoder_outputs to BaseModelOutput format before passing to ProphetNetSeq2SeqModelOutput.

if isinstance(encoder_outputs, tuple):
    encoder_outputs = BaseModelOutput(
        last_hidden_state=encoder_outputs[0],
        hidden_states=encoder_outputs[1] if len(encoder_outputs) > 1 else None,
        attentions=encoder_outputs[2] if len(encoder_outputs) > 2 else None,
    )

@Abdennacer-Badaoui Abdennacer-Badaoui marked this pull request as draft July 30, 2025 15:55
@HuggingFaceDocBuilderDev

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.

@Abdennacer-Badaoui Abdennacer-Badaoui force-pushed the fix/prophetnet-encoder-outputs-tuple branch from cfc7455 to c6a1199 Compare July 30, 2025 17:07
Copy link
Contributor

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

run-slow: prophetnet

@Abdennacer-Badaoui Abdennacer-Badaoui force-pushed the fix/prophetnet-encoder-outputs-tuple branch from 9299165 to feb83dd Compare July 30, 2025 17:17
@Abdennacer-Badaoui Abdennacer-Badaoui marked this pull request as ready for review July 30, 2025 17:45
@github-actions github-actions bot requested a review from ArthurZucker July 30, 2025 17:45
@Rocketknight1
Copy link
Member

cc @ArthurZucker for text models

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

I think we'd rather update the docstring as it should no longer be a tuple!

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