Skip to content

Update scorer.py#2617

Merged
pplantinga merged 9 commits intospeechbrain:developfrom
raotnameh:develop
Feb 7, 2026
Merged

Update scorer.py#2617
pplantinga merged 9 commits intospeechbrain:developfrom
raotnameh:develop

Conversation

@raotnameh
Copy link
Copy Markdown
Contributor

This PR does not do anything Just avoids an edge case.

  • This is just to avoid an edge case in the case if candidates in log_probs is less than int(beam_size * self.scorer_beam_scale)

  • Error I faced.

                  _, candidates = log_probs.topk(                                                                                                                                                                                                                                                        
                      RuntimeError: selected index k out of range  
    

# This is just to avoid an edge case in the case if candidates in log_probs is less than int(beam_size * self.scorer_beam_scale)
        '''
        Error I faced.  
                    _, candidates = log_probs.topk(                                                                                                                                                                                                                                                        
                        RuntimeError: selected index k out of range  
        '''
@TParcollet TParcollet added this to the v1.1.0 milestone Oct 9, 2025
Copy link
Copy Markdown
Collaborator

@pplantinga pplantinga left a comment

Choose a reason for hiding this comment

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

Looks like a good change, once comments are addressed

@pplantinga pplantinga added the bug Something isn't working label Nov 24, 2025
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 updates ScorerBuilder.score() to avoid a RuntimeError: selected index k out of range when selecting top-k candidates for partial scorers by ensuring topk() is not called with k > vocab_size.

Changes:

  • Introduce a computed k (currently sbc) that caps topk’s k to log_probs.shape[-1] when the vocabulary is smaller than int(beam_size * scorer_beam_scale).
  • Replace the inline topk(int(beam_size * scorer_beam_scale)) call with topk(sbc).

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

Comment on lines +1260 to +1261
# select candidates from the results of full scorers for partial scorers
_, candidates = log_probs.topk(
int(beam_size * self.scorer_beam_scale), dim=-1
)
_, candidates = log_probs.topk(sbc, dim=-1)
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

This change addresses a runtime edge case (topk with k > vocab), but there doesn’t appear to be a unit test covering ScorerBuilder.score() candidate selection. Adding a small test that constructs a ScorerBuilder and verifies score() works when vocab_size < int(beam_size * scorer_beam_scale) (and also when the computed k would be 0) would help prevent regressions.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

@pplantinga pplantinga left a comment

Choose a reason for hiding this comment

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

LGTM

@pplantinga pplantinga merged commit de1c94d into speechbrain:develop Feb 7, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants