Skip to content

Conversation

qgallouedec
Copy link
Member

from transformers.modeling_outputs import CausalLMOutputWithPast
from accelerate.utils import convert_to_fp32
import torch

lm_output = CausalLMOutputWithPast(logits=torch.ones(2, 3, 4))
print(convert_to_fp32(lm_output))

before:

CausalLMOutputWithPast(loss={'logits': tensor([[[1., 1., 1., 1.],
         [1., 1., 1., 1.],
         [1., 1., 1., 1.]],

        [[1., 1., 1., 1.],
         [1., 1., 1., 1.],
         [1., 1., 1., 1.]]])}, logits=tensor([[[1., 1., 1., 1.],
         [1., 1., 1., 1.],
         [1., 1., 1., 1.]],

        [[1., 1., 1., 1.],
         [1., 1., 1., 1.],
         [1., 1., 1., 1.]]]), past_key_values=None, hidden_states=None, attentions=None)

after

CausalLMOutputWithPast(loss=None, logits=tensor([[[1., 1., 1., 1.],
         [1., 1., 1., 1.],
         [1., 1., 1., 1.]],

        [[1., 1., 1., 1.],
         [1., 1., 1., 1.],
         [1., 1., 1., 1.]]]), past_key_values=None, hidden_states=None, attentions=None)

@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.

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

Indeed, thanks for the fix !

@SunMarc SunMarc merged commit 3db9fb6 into main Sep 18, 2025
26 of 29 checks passed
@SunMarc SunMarc deleted the fix-recursively-apply branch September 18, 2025 13:18
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