Skip to content

Add NeMo waveform audio processor (data-side feature extractor) - #5570

Merged
yqwangustc merged 5 commits into
NVIDIA:mainfrom
yqwangustc:audio-model-processor
Jul 20, 2026
Merged

Add NeMo waveform audio processor (data-side feature extractor)#5570
yqwangustc merged 5 commits into
NVIDIA:mainfrom
yqwangustc:audio-model-processor

Conversation

@yqwangustc

@yqwangustc yqwangustc commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

What

Adds NemoAudioProcessor under megatron/core/models/audio/audio_processor.py — the concrete waveform → log-mel feature extractor + token-count estimator that the multimodal data pipeline uses to (a) size audio placeholders for packing and (b) materialize encoder inputs.

It composes the model-frontend descriptors NemoAudioFeatureConfig + NemoTransformerAudioTokenEstimator (from #5565) with the vendored standalone log-mel preprocessor.

Design

The audio reference it operates on is duck-typed (Any), so this module has no dependency on the data library's AudioRef type or on Megatron-Energon. The data pipeline consumes the processor through a small structural interface — compute_num_embeddings / compute_num_frames / materialize plus the cumulative-prefix num_*_from_num_samples primitives — and injects it at construction time. This keeps the dependency arrow pointing data → model and lets the energon-side packing code stay model-agnostic.

Test plan

tests/unit_tests/models/test_nemo_audio_processor.py (no GPU required):

  • slice primitives + cumulative-prefix invariants (disjoint slice contributions sum to the unsliced total)
  • slice_range waveform cropping and _infer_num_samples
  • log-mel materialization shape/dtype (full and empty waveform)

Local run of the full models/audio suite: 47 passed, 1 skipped (skip needs CUDA).

🤖 Generated with Claude Code

yqwangustc and others added 2 commits June 29, 2026 19:16
Introduces a self-contained audio encoder stack under
megatron/core/models/audio for multimodal (audio-text) training:

- nemo_transformer_encoder: vendored NeMo ASR TransformerEncoder with
  conv/stacking pre-encode, QK-norm, left-context windowing, activation
  checkpointing, and TE/SDPA/FlashAttention backends.
- nemo_transformer_audio_model: NemoTransformerAudioModel + config
  (mel frames -> audio embeddings; dense and packed forward paths).
- nemo_audio_preprocessing_standalone: vendored log-mel preprocessor with
  no NeMo/Lightning/Hydra runtime dependency.
- nemo_audio_checkpoint: .nemo archive extraction/loading and
  checkpoint-local config persistence.
- audio_projector / packed_audio: projection of audio embeddings to the
  language-model hidden size, with packed (THD) support.
- audio_feature_config: NemoAudioFeatureConfig + NemoTransformerAudioTokenEstimator
  (mel hyperparameters and frame->token math describing the model frontend).

The module depends only on megatron.core (vision MultimodalProjector,
TransformerConfig/MLP specs) plus optional transformer_engine/flash_attn/
omegaconf; it has no data-loader or Megatron-Energon dependency. The
concrete data-side waveform processor is injected separately.

Unit tests cover the projector, the vendored preprocessor, the encoder
forward/packed paths, token estimation, and .nemo checkpoint loading.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Yongqiang Wang <yongqiang.seagull@gmail.com>
…ocessor

- Set stack_factor default to 1 in AudioProjection and
  NemoTransformerAudioTokenEstimator.
- Rename nemo_audio_preprocessing_standalone.py to
  nemo_audio_preprocessing.py and update references.
- Add a module docstring explaining the pure-PyTorch mel feature
  extractor avoids a dependency on NVIDIA-NeMo/Speech; reference the
  upstream feature-parity PR.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Yongqiang Wang <yongqiang.seagull@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yqwangustc
yqwangustc force-pushed the audio-model-processor branch from ef52b47 to 77c4cb5 Compare July 16, 2026 01:45
@yqwangustc
yqwangustc marked this pull request as ready for review July 16, 2026 01:49
@yqwangustc
yqwangustc requested a review from a team as a code owner July 16, 2026 01:49
@yqwangustc

Copy link
Copy Markdown
Contributor Author

/ok to test 77c4cb5

Adds NemoAudioProcessor under megatron/core/models/audio: the concrete
waveform -> log-mel feature extractor and token-count estimator that the
multimodal data pipeline uses to size audio placeholders for packing and to
materialize encoder inputs.

It composes the model-frontend descriptors NemoAudioFeatureConfig and
NemoTransformerAudioTokenEstimator with the vendored standalone log-mel
preprocessor. The audio reference it operates on is duck-typed (Any), so this
module has no dependency on the data library's AudioRef type or on
Megatron-Energon — the data pipeline consumes the processor through a small
structural interface (compute_num_embeddings / compute_num_frames / materialize
plus the cumulative-prefix num_*_from_num_samples primitives) and injects it.

Tests cover the slice primitives (cumulative-prefix invariants),
slice_range waveform cropping, and log-mel materialization.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Yongqiang Wang <yongqiang.seagull@gmail.com>
Resolve audio-file conflicts (both-added from upstream PR NVIDIA#5565): take
upstream's review-polished versions for all audio modules and tests, and
preserve the local-only NemoAudioProcessor export in the package __init__.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Yongqiang Wang <yongqiang.seagull@gmail.com>
@yqwangustc
yqwangustc force-pushed the audio-model-processor branch from 77c4cb5 to 45056ff Compare July 16, 2026 18:24
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Approved All necessary approvals have been made label Jul 16, 2026
@yqwangustc

Copy link
Copy Markdown
Contributor Author

/ok to test 45056ff

The codecov/patch gate failed at 53% (target 80%): the data-side
NemoAudioProcessor's lazy AV-decoder decode chain and branch/error paths
were unexercised. Add tests covering the decoder fakes
(_decode_avdecoder / _resolve_lazy_media / _audio_clip_to_float32 /
_decoder_sample_rate / _load_waveform_from_spec), sample-rate and
tolerance resolution, the waveform-normalization and _infer_num_samples
branches (mono averaging, num_samples pad/crop, dtype/shape/slice_range
errors), and the public compute_num_frames / compute_num_embeddings
methods and properties.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Yongqiang Wang <yongqiang.seagull@gmail.com>
@yqwangustc
yqwangustc enabled auto-merge July 20, 2026 20:37
@yqwangustc

Copy link
Copy Markdown
Contributor Author

/ok to test 6a2defe

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29782051025

Merged via the queue into NVIDIA:main with commit cfb116f Jul 20, 2026
89 checks passed
@yqwangustc
yqwangustc deleted the audio-model-processor branch July 20, 2026 22:47
terminator123 pushed a commit to 021ai/Megatron-LM that referenced this pull request Aug 3, 2026
…IA#5570)

Signed-off-by: Yongqiang Wang <yongqiang.seagull@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
svcnvidia-nemo-ci pushed a commit to dimapihtar/Megatron-LM that referenced this pull request Aug 4, 2026
…IA#5570)

Signed-off-by: Yongqiang Wang <yongqiang.seagull@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Dmytro Pykhtar <dpykhtar@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made complexity: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants