Skip to content

Conversation

@echarlaix
Copy link
Collaborator

Since #35911, some models with a sequence classification head will be exported to ONNX with an ArgMax operator in int64, making the resulting model incompatible with ORT. Here we set token_indices to int32, fixing :

NOT_IMPLEMENTED : Could not find an implementation for ArgMax(13) node with name '/ArgMax'

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

@echarlaix
Copy link
Collaborator Author

@ArthurZucker @Rocketknight1 let me know if that works for you

Copy link
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Ah, I wrote this code, but I didn't realize this would cause an issue for ONNX! The change is fine, since the output should be identical regardless.

We could also consider updating the line

pooled_logits = logits[torch.arange(batch_size, device=logits.device), last_non_pad_token]

to

pooled_logits = logits[torch.arange(batch_size, device=logits.device, dtype=torch.int32), last_non_pad_token]

I don't think it's strictly necessary, but if we don't do this then the indexing will use an int64 tensor for one dimension and an int32 tensor for another dimension. That works fine on Torch right now, but it seems like the kind of thing that might break in other frameworks or when the model is exported.

@Rocketknight1
Copy link
Member

(If you don't want to do that, though, we can just merge this PR as-is. The change I suggested is just future-proofing rather than strictly necessary!)

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.

LGTM anyways

@Rocketknight1
Copy link
Member

Yeah, let's just merge this as-is! If the int64/int32 inputs thing becomes a problem when exporting later we can fix it then.

@Rocketknight1 Rocketknight1 merged commit 055afdb into huggingface:main Mar 20, 2025
23 checks passed
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 14, 2025
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