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

Fix unsoundness in tokenizers::utils::parallelism #1492

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

albertsgarde
Copy link

@albertsgarde albertsgarde commented Apr 12, 2024

Fixes #1491 by turning static mut USED_PARALLELISM: bool into a Mutex, i.e. static USED_PARALLELISM: Mutex<bool>. This allows the value to be accessed and modified safely and avoids unsoundness. There is a slight performance penalty, but given that the variable is only modified in the context of other parallel work, it is almost certainly negligible.

This PR fails several tests, but only the tests main also fails.

The static variable `USED_PARALLELISM` was previously modified and
accessed in safe functions with no guarantee of soundness. This is fixed
by putting it into a Mutex.
@albertsgarde albertsgarde changed the title Fix unsoundness Fix unsoundness in tokenizers::utils::parallelism Apr 12, 2024
@github-actions github-actions bot added the Stale label May 13, 2024
@github-actions github-actions bot closed this May 19, 2024
@ArthurZucker ArthurZucker reopened this May 23, 2024
@ArthurZucker
Copy link
Collaborator

Hey sorry for the delay I'll try to review for next week!

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

@github-actions github-actions bot removed the Stale label May 24, 2024
@albertsgarde
Copy link
Author

@ArthurZucker I think #1532 is a superior solution, so this PR should probably just be closed

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.

Unsound use of unsafe in src/utils/parallelism.rs
3 participants