Skip to content

Commit cab4152

Browse files
omarespejelOmar Espejelosanseviero
authored
Add fastai upstream and downstream capacities for fastai>=2.4 and fastcore>=1.3.27 versions (#678)
* added a fastai mixin for upstream and downstream tasks with fastai library * Added check for right fastai version * Added aditional documentation * Add support for fastai>=2.4 versions and fastcore>=1.3.27 * Update docstrings, save_fastai_learner, push_to_hub_fastai, and change name from fastai_mixin * trim triling whitespaces * Import fastai_utils.py in huggingface_hub/__init__py * Add check_fastai_fastcore_versions function in fastai_utils.py * Eliminate imports of libraries not used in fastai_utils.py * Add isort and black format to fastai_utils.py * Change pickle_protocol argument from kwargs to explicit * Change kwargs arguments in the function from_pretrained_fastai to explicit * Simplify push_to_hub_fastai function, particularly the repo_id argument * Eliminate search for a pickle document in from_pretrained_fastai function * Simplify push_to_hub_fastai and correct bug in from_pretrained_fastai * Add pickle.DEFAULT_PROTOCOL for get adequate protocol when exporting the Learners * Allow to load only models in the Hub when using from_pretrained_fastai * Eliminate cache_dir from from_pretrained_fastai for simplification * Correct nit picks in push_to_hub_fastai * Update with nits * Apply isort * Replace config.json for pyproject.toml to check for fastai and fastcore versions * Isort imports * Make pyproject.toml automatically filled with fastai, fastcore, and python versions used. * add check_fastai_fastcore_pyproject_versions function to know the fastai and fastcore versions of the pretrained model to load from the Hub * Change library tomlkit for toml * Add extras[fastai] with the toml library * Change the way the token is asked in def push_to_hub_fastai( * Eliminate logger from imports * Fix nits * Remove typing.Union from imports * add fastai integration tests * Import fastai in setup.py * Import toml inside check_fastai_fastcore_pyproject_versions function * Nits in fastai_utils.py * Add build_fastai to python-tests.yml * Add fastcore import to setup.py * Add require_fastai_fastcore() to skip tests * Nits and documentation of raised errors improved * add strategy for fastai in python-tests.yml * Eliminate organization from push_to_hub_fastai * Add python 3.7-3.10 to python-tests.yml * Change python version in tests to 3.9 * Fix tests * Fix conflict in config.py due to order of tf packages * Fix delete_repo function in test_fastai_integration * Isort test_fastai_integration * Replace the repo_id name for model_id * Keep the names consistent * Make fastai and fastcore versions flexible in setup.py * Would be "fastai>=2.4" and "fastcore>=1.3.27" * Confirm fastai supports python 3.10 in python-tests-yml * Version 2.5.6 of fastai supports python 3.10 * Fix docs in fastai_utils.py * Fix functions' arguments documentation for a proper rendering * Change the name of DummyModel for dummy_model * Handle pickling errors when exporting a fastai.Learner * Guide user in how to deal with a PicklingError * Change name of internal functions in fastai_utils.py * Start functions that are not push_to_hub_fastai and from_pretrained_fastai with a "_" to indicate that they are internal functions. They would not be necessary for the user. * black style to fastai_utils.py * Eliminate unnecessary comments from fastai_utils.py * Add capacity to load a local fastai.Learner to from_pretrained_keras * In fastai_utils.py. * This would be in addition to being able to load a pretrained model from the Hub * black format fastai_utils.py * Come back to Python 3.9 instead of 3.10 * fastai was made compatible with Python 3.10 just in the most recent version 3.5.6 released on April 1st. I would prefer to wait for the next release of fastai. * Change name name of save_fastai_learner to _save_pretrained_fastai in test_fastai_integration.py * Change the name to _save_pretrained_fastai in __init__.py * Additionally, isort test_fastai_integration.py * Change the name from save_fastai_learner to _save_pretrained_fastai * isort __init__.py * Fix nits in test_fastai_integration.py * Add fastai integration to docs * functions from_pretrained_fastai and push_to_hub_fastai were added to mixins.mdx * Fix nits * Fix wording * Allow _save_pretrained_fastai to directly export the model in save_directory * By default learner.export saves learner to learner.path * Before we where saving the model in learner.path and them moving it to save_directory * Fix by changing learner.path to being equal to save_directory * black fastai_utils.py * Make the requirement of having a pyproject.toml optional * Additionally, makes optional that the pyproject.toml contains the fastai and fastcore versions * Will continue to throw an error if the toml library is not available * Will continue to thrown an error if the pyproject.toml specifies fastai or fastcore versions that are not supported by from_pretrained_fastai * This will allow to load fastai models from the Hub that were not necessarily uploaded using push_to_hub_fastai. * Add warnings if the pyproject.toml does not contain a "build-system" and "requires" section * Change try-excepts for ifs in the warnings checking the fastai and fastcore versions * Fix nits in documentation * Move errors in _check_fastai_fastcore_pyproject_versions to conditions after warnings * Misc improvements * Move the versions checks for fastai and fastcore to "else"'s * This allows to eliminate the returns when checking for the versions of fastai and fastcore in the pyproject.toml * Move the versions checks for fastai and fastcore to "else"'s * This allows to eliminate the returns when checking for the versions of fastai and fastcore in the pyproject.toml * Black reformat Co-authored-by: Omar Espejel <[email protected]> Co-authored-by: osanseviero <[email protected]>
1 parent 04c38fc commit cab4152

File tree

7 files changed

+639
-1
lines changed

7 files changed

+639
-1
lines changed

.github/workflows/python-tests.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,27 @@ jobs:
9090
pip install .[testing,tensorflow]
9191
9292
- run: pytest -Werror::FutureWarning -sv ./tests/test_keras*
93+
94+
build_fastai:
95+
runs-on: ubuntu-latest
96+
strategy:
97+
matrix:
98+
python-version: ["3.7", "3.9"]
99+
100+
steps:
101+
- uses: actions/checkout@v2
102+
103+
- name: Set up Python ${{ matrix.python-version }}
104+
uses: actions/setup-python@v2
105+
with:
106+
python-version: ${{ matrix.python-version }}
107+
108+
- name: Install dependencies
109+
run: |
110+
pip install --upgrade pip
111+
pip install .[testing,fastai]
112+
113+
- run: pytest -Werror::FutureWarning -sv ./tests/test_fastai*
93114

94115
tests_lfs:
95116
runs-on: ubuntu-latest

docs/source/package_reference/mixins.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@ objects, in order to provide simple uploading and downloading functions.
1717

1818
[[autodoc]] save_pretrained_keras
1919

20-
[[autodoc]] KerasModelHubMixin
20+
[[autodoc]] KerasModelHubMixin
21+
22+
### Fastai
23+
24+
[[autodoc]] from_pretrained_fastai
25+
26+
[[autodoc]] push_to_hub_fastai
27+
28+
29+

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def get_version() -> str:
2727
"torch",
2828
]
2929

30+
extras["fastai"] = [
31+
"toml",
32+
"fastai>=2.4",
33+
"fastcore>=1.3.27",
34+
]
35+
3036
extras["tensorflow"] = ["tensorflow", "pydot", "graphviz"]
3137

3238
extras["testing"] = [

src/huggingface_hub/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
TF2_WEIGHTS_NAME,
3232
TF_WEIGHTS_NAME,
3333
)
34+
from .fastai_utils import (
35+
_save_pretrained_fastai,
36+
from_pretrained_fastai,
37+
push_to_hub_fastai,
38+
)
3439
from .file_download import cached_download, hf_hub_download, hf_hub_url
3540
from .hf_api import (
3641
DatasetSearchArguments,

0 commit comments

Comments
 (0)