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

Do not fail on touch() if OSError (to cache non existence of file) #2505

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Sep 3, 2024

Related to this thread on slack (private link).

When trying to download a file, if the file does not exist on the Hub, we cache this information by creating an empty file under the ./no-exists folder. This is used in transformers to avoid requesting a given file each time the pipeline is reloaded. The only purpose of this file is to save a HEAD call on initialization. @ydshieh and @glegendre01 have found out that Path.touch() raises a PermissionError when used on a S3-mounted drive if the file already exists. This PR adds a try/catch block to ignore such failures.

EDIT: I've checked and it's the only occurrence where we use .touch() on a potentially existing file.

@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

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Ok makes sense! Hard to add a test for this I think

@Wauplin
Copy link
Contributor Author

Wauplin commented Sep 3, 2024

I think @ydshieh is currently testing it on a live S3 mounted drive in a CI to make sure we are solving their problem. Unit testing is not worth it IMO

@ydshieh
Copy link
Contributor

ydshieh commented Sep 3, 2024

Yes, let me check and give update here later.

Comment on lines +1751 to +1756
try:
no_exist_file_path.touch()
except OSError as e:
logger.error(
f"Could not cache non-existence of file. Will ignore error and continue. Error: {e}"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The current issue we have is that we can't touch (with S3) if this file exists.

This change here solves that issue (I confirmed with CI), but it's more general (i.e. whenever there is an OSSError no matter what cuases it).

Should we check if the file exists anyway just after this block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No I don't think so. As I mentioned in the PR description, this file exists only to save a HEAD call so it's a very optional optimization. If it fails because of a filesystem-specific issue then it's not a problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks!

@ydshieh
Copy link
Contributor

ydshieh commented Sep 3, 2024

Checked with CI and the previous failing test like

tests/models/auto/test_configuration_auto.py::AutoConfigTest::test_configuration_not_found

(on new cluster/cache system) now passes.

@Wauplin
Copy link
Contributor Author

Wauplin commented Sep 3, 2024

Thanks for confirming! I'll merge it then :)

@Wauplin Wauplin merged commit 36bc497 into main Sep 3, 2024
19 checks passed
@Wauplin Wauplin deleted the do-not-fail-on-touch-if-fails branch September 3, 2024 15:10
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.

5 participants