Skip to content

Implement per-key padding configuration in PaddedBatch#3008

Merged
TParcollet merged 10 commits intodevelopfrom
add-padded-keys
Dec 1, 2025
Merged

Implement per-key padding configuration in PaddedBatch#3008
TParcollet merged 10 commits intodevelopfrom
add-padded-keys

Conversation

@Adel-Moumen
Copy link
Copy Markdown
Collaborator

Added support for per-key padding configuration in PaddedBatch.

What does this PR do?

Allow keys to have specific padding values.

Before submitting
  • Did you read the contributor guideline?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Does your code adhere to project-specific code style and conventions?

PR review

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified
  • Confirm that the changes adhere to compatibility requirements (e.g., Python version, platform)
  • Review the self-review checklist to ensure the code is ready for review

Adel-Moumen and others added 5 commits November 29, 2025 17:14
Added support for per-key padding configuration in PaddedBatch.
Added tests for PaddedBatch functionality including per-key padding, mixed configuration, numpy array support, and backward compatibility.
Initialize per_key_padding_kwargs to an empty dictionary by default.
Copy link
Copy Markdown
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 PR adds per-key padding configuration support to the PaddedBatch class, allowing different padding values (and other padding parameters) to be specified for different data keys in a batch. This is useful for scenarios where different types of data require different padding strategies, such as padding audio with 0 and labels with -100 (a common ignore index in loss calculations).

  • Adds a new per_key_padding_kwargs parameter to PaddedBatch.__init__() that accepts a dictionary mapping keys to padding configuration dictionaries
  • The per-key configuration takes precedence over the global padding_kwargs for specified keys
  • Maintains full backward compatibility with existing code

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
speechbrain/dataio/batch.py Adds per_key_padding_kwargs parameter and implements logic to apply per-key or global padding configuration based on key presence
tests/unittests/test_batching.py Adds comprehensive test coverage including basic per-key padding, mixed configurations, numpy array handling, and backward compatibility

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Adel-Moumen and others added 5 commits November 30, 2025 13:59
Clarify the optional nature of padding_kwargs and per_key_padding_kwargs in the docstring.
Copy link
Copy Markdown
Collaborator

@TParcollet TParcollet left a comment

Choose a reason for hiding this comment

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

Great add thanks!

@TParcollet TParcollet merged commit c94d5e2 into develop Dec 1, 2025
5 checks passed
@TParcollet TParcollet deleted the add-padded-keys branch December 1, 2025 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants