Skip to content

[TTS] Add Python 3 type hints and module docstring to helpers.py#15708

Open
shivansh023023 wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
shivansh023023:typing/add-type-hints-tts-helpers
Open

[TTS] Add Python 3 type hints and module docstring to helpers.py#15708
shivansh023023 wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
shivansh023023:typing/add-type-hints-tts-helpers

Conversation

@shivansh023023
Copy link
Copy Markdown

What does this PR do?

Adds complete Python 3 type annotations to 26 public functions and a module-level
docstring in nemo/collections/tts/parts/utils/helpers.py, as required by
CONTRIBUTING.md: "Use Python 3 type hints for every class and method exposed to the user."

Collection: TTS

Changelog

  • Added module-level docstring describing the purpose of the utility module
  • Added Iterable to the existing typing imports
  • Annotated 26 public functions:
    • get_batch_size, get_num_workers — training utility helpers
    • binarize_attention, binarize_attention_parallel — attention alignment
    • mas, mas_width1, b_mas — monotonic alignment search (numba @jit)
    • griffin_lim — spectrogram-to-audio conversion
    • log_audio_to_tb — TensorBoard audio logging (@rank_zero_only)
    • regulate_len, slice_segments, rand_slice_segments — length/segment ops
    • clip_grad_value_, convert_pad_shape, generate_path — training utilities
    • process_batch, sample_tts_input, get_speaker_embeddings_from_filepaths — data pipeline
    • plot_alignment_to_numpy, plot_alignment_to_numpy_for_speechllm, plot_pitch_to_numpy, plot_multipitch_to_numpy, plot_spectrogram_to_numpy, create_plot, plot_gate_outputs_to_numpy, save_figure_to_numpy — visualization helpers
  • Fixed torch.tensortorch.Tensor in regulate_len signature (incorrect type reference)

Usage

No API changes. Type hints are purely additive and improve IDE autocompletion
and static analysis for downstream users of these TTS utilities.

# Example: IDE now correctly infers return types
from nemo.collections.tts.parts.utils.helpers import regulate_len

# regulate_len now shows: (torch.Tensor, torch.Tensor) return type in IDE
enc_rep, dec_lens = regulate_len(durations, enc_out, pace=1.0)

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests? — No tests needed, annotations only
  • Did you add or update any necessary documentation? — Added module-level docstring
  • Does the PR affect components that are optional to install? (Numba is used for @jit functions — type hints on @jit functions are safely stripped at runtime by numba)

PR Type:

  • New Feature
  • Bugfix
  • Documentation / Code Style

Additional Information

  • 79 insertions, 56 deletions (signature reformatting only)
  • black, isort, and py_compile all pass locally
  • No logic changes whatsoever — annotations and module docstring only
  • Follows the same pattern as recently merged PR Add typing to speech_to_text_finetune.py #15326 (typing for speech_to_text_finetune.py)
  • Tag for TTS review: @blisc

Adds complete type annotations to 26 public functions and a module-level
docstring in nemo/collections/tts/parts/utils/helpers.py as required by
CONTRIBUTING.md: 'Use Python 3 type hints for every class and method
exposed to the user.'

Changes:
- Added module-level docstring describing the utility module
- Added Iterable to typing imports
- Annotated 26 public functions covering: attention binarization,
  Griffin-Lim, audio logging, pitch/spectrogram plotting, segment
  slicing, path generation, TTS input sampling, and speaker embeddings
- Fixed torch.tensor -> torch.Tensor in regulate_len signature
- No logic changes — annotations and docstring only

black and isort checks pass locally.

Signed-off-by: Hackathon User <hackathon@example.com>
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 17, 2026

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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request TTS waiting-on-maintainers Waiting on maintainers to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants