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

Fixes for Modular Converter on Windows #34266

Merged
merged 5 commits into from
Oct 29, 2024

Conversation

hlky
Copy link
Contributor

@hlky hlky commented Oct 20, 2024

What does this PR do?

This PR fixes some issues with Modular Converter on Windows.

  1. Relative path regex. rf"(src{os.sep}transformers{os.sep}.*|examples{os.sep}.*)" results in (src\transformers\.*|examples\.*), due to \t and \. this regex fails, we replace \ on os.path.abspath instead, and use (src/transformers/.*|examples/.*) as the regex.
    2. Relative path in auto generated message. On Windows this generates as This file was automatically generated from src\transformers\models\florence2\modular_florence2.py. This could potentially cause issues elsewhere, and it's better to be standardized, so when os.sep == \ we replace os.sep with /.
  2. open encoding. On Windows the default encoding is cp1252 which doesn't work with 🚨, so we use encoding=utf-8 instead for all open. This particular fix is in effect in many other places in the codebase.

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@ArthurZucker

@hlky
Copy link
Contributor Author

hlky commented Oct 20, 2024

Please note the test failure here is unrelated, looks like modeling_glm needs to be overwritten with modular generated code.

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 maybe using os.path will simplify the separation! 🤗

relative_path = re.search(
rf"(src{os.sep}transformers{os.sep}.*|examples{os.sep}.*)", os.path.abspath(modular_file)
rf"(src{sep}transformers{sep}.*|examples{sep}.*)", os.path.abspath(modular_file)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we'd better use os.path.join no? This would directly support correct separation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the same separation as os.sep with os.path.join. This is a python/regex issue due to the combination of raw and formatted.

An alternate solution would be replacing \\ on os.path.abspath, then regex can just use /:

relative_path = re.search(
    r"(src/transformers/.*|examples/.*)", os.path.abspath(modular_file).replace("\\", "/")
).group(1)

Copy link
Collaborator

Choose a reason for hiding this comment

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

looks simpler let's go with this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks!

@hlky hlky force-pushed the modular-converter-windows branch from 6b8b5ae to c47af79 Compare October 24, 2024 16:38
@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.

@ArthurZucker ArthurZucker merged commit 9e3d704 into huggingface:main Oct 29, 2024
9 checks passed
@ArthurZucker
Copy link
Collaborator

Thanks for your contribution!

BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
* Separator in regex

* Standardize separator for relative path in auto generated message

* open() encoding

* Replace `\` on `os.path.abspath`

---------

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants