Skip to content

Patch set_attn_implementation for Windows#43433

Merged
ArthurZucker merged 3 commits intohuggingface:mainfrom
tomaarsen:fix/windows_set_attn_implementation
Jan 23, 2026
Merged

Patch set_attn_implementation for Windows#43433
ArthurZucker merged 3 commits intohuggingface:mainfrom
tomaarsen:fix/windows_set_attn_implementation

Conversation

@tomaarsen
Copy link
Copy Markdown
Member

What does this PR do?

It patches the following on Windows devices:

from transformers import ChineseCLIPModel

model = ChineseCLIPModel.from_pretrained("OFA-Sys/chinese-clip-vit-base-patch16")
model.set_attn_implementation("eager")
print(model.config._attn_implementation)
Traceback (most recent call last):
  File "[sic]\demo_chinese_clip.py", line 4, in <module>
    model.set_attn_implementation("eager")
  File "[sic]\transformers\modeling_utils.py", line 1975, in set_attn_implementation
    if not submodule._can_set_attn_implementation():
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]\transformers\modeling_utils.py", line 1921, in _can_set_attn_implementation
    code = f.read()
           ^^^^^^^^
  File "[sic]\transformers\Lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 44039: character maps to <undefined>

With this PR in place, it simply returns:

eager

Follow-up from #42564 (comment)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@vasqu
It would be very nice to include this in the v5. This caused test failures for my work on #42564 for ChineseCLIP and AyaVision, likely as those modeling files have characters that the default Windows cp1252 encoding doesn't recognize.

  • Tom Aarsen

idem with set_experts_implementation
@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.

Copy link
Copy Markdown
Contributor

@vasqu vasqu left a comment

Choose a reason for hiding this comment

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

Can we also patch set experts at the same time? bf0ae70

LGTM otherwise, waiting for CI to stabilize first - torchcodec at it again 😢

@tomaarsen
Copy link
Copy Markdown
Member Author

Fixed, turns out my main was behind locally.

  • Tom Aarsen

@github-actions
Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=43433&sha=f9f404

@ArthurZucker ArthurZucker merged commit 388313e into huggingface:main Jan 23, 2026
16 of 25 checks passed
SangbumChoi pushed a commit to SangbumChoi/transformers that referenced this pull request Jan 23, 2026
* Patch set_attn_implementation for Windows

idem with set_experts_implementation

* Extend the fix to _can_set_experts_implementation
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