KEMBAR78
Add -e flag to some GH workflow yml files by ydshieh · Pull Request #16959 · huggingface/transformers · GitHub
Skip to content

Conversation

@ydshieh
Copy link
Collaborator

@ydshieh ydshieh commented Apr 27, 2022

What does this PR do?

Current 2 GitHub actions workflow yml use pip install [.dev]. This installs transformers in /home/runner/venv/lib/python3.6/site-packages, and this is cached. In future job runs, the cache is restored, and that transformers version is used - instead of the latest commit, i.e. we want to use /home/runner/work/transformers/transformers/src.

Without this PR, I have trouble after updating add_new_model.py (to change test model folders from tests/ to tests/models/) because the add_new_model.py from /home/runner/venv/lib/python3.6/site-packages would be used, which would put the test template models under tests/

This PR makes sure the latest transformers is used by using pip install -e [.dev], and builds a new cache with it.

  • Add -e flag to some GH workflow yml files
  • change cache key in order to make the change effective
  • add a check on transformers location

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Apr 27, 2022

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

with:
path: ~/venv/
key: v2-tests_model_like-${{ hashFiles('setup.py') }}
key: v3-tests_model_like-${{ hashFiles('setup.py') }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in order to make the change effective (then saved to a new cache)

python -m venv ~/venv && . ~/venv/bin/activate
pip install --upgrade pip!=21.3
pip install .[dev]
pip install -e .[dev]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is the main change in order to use /home/runner/work/transformers/transformers/src

Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't usually work, as an editable install writes some content in some folders, and this is not allowed on GitHub action pull-request (for security reasons, since the user have put code on their own in their PR).

I have no idea why the check passes now, maybe it's not executing this version of the test script.

Comment on lines 39 to 48
- name: Check transformers location
run: |
. ~/venv/bin/activate
transformer_loc=$(pip show transformers | grep "Location: " | cut -c11-)
transformer_repo_loc=$(pwd .)
if [ "$transformer_loc" != "$transformer_repo_loc/src" ]; then
echo "transformers is from $transformer_loc but it shoud be from $transformer_repo_loc/src."
echo "A fix is required. Stop testing."
exit 1
fi
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

add a check of the package location, so we won't be fooled in the future.

Copy link
Member

@gante gante left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix 👍

@ydshieh
Copy link
Collaborator Author

ydshieh commented Apr 27, 2022

The added check will produce something like (if the transformers is not from the expected location)

Screenshot 2022-04-27 131320

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

As discussed offline, good for me, but let's be super vigilant after merging and ready to revert.

Thanks for working on this!

@ydshieh
Copy link
Collaborator Author

ydshieh commented Apr 27, 2022

after the new cache is built the first time and job completes (pass the check I added too), the next run when we have

Cache restored from key: v3-tests_model_like-ce386d6c28d7afcca58dc875de2ef1b7477e8246a0bfdb6ff4de0eb222eafef2

the check failed with

transformers is from  but it shoud be from /home/runner/work/transformers/transformers/src.
A fix is required. Stop testing.

which means pip show transformers gives empty location!

I will try to make it work - I really like to have this test.
(But things should work now if we just remove this test)

@ydshieh
Copy link
Collaborator Author

ydshieh commented Apr 27, 2022

Confirmed this (with -e) currently not working for the subsequentially run (i.e. cache loaded).

I still think there might be some workaround, let me try. Set to draft for now

currently error

Traceback (most recent call last):
  File "/home/runner/venv/bin/transformers-cli", line 33, in <module>
    sys.exit(load_entry_point('transformers', 'console_scripts', 'transformers-cli')())
  File "/home/runner/venv/bin/transformers-cli", line [22](https://github.com/huggingface/transformers/runs/6197315688?check_suite_focus=true#step:7:22), in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/home/runner/venv/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 815, in distribution
    return Distribution.from_name(distribution_name)
  File "/home/runner/venv/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 430, in from_name
    raise PackageNotFoundError(name)
importlib_metadata.PackageNotFoundError: No package metadata was found for transformers
Error: Process completed with exit code 1.

@ydshieh ydshieh marked this pull request as draft April 27, 2022 16:25
Comment on lines 40 to 43
# make `transformers` available as package (required since we use `-e` flag) and check it indeeds from the repo.
run: |
. ~/venv/bin/activate
python setup.py build install
Copy link
Collaborator Author

@ydshieh ydshieh Apr 27, 2022

Choose a reason for hiding this comment

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

@sgugger let me know if you have any comment regarding this new change. 🙏

(Lysandre and gante are OK with it on a Slack message)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good!

@ydshieh ydshieh marked this pull request as ready for review April 27, 2022 17:03
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.

LGTM

# make `transformers` available as package (required since we use `-e` flag) and check it's indeed from the repo.
run: |
. ~/venv/bin/activate
python setup.py build install
Copy link
Member

Choose a reason for hiding this comment

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

Usually when installing it with -e, you should do python setup.py develop, no?
If this works well here, fine by me!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Change it to develop as it makes more sense. Thank you for the information!

@ydshieh ydshieh merged commit 992996e into huggingface:main Apr 27, 2022
@ydshieh ydshieh deleted the fix_git_workflow_yml branch April 27, 2022 19:44
chamidullinr pushed a commit to chamidullinr/transformers that referenced this pull request Apr 28, 2022
* Add -e flag

* add check

* create new keys

* run python setup.py build install

* add comments

* change to develop

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
elusenji pushed a commit to elusenji/transformers that referenced this pull request Jun 12, 2022
* Add -e flag

* add check

* create new keys

* run python setup.py build install

* add comments

* change to develop

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
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