Skip to content

Reduce code duplication in audio collection + some small fixes#15587

Open
racoiaws wants to merge 13 commits intoNVIDIA-NeMo:mainfrom
racoiaws:audio-refactor
Open

Reduce code duplication in audio collection + some small fixes#15587
racoiaws wants to merge 13 commits intoNVIDIA-NeMo:mainfrom
racoiaws:audio-refactor

Conversation

@racoiaws
Copy link
Copy Markdown
Collaborator

@racoiaws racoiaws commented Apr 7, 2026

Important

The Update branch button must only be pressed in very rare occassions.
An outdated branch is never blocking the merge of a PR.
Please reach out to the automation team before pressing that button.

What does this PR do ?

Reduce duplicated code across the 6 AudioToAudioModel subclasses by moving shared logic into the base class.

Collection: Audio

Changelog

  • Move shared training loop logic (batch parsing, training_step, normalization, init boilerplate) into AudioToAudioModel base class
  • Fix SB component loss logging firing during evaluation
  • Fix redundant world_size init in EncMaskDec and BNR2

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this 

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

@github-actions github-actions bot added the audio label Apr 7, 2026
racoiaws and others added 10 commits April 7, 2026 06:14
Move component loss logging (train_loss_encoded, train_loss_time) into
_step itself, so it returns a plain scalar like all other models.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
Replace duplicated batch parsing and 2D-to-3D reshape logic across
all 6 audio model subclasses with a single _parse_batch method on the
base class. FlowMatchingAudioToAudioModel overrides it to allow
missing target_signal for SSL pretraining.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
Add abstract _compute_train_loss method that each subclass implements
with its model-specific loss computation. The base class training_step
handles batch parsing, logging, and return.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
_step is called from both training and evaluation. The train_loss_encoded
and train_loss_time logs should only fire during training.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
…el.__init__

Both are set identically by all 6 subclasses. setup_optimization_flags
only reads self._cfg, so it is safe to call before subclass-specific
module initialization.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
ModelPT.__init__ calls set_trainer → set_world_size before any data
loader setup, so the pre-super assignment is always overwritten before
it can be read.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
Consistent with all other audio model subclasses which use
self.from_config_dict rather than the concrete class name.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
Now called from base __init__, no longer requires explicit subclass call.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
Replace repeated normalize/denormalize boilerplate across 4 forward()
and 3 _step() methods with calls to shared helpers on AudioToAudioModel.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
racoiaws and others added 2 commits April 7, 2026 06:19
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
The test calls _step directly, which now logs component losses via
self.log. Disable logging in this test since there is no active
Lightning loop context. Also update to use _parse_batch and the
scalar return from _step.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
_denormalize to restore the original scale.
"""
norm_scale = torch.amax(signal.abs(), dim=(-1, -2), keepdim=True)
return signal / (norm_scale + self.eps), norm_scale
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should the returned norm_scale include + self.eps for identical reverse operation?

Copy link
Copy Markdown
Collaborator Author

@racoiaws racoiaws Apr 7, 2026

Choose a reason for hiding this comment

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

Good catch

I'd prefer an explicit add in the reverse operation instead of baking it into norm_scale

_normalize divides by (norm_scale + eps), so _denormalize should
multiply by (norm_scale + eps) to recover the original signal.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Roman Korostik <rkorostik@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants