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

Skip to content

[espnet3-8] Bugfix for recipe#6270

Merged
sw005320 merged 12 commits intoespnet:espnet3from
Masao-Someki:espnet3/update_and_bugfix
Nov 12, 2025
Merged

[espnet3-8] Bugfix for recipe#6270
sw005320 merged 12 commits intoespnet:espnet3from
Masao-Someki:espnet3/update_and_bugfix

Conversation

@Masao-Someki
Copy link
Contributor

What did you change?

  • Updated espnet3/collect_stats.py with Runner/Provider classes:

    • This fix includes bugfix in collect_stats.
  • Bug fixed base_runner.py:

    • Wrapped parallel_for() with tqdm progress bar for visual feedback during distributed runs.
  • Bug fixed espnet3/utils/config.py:

    • Returned ListConfig instead of plain list in load_line().
    • Added OmegaConf.resolve() after merging configs.
  • Bug fixed espnet3/trainer/model.py: imported Path for consistency with file I/O utilities.


Why did you make this change?

  • The previous collect_stats system used separate implementations (collect_stats_local, collect_stats_parallel, etc.), which made maintenance and testing difficult.

  • In the [espnet3-6] Add evaluation scripts #6178 we implemented Runner/Provider classes for seamless integration of parallel processing/local execution.

  • This is much easier to maintain, so I modified from the parallel processing into runner/provider.

  • Added tqdm progress monitoring to improve user experience during long Dask-based runs.

  • The config.py changes improve Hydra compatibility and ensure proper type resolution in nested configurations.


Is your PR small enough?

Yes.

  • 5 files changed
  • ~450 insertions, ~20 deletions
  • All changes are localized and focused on refactoring the collect_stats workflow.

Additional Context

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 24, 2025
@Masao-Someki Masao-Someki changed the title [espnet3-8]Espnet3/bugfix [espnet3-8] Bugfix for recipe Oct 24, 2025
@Masao-Someki Masao-Someki requested a review from Emrys365 October 24, 2025 01:57
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 introduces a significant and valuable refactoring of the collect_stats functionality, replacing separate local and parallel implementations with a more maintainable Runner/Provider pattern. The changes improve code structure, enhance user experience by adding a progress bar for parallel runs, and fix important configuration handling issues in espnet3/utils/config.py.

My review focuses on the new implementation in espnet3/collect_stats.py. I've identified a couple of areas for improvement: a leftover debug statement and an opportunity to reduce code duplication, which will further enhance the maintainability of the new architecture. Overall, this is a solid improvement.

else:
model = instantiate(model_config)

print(model)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This print(model) statement appears to be a leftover from debugging. It should be removed to avoid polluting logs, especially in distributed environments where it could generate a large amount of output.

Comment on lines +254 to +298
def build_env_local(self) -> Dict[str, Any]:
env = super().build_env_local()
collate_fn = _build_collate_fn(self.config.dataloader_config)
env["collate_fn"] = collate_fn

dataset = env.get("dataset")
if hasattr(dataset, "use_espnet_collator"):
dataset.use_espnet_collator = isinstance(collate_fn, CommonCollateFn)
env["dataset"] = dataset

device = env.get("device")
if device is None:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
env["device"] = device

env["model"] = env["model"].to(device).eval()
env.setdefault("write_collected_feats", False)
env.setdefault("collect_stats_kwargs", None)
return env

def make_worker_setup_fn(self):
base_setup = super().make_worker_setup_fn()
dataloader_config = self.config.dataloader_config

def setup():
env = base_setup()
collate_fn = _build_collate_fn(dataloader_config)
env["collate_fn"] = collate_fn

dataset = env.get("dataset")
if hasattr(dataset, "use_espnet_collator"):
dataset.use_espnet_collator = isinstance(collate_fn, CommonCollateFn)
env["dataset"] = dataset

device = env.get("device")
if device is None:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
env["device"] = device

env["model"] = env["model"].to(device).eval()
env.setdefault("write_collected_feats", False)
env.setdefault("collect_stats_kwargs", None)
return env

return setup
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The methods build_env_local and the inner setup function within make_worker_setup_fn contain nearly identical logic for setting up the environment (e.g., creating collate_fn, determining device, preparing the model). This code duplication can make future maintenance more difficult, as changes might not be consistently applied to both places.

Consider extracting this common logic into a private helper method to be called by both build_env_local and setup. This would centralize the environment setup and improve code clarity and maintainability.

@Masao-Someki Masao-Someki mentioned this pull request Oct 24, 2025
52 tasks
@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

❌ Patch coverage is 83.17757% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.17%. Comparing base (ce649fa) to head (8de525a).
⚠️ Report is 14 commits behind head on espnet3.

Files with missing lines Patch % Lines
espnet3/collect_stats.py 83.25% 35 Missing ⚠️
espnet3/runner/base_runner.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           espnet3    #6270      +/-   ##
===========================================
- Coverage    70.17%   70.17%   -0.01%     
===========================================
  Files          754      752       -2     
  Lines        69240    69300      +60     
===========================================
+ Hits         48589    48630      +41     
- Misses       20651    20670      +19     
Flag Coverage Δ
test_integration_espnet2 47.88% <ø> (ø)
test_python_espnet2 62.54% <0.00%> (-0.06%) ⬇️
test_python_espnet3 16.20% <83.17%> (+0.04%) ⬆️
test_utils 62.54% <0.00%> (-0.06%) ⬇️

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

@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.

  • I'm not sure what the meaning of process_batch_batching. The function name is also confusing. Please clarify it and also rename it appropriately.
  • Is the newly added collect stats function going through the unit test?

@Emrys365, can you review this?

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 24, 2025
@Masao-Someki
Copy link
Contributor Author

Masao-Someki commented Oct 24, 2025

For the collect-stats part, I realized the current fix is not enough.

  1. I need to remove collect-stats files in utils/
  2. Update unit tests
  3. Collect-stats provider needs refactoring, it's very complicated and we can make it simple

While the update on current commits is enough for running recipe, I will fix the above items to make this PR better

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Oct 24, 2025
@Fhrozen Fhrozen added this to the v.202512 milestone Oct 26, 2025
@jctian98
Copy link
Collaborator

LGTM

@sw005320
Copy link
Contributor

We need a careful document and explanation about what a runner is and what a provider is.

  • Please embed this information in the source code
  • Please add TODO to explain the runner and provider in our document for parallel processing

@Masao-Someki
Copy link
Contributor Author

Thank you, I added a todo comment, and I will create a PR on document! I have prepared it but couldn't make a PR as we have multiple changes to interfaces, but for now I think it is a good timing to make PR!

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Oct 31, 2025
@mergify mergify bot added the Installation label Oct 31, 2025
@Masao-Someki
Copy link
Contributor Author

I have added the document for parallel processing and runner/provider classes.
It is still not on PR but you can check form here

Copy link
Collaborator

@Emrys365 Emrys365 left a comment

Choose a reason for hiding this comment

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

Thanks @Masao-Someki. The modifications make the code more compact. With more detailed documentations (as mentioned in TODOs) it would be much more clear to read / use.

@Masao-Someki
Copy link
Contributor Author

@Emrys365
I'm sorry, I just realized this and fixed the reviews!
For the pip version, I think we can focus on this later.. I had put this in the loadmap.

@sw005320 sw005320 merged commit 99697da into espnet:espnet3 Nov 12, 2025
28 checks passed
@Fhrozen Fhrozen modified the milestones: v.202512, v.202511 Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugfix ESPnet3 Installation lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants