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

Clean up utils.hub using the latest from hf_hub #18857

Merged
merged 4 commits into from
Sep 2, 2022
Merged

Clean up utils.hub using the latest from hf_hub #18857

merged 4 commits into from
Sep 2, 2022

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented Sep 1, 2022

What does this PR do?

This PR uses the newly released version of hugginface_hub to clean up a few things introduced in #18438 (points 1 and 2 in the description of this PR). For point 3 (load from cache) there is currently a difference between Transformers' try_to_load_from_cache and the huggingface_hub's one, so this will a follow-up PR in huggingface_hub (and then to wait for the next release).

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 1, 2022

The documentation is not available anymore as the PR was closed or merged.

_ = AutoConfig.from_pretrained(TINY_MODEL, force_download=True)
mock_tqdm.assert_called()
enable_progress_bar()
assert not are_progress_bars_disabled()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did not manage to adapt this test with mock since:

  • the tqdm from huggingface_hub.file_download is always called
  • the calls to tqdm.auto.tqdm are not detected anymore
    If someone has a genius idea, happy to hear!

Copy link
Contributor

Choose a reason for hiding this comment

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

In huggingface_hub I test that by using the capsys fixture from pytest that catch the output while running the tests. Then you can check if the output stayed quiet or if you have progress bars in it.

You can have a look here for the setup and here for a test where tqdm is enabled.

However from transformers's point of view, this is a job done by an external library (huggingface_hub) so testing it here would be a duplicate of what is already tested. It's would not be wrong to test it but the current test you wrote is good enough I think 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

And in general, are transformers's _tqdm_active and _tqdm_cls used anywhere now ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No they're not used anywhere now (we do use tqdm in other places, so should switch to the one in logging, but probably for another PR).

Comment on lines 400 to 401
except ValueError:
# We try to see if we have a cached version (not up to date):
Copy link
Contributor

Choose a reason for hiding this comment

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

Here to be more precise you can use except LocalEntryNotFoundError.

And since the newly introduced exception is defined as (EntryNotFoundError, FileNotFoundError, ValueError), you will never catch it because you catch EntryNotFoundError line 382 above.

    except EntryNotFoundError:
        if not _raise_exceptions_for_missing_entries:
            return None
        if revision is None:
            revision = "main"
        raise EnvironmentError(
            f"{path_or_repo_id} does not appear to have a file named {full_filename}. Checkout "
            f"'https://huggingface.co/{path_or_repo_id}/{revision}' for available files."
        )

In the end, I suggest to use except LocalEntryNotFoundError: instead of except ValueError: and to reorder the except (...).

(Here is a link to the doc.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point! Will adapt.

_ = AutoConfig.from_pretrained(TINY_MODEL, force_download=True)
mock_tqdm.assert_called()
enable_progress_bar()
assert not are_progress_bars_disabled()
Copy link
Contributor

Choose a reason for hiding this comment

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

In huggingface_hub I test that by using the capsys fixture from pytest that catch the output while running the tests. Then you can check if the output stayed quiet or if you have progress bars in it.

You can have a look here for the setup and here for a test where tqdm is enabled.

However from transformers's point of view, this is a job done by an external library (huggingface_hub) so testing it here would be a duplicate of what is already tested. It's would not be wrong to test it but the current test you wrote is good enough I think 👍

_ = AutoConfig.from_pretrained(TINY_MODEL, force_download=True)
mock_tqdm.assert_called()
enable_progress_bar()
assert not are_progress_bars_disabled()
Copy link
Contributor

Choose a reason for hiding this comment

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

And in general, are transformers's _tqdm_active and _tqdm_cls used anywhere now ?

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.

Looks good to me!

@sgugger sgugger merged commit 38c3cd5 into main Sep 2, 2022
@sgugger sgugger deleted the bump_hf_hub branch September 2, 2022 14:30
oneraghavan pushed a commit to oneraghavan/transformers that referenced this pull request Sep 26, 2022
* Clean up utils.hub using the latest from hf_hub

* Adapt test

* Address review comment

* Fix test
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