Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transformers+tokenizers not imported on module lvl (#948)
With this PR, the Hugging Face packages transformers and tokenizers are no longer imported on a module level. This allows users to use the parts of skorch.hf that are independent of those packages without installing them, e.g. the accelerate mixin. Comment Previously, I had imported them on a class level, wrongly thinking that would be enough. I wanted to add a test for this change, patching the import function to raise an error when either package is imported, then importing something else from skorch.hf and checking that no ImportError is raised. This test did, however, not work, because AccelerateMixin is imported on module level in test_hf.py (this is necessary in order to define AcceleratedNet on the module level, as it would otherwise not be pickleable). This leads to the following situation: - the hf.py module is already loaded when the tests are collected by pytest - therefore, the imports are triggered before the patch is applied - therefore, the imports are cached and the patch is useless Well, if someone knows a way out of this conundrum, let me know. But I don't think this test is particularly important, so I would be fine merging without it.
- Loading branch information