Skip to content

adding --use-adapter and --adapter-dim to zipformer_adapter decode.py#2079

Open
Elquintas wants to merge 4 commits into
k2-fsa:masterfrom
Elquintas:update_decoder_script
Open

adding --use-adapter and --adapter-dim to zipformer_adapter decode.py#2079
Elquintas wants to merge 4 commits into
k2-fsa:masterfrom
Elquintas:update_decoder_script

Conversation

@Elquintas

@Elquintas Elquintas commented Apr 15, 2026

Copy link
Copy Markdown

egs/librispeech/ASR/zipformer_adapter/decode.py expects --use-adapter and --adapter-dim arguments. I've added both arguments in the parser and updated the docstring.

Summary by CodeRabbit

  • New Features

    • Added command-line options to control adapters during ASR decoding: --use-adapters (0/1) and --adapter-dim (integer), making adapter usage configurable at decode time.
  • Documentation

    • Updated usage examples and instructions to show how to enable adapters and set adapter dimensionality in decoding commands.

@coderabbitai

coderabbitai Bot commented Apr 15, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4e6d1a8f-b66e-4679-b277-ca1526bc922b

📥 Commits

Reviewing files that changed from the base of the PR and between f5a3a44 and f3bcef2.

📒 Files selected for processing (1)
  • egs/librispeech/ASR/zipformer_adapter/decode.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • egs/librispeech/ASR/zipformer_adapter/decode.py

📝 Walkthrough

Walkthrough

The zipformer_adapter decode script now accepts two new CLI arguments—--use-adapters and --adapter-dim—and updates usage examples to include --use-adapters 1 --adapter-dim 16. Parsed values are merged into params; no decoding control flow was changed here.

Changes

Cohort / File(s) Summary
Adapter CLI Parameters
egs/librispeech/ASR/zipformer_adapter/decode.py
Added CLI arguments --use-adapters (int, default 1) and --adapter-dim (int, default 16). Updated usage examples to append --use-adapters 1 --adapter-dim 16. Parsed values are merged into params via the existing params.update(vars(args)) flow.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I nibble at flags, --use-adapters in tow,
I tuck --adapter-dim where soft bytes grow,
Greedy hops and beam bounds, the decode trails wide,
Tiny adapters snug at my side,
A rabbit cheers as params glide!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding two CLI arguments (--use-adapter and --adapter-dim) to the zipformer_adapter decode.py file.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the decode.py script for the Zipformer adapter by modifying docstring examples and adding --use-adapters and --adapter-dim arguments to the parser. The review feedback identifies a naming inconsistency between the examples and the parser, suggests using str2bool for boolean arguments to handle string inputs correctly, and recommends updating the default adapter dimension for consistency with training scripts.

Comment thread egs/librispeech/ASR/zipformer_adapter/decode.py Outdated
Comment thread egs/librispeech/ASR/zipformer_adapter/decode.py
Comment thread egs/librispeech/ASR/zipformer_adapter/decode.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50be6cb778

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread egs/librispeech/ASR/zipformer_adapter/decode.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
egs/librispeech/ASR/zipformer_adapter/decode.py (1)

23-27: ⚠️ Potential issue | 🔴 Critical

--use-adapter is completely unusable as documented.

Documentation (lines 23, 26, 35, 46, 57, 70, 85, 100, 113) shows --use-adapter True and --use-adapter False, but line 396 defines --use-adapters (plural) with type=int. Parsing fails with: error: argument --use-adapters: invalid int value: 'True'.

Fix by making the flag name singular and the type boolean-compatible:

Suggested fix
     parser.add_argument(
-        "--use-adapters",
-        type=int,
-        default=0,
-        help="Whether to use adapters",
+        "--use-adapter",
+        type=str2bool,
+        default=False,
+        help="Whether to use adapters",
     )

Also applies to: 35–36, 395–407

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@egs/librispeech/ASR/zipformer_adapter/decode.py` around lines 23 - 27, The
flag is defined as --use-adapters (plural) with type=int but docs and examples
use --use-adapter True/False; update the argument registration (the
parser.add_argument call that defines "--use-adapters") to use the singular name
"--use-adapter" and make it boolean-compatible (use action="store_true" /
action="store_false" or type=bool handling) so CLI accepts True/False as
documented and the help text matches lines referencing --use-adapter; ensure any
downstream references to the variable (e.g., use_adapters or args.use_adapters)
are renamed/aliased to args.use_adapter to stay consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@egs/librispeech/ASR/zipformer_adapter/decode.py`:
- Around line 402-407: The CLI argument for adapter bottleneck uses default=0
which conflicts with Zipformer2's adapter_dim default of 16; change the
parser.add_argument for "--adapter-dim" to default=16 to align with the model,
and add a parse-time guard after argument parsing that checks if adapters are
enabled (e.g., the flag controlling adapter usage in this script) and ensures
adapter_dim > 0—if not, either set it to 16 or raise a clear error message so
adapters are never instantiated with a zero bottleneck.

---

Outside diff comments:
In `@egs/librispeech/ASR/zipformer_adapter/decode.py`:
- Around line 23-27: The flag is defined as --use-adapters (plural) with
type=int but docs and examples use --use-adapter True/False; update the argument
registration (the parser.add_argument call that defines "--use-adapters") to use
the singular name "--use-adapter" and make it boolean-compatible (use
action="store_true" / action="store_false" or type=bool handling) so CLI accepts
True/False as documented and the help text matches lines referencing
--use-adapter; ensure any downstream references to the variable (e.g.,
use_adapters or args.use_adapters) are renamed/aliased to args.use_adapter to
stay consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 35038d16-bc7f-4e0c-a3f3-ea46ee9018ec

📥 Commits

Reviewing files that changed from the base of the PR and between 21f6cb4 and 50be6cb.

📒 Files selected for processing (1)
  • egs/librispeech/ASR/zipformer_adapter/decode.py

Comment thread egs/librispeech/ASR/zipformer_adapter/decode.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
egs/librispeech/ASR/zipformer_adapter/decode.py (1)

395-407: ⚠️ Potential issue | 🟠 Major

Guard adapter configuration and avoid zero adapter dimension by default.

Line 405 still sets --adapter-dim to 0. Combined with --use-adapters 1, this permits an invalid adapter setup unless users always override it manually. This was already raised in prior review and remains unresolved.

Suggested fix
     parser.add_argument(
         "--adapter-dim",
         type=int,
-        default=0,
+        default=16,
         help="Adapter dimension",
     )
 def main():
     parser = get_parser()
     LibriSpeechAsrDataModule.add_arguments(parser)
     LmScorer.add_arguments(parser)
     args = parser.parse_args()
+    if args.use_adapters and args.adapter_dim <= 0:
+        parser.error("--adapter-dim must be > 0 when --use-adapters=1")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@egs/librispeech/ASR/zipformer_adapter/decode.py` around lines 395 - 407, The
CLI currently allows enabling adapters via the --use-adapters flag while
--adapter-dim defaults to 0, which permits an invalid configuration; update the
parser/validation so that parser.add_argument("--adapter-dim", ...) uses a
sensible non-zero default (e.g., 32/64) or add a runtime check after parsing
that raises an error if args.use_adapters is true and args.adapter_dim <= 0;
reference the parser.add_argument calls for "--use-adapters" and "--adapter-dim"
and enforce the validation immediately after args = parser.parse_args() to
prevent starting with a zero adapter dimension.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@egs/librispeech/ASR/zipformer_adapter/decode.py`:
- Around line 395-407: The CLI currently allows enabling adapters via the
--use-adapters flag while --adapter-dim defaults to 0, which permits an invalid
configuration; update the parser/validation so that
parser.add_argument("--adapter-dim", ...) uses a sensible non-zero default
(e.g., 32/64) or add a runtime check after parsing that raises an error if
args.use_adapters is true and args.adapter_dim <= 0; reference the
parser.add_argument calls for "--use-adapters" and "--adapter-dim" and enforce
the validation immediately after args = parser.parse_args() to prevent starting
with a zero adapter dimension.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c1a99599-9cdd-4a77-b306-c7e9a58660cc

📥 Commits

Reviewing files that changed from the base of the PR and between 50be6cb and 3fa0f57.

📒 Files selected for processing (1)
  • egs/librispeech/ASR/zipformer_adapter/decode.py

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.

1 participant