-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[RFC] Contrib test suite + tests for timm and sentence_transformers #1200
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f22d1cb
First draft for a contrib test suite + test for timm contrib
Wauplin fc1da54
run only Python 3.8
Wauplin 24427d3
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin 64185aa
remove commented code
Wauplin 572ca56
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin e4766a7
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin af45cdb
Run contrib tests in separate environments
Wauplin 821aa04
fix ci
Wauplin 2a0d7c6
fix ci again
Wauplin 339af7f
and now ?
Wauplin 68c26b2
stupid me
Wauplin 1eb0a09
this time ?
Wauplin d4a72e7
Refactor how to run contrib tests locally
Wauplin aa1ffad
add tests for sentence_transformers
Wauplin 930c29e
amke style
Wauplin 625768d
Update contrib/README.md
Wauplin 7b28a5f
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin 987ec8a
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin 12aa4ba
ADapt timm tests
Wauplin 173aff8
Include feedback form osanseviero
Wauplin cd11be8
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin b148848
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin d8ddba6
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin f20ab77
script to check contrib list is accurate
Wauplin d5949fa
Use [testing] requirements as contrib common dependencies
Wauplin 6cb96e7
add check_contrib_list in github workflow
Wauplin b299077
code qualiry
Wauplin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| name: Contrib tests | ||
|
|
||
| on: workflow_dispatch | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - name: Set up Python 3.8 | ||
| uses: actions/setup-python@v2 | ||
| with: | ||
| python-version: 3.8 | ||
|
|
||
| # Install huggingface_hub | ||
| - name: Install `huggingface_hub` | ||
| run: | | ||
| pip install --upgrade pip | ||
| pip install . | ||
|
|
||
| # Install downstream libraries | ||
| - name: Install downstream libraries | ||
| run: pip install -r contrib/requirements.txt | ||
|
osanseviero marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Run tests | ||
| - name: Run tests | ||
| run: pytest contrib/ -n 4 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Contrib test suite | ||
|
|
||
| The contrib folder contains simple end-to-end scripts to test integration of `huggingface_hub` in downstream libraries. The main goal is to proactively notice breaking changes and deprecation warnings. | ||
|
|
||
| ## Run contrib tests on CI | ||
|
|
||
| Contrib tests can be [manually triggered in github](https://github.com/huggingface/huggingface_hub/actions) with the `Contrib tests` workflow. | ||
|
Wauplin marked this conversation as resolved.
Outdated
|
||
|
|
||
| Tests are not run in the default test suite (for each PR) as this would slow down development process. The goal is to notice breaking changes, not to avoid them. In particular, it is interesting to trigger it before a release to make sure it will not cause too much friction. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also run them once a week just to check
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cron job added by d5949fa. Will run every week on Saturday midnight. |
||
|
|
||
| ## Run contrib tests locally | ||
|
|
||
| ### Install dependencies | ||
|
|
||
| ```sh | ||
| # Create a separate contrib environment | ||
| python3 -m venv .venv_contrib | ||
| source .venv_contrib/bin/activate | ||
|
|
||
| # Install requirements | ||
| pip install . # huggingface_hub | ||
| pip install -r contrib/requirements.txt | ||
|
|
||
| # Run tests ! | ||
| pytest contrib -n 4 | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import time | ||
| import uuid | ||
| from typing import Generator | ||
|
|
||
| import pytest | ||
|
|
||
| from huggingface_hub import HfFolder, delete_repo | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def token() -> str: | ||
| # Not critical, only usable on the sandboxed CI instance. | ||
| return "hf_94wBhPGp6KrrTH3KDchhKpRxZwd6dmHWLL" | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def user() -> str: | ||
| return "__DUMMY_TRANSFORMERS_USER__" | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True, scope="session") | ||
| def login_as_dummy_user(token: str) -> Generator: | ||
| """Login with dummy user token on machine | ||
|
|
||
| Once all tests are completed, set back previous token.""" | ||
| # Remove registered token | ||
| old_token = HfFolder().get_token() | ||
| HfFolder().save_token(token) | ||
|
|
||
| yield # Run all tests | ||
|
|
||
| # Set back token once all tests have passed | ||
| if old_token is not None: | ||
| HfFolder().save_token(old_token) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def repo_name(request) -> None: | ||
| """ | ||
| Return a readable pseudo-unique repository name for tests. | ||
|
|
||
| Example: "repo-2fe93f-16599646671840" | ||
| """ | ||
| prefix = request.module.__name__ # example: `test_timm` | ||
| id = uuid.uuid4().hex[:6] | ||
| ts = int(time.time() * 10e3) | ||
| return f"repo-{prefix}-{id}-{ts}" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def cleanup_repo(user: str, repo_name: str) -> None: | ||
| """Delete the repo at the end of the tests. | ||
|
|
||
| TODO: Adapt to handle `repo_type` as well | ||
| """ | ||
| yield # run test | ||
| delete_repo(repo_id=f"{user}/{repo_name}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pytest | ||
| pytest-env | ||
| pytest-xdist | ||
|
|
||
| # Timm | ||
| git+https://github.com/rwightman/pytorch-image-models.git#egg=timm | ||
|
osanseviero marked this conversation as resolved.
osanseviero marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| def test_push_to_hub(repo_name: str, cleanup_repo: None) -> None: | ||
|
osanseviero marked this conversation as resolved.
Outdated
|
||
| import timm | ||
|
|
||
| # Build a model 🔧 | ||
| model = timm.create_model("resnet18", pretrained=True, num_classes=4) | ||
|
|
||
| # Push it to the 🤗 hub | ||
| timm.models.hub.push_to_hf_hub( | ||
| model, repo_name, model_config=dict(labels=["a", "b", "c", "d"]) | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.