-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Changes required for enabling prompt based models in Nemo Inference #15036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
124fcb8
6d4022e
ec18de4
e79e300
2e8a733
552a449
f027109
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -70,6 +70,7 @@ def __init__( | |||||||||||||||||
| self.init_bpe_decoder() | ||||||||||||||||||
| self.init_decoding_computer() | ||||||||||||||||||
| self.init_text_processor(cfg, itn_model) | ||||||||||||||||||
| self.init_prompt_support() | ||||||||||||||||||
| super().__init__() | ||||||||||||||||||
|
|
||||||||||||||||||
| def init_parameters(self, cfg: DictConfig) -> None: | ||||||||||||||||||
|
|
@@ -174,6 +175,99 @@ def init_decoding_computer(self) -> None: | |||||||||||||||||
| if self.stateful: | ||||||||||||||||||
| self.decoding_computer = self.asr_model.asr_model.decoding.decoding.decoding_computer | ||||||||||||||||||
|
|
||||||||||||||||||
| def init_prompt_support(self) -> None: | ||||||||||||||||||
| """Initialize prompt support for multilingual models.""" | ||||||||||||||||||
| self.prompt_enabled = hasattr(self.asr_model.asr_model, 'concat') and self.asr_model.asr_model.concat | ||||||||||||||||||
|
|
||||||||||||||||||
| if self.prompt_enabled: | ||||||||||||||||||
| self._prompt_config = self._load_prompt_config() | ||||||||||||||||||
| self._prompt_matrix_cache = {} | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+184
to
+185
|
||||||||||||||||||
| self._prompt_matrix_cache = {} | |
| if not self._prompt_config: | |
| raise RuntimeError( | |
| "Model has concat=True but prompt configuration (num_prompts, prompt_dictionary) " | |
| "is missing or invalid in model_defaults." | |
| ) | |
| self._prompt_matrix_cache = {} |
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded "en-US" language code assumes this language will always be present in the prompt dictionary. If a prompt-enabled model doesn't include "en-US" in its prompt dictionary, this will cause a ValueError during initialization in init_zero_enc().
Consider either:
- Using the first available language from the prompt dictionary
- Making this configurable
- Adding validation at initialization to ensure "en-US" exists
Example fix:
# Get the first available language or use a configurable default
available_languages = list(self._prompt_config['prompt_dict'].keys())
default_lang = available_languages[0] if available_languages else "en-US"
default_prompt_idx = self._resolve_prompt_index(default_lang)| # Use "en-US" as the default prompt for zero encoding | |
| # This region is sliced out before decoding, so language choice doesn't matter | |
| default_prompt_idx = self._resolve_prompt_index("en-US") | |
| # Use the first available language as the default prompt for zero encoding | |
| # This region is sliced out before decoding, so language choice doesn't matter | |
| available_languages = list(self._prompt_config['prompt_dict'].keys()) | |
| default_lang = available_languages[0] if available_languages else "en-US" | |
| default_prompt_idx = self._resolve_prompt_index(default_lang) |
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The augment_with_defaults call is missing the default_language_code parameter. According to the updated signature in request_options.py, this parameter should be passed here. Without it, the default language code will always be None even if a default was intended to be set.
Consider adding:
new_options = options.augment_with_defaults(
default_enable_itn=self.text_processor.is_itn_enabled(),
default_enable_pnc=self.text_processor.is_pnc_enabled(),
default_stop_history_eou=self.stop_history_eou_in_milliseconds,
default_asr_output_granularity=self.asr_output_granularity,
default_language_code=None, # or an appropriate default
)| default_asr_output_granularity=self.asr_output_granularity, | |
| default_asr_output_granularity=self.asr_output_granularity, | |
| default_language_code=None, # or "en-US" if a default is desired |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is duplicated code for building prompts in both
encode_raw_signalsandencode_processed_signals. It would be better to move this logic into a separate helper method.