Disabling Chainer from default installation#6224
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull Request Overview
This pull request removes Chainer from the default ESPnet installation while maintaining backward compatibility and providing clear deprecation warnings. The changes prepare for Chainer's complete removal in the next release (v202509) by making it an optional dependency.
- Introduced conditional imports with fallback to dummy classes when Chainer is not available
- Added deprecation warnings and installation instructions throughout the codebase
- Updated build scripts and CI workflows to exclude Chainer from default installations
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/Makefile | Removed chainer.done from default python target and added deprecation warning |
| espnet/utils/dummy_chainer.py | Added dummy classes for Chainer components to maintain compatibility |
| espnet/utils/training/*.py | Updated imports to use try/except with dummy fallbacks |
| espnet/nets/pytorch_backend/e2e_asr.py | Refactored Reporter class with conditional Chainer import |
| espnet/lm/lm_utils.py | Updated class inheritance to use dummy classes when Chainer unavailable |
| espnet/asr/pytorch_backend/*.py | Added conditional imports for Chainer training components |
| espnet/asr/asr_mix_utils.py | Updated Extension inheritance with conditional import |
| espnet/scheduler/chainer.py | Added type annotation for Optimizer parameter |
| espnet/optimizer/chainer.py | Updated imports with try/except pattern |
| espnet/utils/deterministic_utils.py | Added conditional check for Chainer availability |
| ci/test_*.sh | Added Chainer availability checks with early exit warnings |
| ci/install.sh | Removed Chainer from installation script and improved formatting |
| .github/workflows/ci_on_ubuntu.yml | Removed Chainer installation from CI workflow |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request aims to make Chainer an optional dependency by removing it from the default installation and introducing dummy classes for compatibility. The approach is sound, but there are several critical issues that need to be addressed. The CI scripts have inverted logic for checking Chainer's presence, which will cause tests to be skipped incorrectly. Additionally, several Python files will raise a NameError if Chainer is not installed because some Chainer modules are used without being imported or having a dummy fallback in the except block. There is also a duplicated class definition that needs to be resolved.
| logging.warning("Chainer is not Installed. Run `make chainer.done` at tools dir.") | ||
| from espnet.utils.dummy_chainer import StandardUpdater | ||
|
|
There was a problem hiding this comment.
The except ImportError block only provides a dummy for StandardUpdater. However, this file also uses reporter_module, training, and extensions from Chainer, which will be undefined if Chainer is not installed, leading to a NameError. Dummy objects or alternative logic should be provided for these modules as well to ensure the code runs without Chainer. For example, training.Trainer is used at line 820.
| except ImportError: | ||
| logging.warning("Chainer is not Installed. Run `make chainer.done` at tools dir.") |
There was a problem hiding this comment.
| except ImportError: | ||
| logging.warning("Chainer is not Installed. Run `make chainer.done` at tools dir.") | ||
|
|
||
| from espnet.utils.dummy_chainer import Extension, Iterator |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6224 +/- ##
===========================================
- Coverage 70.30% 55.53% -14.77%
===========================================
Files 897 897
Lines 84917 84908 -9
===========================================
- Hits 59698 47151 -12547
- Misses 25219 37757 +12538
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Note
Move code related to disabling Chainer from the default installation. Ref: #6221
What did you change?
This pull request focuses on deprecating Chainer support in the codebase and making ESPnet robust to environments where Chainer is not installed. It introduces dummy classes to allow the code and CI to run without Chainer, adds warnings and instructions for users, and updates the installation and testing scripts accordingly. Chainer is now optional, and users are notified that it will be removed in the next release.
Chainer deprecation and compatibility
espnet.utils.dummy_chainerwhen Chainer is not installed. This ensures the codebase can run (with limited functionality) without Chainer. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]espnet.utils.dummy_chainerwith dummy implementations for key Chainer classes (e.g.,Extension,StandardUpdater,Reporter,Iterator, etc.), raising informative errors if used without Chainer installed.User and CI notifications
Makefile. [1] [2]ci/test_python_espnet1.sh,ci/test_integration_espnet1.sh) to check for Chainer and exit early with a warning if not present, reflecting its deprecated status. [1] [2] [3]Build and dependency updates
tools/Makefileand the main CI workflow, making it an explicit, optional dependency. [1] [2]These changes collectively make Chainer optional, prepare for its complete removal, and ensure users and contributors are clearly informed about the transition.