Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Disabling Chainer from default installation#6224

Merged
sw005320 merged 8 commits intoespnet:masterfrom
Fhrozen:pr-chainer
Aug 26, 2025
Merged

Disabling Chainer from default installation#6224
sw005320 merged 8 commits intoespnet:masterfrom
Fhrozen:pr-chainer

Conversation

@Fhrozen
Copy link
Member

@Fhrozen Fhrozen commented Aug 25, 2025

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

  • Added try/except imports for Chainer throughout the codebase, logging a warning and falling back to dummy classes in espnet.utils.dummy_chainer when 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]
  • Introduced espnet.utils.dummy_chainer with dummy implementations for key Chainer classes (e.g., Extension, StandardUpdater, Reporter, Iterator, etc.), raising informative errors if used without Chainer installed.
  • Updated all Chainer-dependent classes and usages to inherit from or use the dummy classes when Chainer is missing, ensuring the code can still be imported and tested. [1] [2] [3] [4]

User and CI notifications

  • Added warnings and clear instructions to users about Chainer deprecation and how to install it if needed, both in the codebase and in the Makefile. [1] [2]
  • Modified test scripts (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

  • Removed Chainer from default installation targets in tools/Makefile and the main CI workflow, making it an explicit, optional dependency. [1] [2]
  • Improved Makefile and CI scripts for clarity and maintainability, including multi-line formatting and clearer warnings. [1] [2]

These changes collectively make Chainer optional, prepare for its complete removal, and ensure users and contributors are clearly informed about the transition.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 25, 2025
@Fhrozen Fhrozen requested a review from Copilot August 25, 2025 13:29
@dosubot dosubot bot added the Installation label Aug 25, 2025
@mergify mergify bot added ESPnet1 ASR Automatic speech recogntion LM CI Travis, Circle CI, etc labels Aug 25, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +66 to +68
logging.warning("Chainer is not Installed. Run `make chainer.done` at tools dir.")
from espnet.utils.dummy_chainer import StandardUpdater

Copy link
Contributor

Choose a reason for hiding this comment

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

critical

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.

Comment on lines +50 to +51
except ImportError:
logging.warning("Chainer is not Installed. Run `make chainer.done` at tools dir.")
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The except ImportError block is empty. This means if Chainer is not installed, training and extensions will be undefined, causing a NameError when they are used later in the file (e.g., training.Trainer at line 362). Dummy implementations or guarded logic should be added for these modules.

Comment on lines +22 to +25
except ImportError:
logging.warning("Chainer is not Installed. Run `make chainer.done` at tools dir.")

from espnet.utils.dummy_chainer import Extension, Iterator
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The except ImportError block does not define a dummy for the chainer module itself. The code later uses chainer.serializer.Serializer at line 272, which will cause a NameError if Chainer is not installed. A dummy for chainer or guarded logic is needed.

Fhrozen and others added 3 commits August 25, 2025 22:32
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
Copy link

codecov bot commented Aug 25, 2025

Codecov Report

❌ Patch coverage is 0% with 114 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.53%. Comparing base (2aeb6b7) to head (04cb2b0).
⚠️ Report is 23 commits behind head on master.

Files with missing lines Patch % Lines
espnet/utils/dummy_chainer.py 0.00% 27 Missing ⚠️
espnet/nets/pytorch_backend/e2e_asr.py 0.00% 16 Missing ⚠️
espnet/lm/lm_utils.py 0.00% 9 Missing ⚠️
espnet/asr/pytorch_backend/asr.py 0.00% 8 Missing ⚠️
espnet/utils/training/iterators.py 0.00% 8 Missing ⚠️
espnet/utils/deterministic_utils.py 0.00% 7 Missing ⚠️
espnet/asr/asr_mix_utils.py 0.00% 6 Missing ⚠️
espnet/optimizer/chainer.py 0.00% 6 Missing ⚠️
espnet/scheduler/chainer.py 0.00% 6 Missing ⚠️
espnet/utils/training/evaluator.py 0.00% 6 Missing ⚠️
... and 3 more

❗ There is a different number of reports uploaded between BASE (2aeb6b7) and HEAD (04cb2b0). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (2aeb6b7) HEAD (04cb2b0)
test_python_espnet1 1 0
test_integration_espnet1 1 0
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     
Flag Coverage Δ
test_integration_espnet1 ?
test_integration_espnet2 46.39% <ø> (ø)
test_integration_espnetez 37.15% <ø> (ø)
test_python_espnet1 ?
test_python_espnet2 50.23% <0.00%> (-0.07%) ⬇️
test_python_espnetez 12.70% <0.00%> (-0.03%) ⬇️
test_utils 18.77% <ø> (-1.87%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@Fhrozen Fhrozen requested a review from sw005320 August 26, 2025 22:07
Copy link
Contributor

@sw005320 sw005320 left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 26, 2025
@sw005320 sw005320 merged commit bdf44cd into espnet:master Aug 26, 2025
32 of 33 checks passed
@Fhrozen Fhrozen deleted the pr-chainer branch August 26, 2025 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ASR Automatic speech recogntion CI Travis, Circle CI, etc ESPnet1 Installation lgtm This PR has been approved by a maintainer LM size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants