Skip to content
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

[SwitchTransformers] Fix return values #24300

Merged
merged 5 commits into from
Jun 16, 2023

Conversation

ArthurZucker
Copy link
Collaborator

What does this PR do?

The previous version of the code would always return None values for the router losses, since the if output_router_probs was wrapper around if labels is not None. But router logits can still be computed wthout labels.
Also returns tensors instead of None, this follows our usual API, and is less prone to errors.

Comment on lines -1690 to -1693
encoder_router_logits, encoder_expert_indexes = self._unpack_router_logits(
encoder_outputs.router_probs
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

encoder_outputs.router_probs cannot be accessed if return_dict = False

Comment on lines -1721 to -1727
*decoder_outputs[1:],
*encoder_outputs,
)
else:
output += (*decoder_outputs[1:], *encoder_outputs)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just reduce used lines

@@ -1736,18 +1723,18 @@ def forward(
decoder_hidden_states=decoder_outputs.hidden_states,
decoder_attentions=decoder_outputs.attentions,
cross_attentions=decoder_outputs.cross_attentions,
decoder_router_logits=decoder_outputs.router_probs,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

make order of return consistent with tuples

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 15, 2023

The documentation is not available anymore as the PR was closed or merged.

@ArthurZucker ArthurZucker requested a review from sgugger June 16, 2023 09:04
Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes!

@ArthurZucker ArthurZucker merged commit ba3fb4b into huggingface:main Jun 16, 2023
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.

3 participants