Skip to content

[recipe] qwen2audio & kimiaudio sft on wenetspeech#96

Merged
xingchensong merged 1 commit into
mainfrom
recipe
Jul 9, 2025
Merged

[recipe] qwen2audio & kimiaudio sft on wenetspeech#96
xingchensong merged 1 commit into
mainfrom
recipe

Conversation

@xingchensong

@xingchensong xingchensong commented Jul 9, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added configuration files for Qwen2-Audio-7B and Kimi-Audio-7B models, enabling support for finetuning on ASR tasks.
    • Enhanced training and evaluation script to support multiple audio models, flexible distributed workflows, and detailed logging.
    • Introduced an inference and evaluation stage with automated error rate calculation.
  • Documentation

    • Updated README files to announce new model support and provide detailed ASR results, including comparative performance tables and key observations.
    • Removed outdated TODO section from documentation.
  • Bug Fixes

    • Improved device detection in FLOPS metric calculation to support additional hardware variants.
  • Style

    • Adjusted default instruction formatting in audio processing for consistency.
  • Refactor

    • Updated internal model logic to streamline outputs and token handling, reflecting current ASR-only support and improving audio token identification.

@coderabbitai

coderabbitai Bot commented Jul 9, 2025

Copy link
Copy Markdown

Walkthrough

This update introduces support for finetuning and evaluating the Qwen2-Audio-7B and Kimi-Audio-7B models on ASR tasks. It adds new configuration files, expands documentation with results and observations, generalizes the training/evaluation script for multiple models, and makes minor code adjustments for output consistency and device compatibility.

Changes

File(s) Change Summary
README.md Added "Latest News" section for ASR model support; removed outdated TODO section.
examples/audio/sft/asr/README.md Expanded with detailed WenetSpeech results, table of experiments, and key observations.
examples/audio/sft/asr/wenetspeech/config/Kimi-Audio-7B*.json
examples/audio/sft/asr/wenetspeech/config/Qwen2-Audio-7B.json
Added new JSON configs for Kimi-Audio-7B, Kimi-Audio-7B-Instruct, and Qwen2-Audio-7B models, specifying architecture and params.
examples/audio/sft/asr/wenetspeech/run.sh Generalized script to support multiple models, dynamic configs, improved logging, and added inference/evaluation stage.
touchnet/models/kimi_audio/modeling_kimi_audio.py Modified forward method to return only text logits for ASR; audio logits omitted for now.
touchnet/models/kimi_audio/processing_kimi_audio.py Changed default instruction string in dynamic_batch to include a colon.
touchnet/models/qwen2_audio/init.py Updated attribute from audio_token_id to audio_token_index in Qwen2AudioForConditionalGeneration's forward method.
touchnet/utils/metrics.py Added "H20Z" device support for peak FLOPS calculation in get_peak_flops.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script
    participant ModelConfig
    participant Trainer
    participant Inference
    participant Evaluator

    User->>Script: Select model (Qwen2/Kimi)
    Script->>ModelConfig: Load model config JSON
    Script->>Trainer: Start training with config
    Trainer->>Script: Save checkpoints
    Script->>Inference: Run inference on test sets
    Inference->>Evaluator: Generate transcriptions
    Evaluator->>Script: Compute and report WER
Loading

Possibly related PRs

  • [models] support kimi audio #79: Introduced the initial implementation and core codebase for the KimiAudio model, which this PR extends with new configs, documentation, and training/evaluation scripts.

Suggested reviewers

  • Mddct

Poem

In the warren of code, new models appear,
Qwen2 and Kimi, their voices now clear.
With configs and scripts, results shining bright,
ASR finetuning takes off in flight.
A hop and a skip, with metrics in view—
The rabbits rejoice: “Transcribe something new!”
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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: 2

♻️ Duplicate comments (1)
examples/audio/sft/asr/wenetspeech/config/Kimi-Audio-7B-Instruct.json (1)

34-37: Same sliding-window inconsistency as base Kimi config

See comment on Kimi-Audio-7B.json. Align the two fields for clarity.

🧹 Nitpick comments (5)
README.md (1)

15-18: Fix formatting issues in the Latest News section

Static analysis identified several formatting issues that should be addressed:

Apply these fixes:

## Latest News 🔥
-- [2025/07/07] We support finetuning `Qwen2-Audio-7B` & `Kimi-Audio-7B` on ASR task! See [WeneSpeech results](examples/audio/sft//asr/README.md) for details.
+- [2025/07/07] We support finetuning `Qwen2-Audio-7B` & `Kimi-Audio-7B` on ASR tasks! See [WenetSpeech results](examples/audio/sft/asr/README.md) for details.

Changes made:

  1. "task" → "tasks" (plural form)
  2. "WeneSpeech" → "WenetSpeech" (correct spelling)
  3. Fixed double slash in path: "//asr" → "/asr"
examples/audio/sft/asr/README.md (2)

6-6: Fix minor punctuation/formatting of external link note

“NOTE:” is followed by two spaces before the sentence continues. Markdown renders fine, but remove the extra spaces for consistency and to avoid triggering linters.


22-26: Correct typos & agreement in the observation list

Several small language glitches slipped in (e.g. “Finetuning … get”, “benifits”, missing article). Tighten wording – it improves credibility of the experimental write-up.

-1. Comparing 0 & 1, Finetuning Qwen2-Audio on wenetspeech training set get much better results.
-2. Comparing 1 & 2, Pretraining benifits a lot on downstream task.
+1. Comparing 0 & 1, finetuning Qwen2-Audio on the WenetSpeech training set **gets** much better results.
+2. Comparing 1 & 2, pre-training **benefits** downstream tasks substantially.

(Apply similar grammar fixes to items 3-5.)

examples/audio/sft/asr/wenetspeech/run.sh (1)

254-280: Huge positional-parameter block is unquoted – can break on whitespace

Inside the if [ "${model_type}" = "touch_audio" ]; then … fi substitution, the multi-line echo contains many unquoted expansions (${stack} ${stride}). If either variable is empty, trailing spaces collapse and options shift.

Recommend switching to a here-document or quoting the whole string:

cat <<EOF
  --lr_scheduler_lr_min 0.0 \
  --audiofeat_stack_length ${stack} \
  --audiofeat_stride_length ${stride} \

EOF
examples/audio/sft/asr/wenetspeech/config/Kimi-Audio-7B.json (1)

34-37: sliding_window set but use_sliding_window is false

You specify "sliding_window": 4096 while "use_sliding_window": false.
Either drop the size or enable the feature; keeping both is confusing and may be ignored by downstream libraries.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6155bbd and d7ff762.

📒 Files selected for processing (10)
  • README.md (1 hunks)
  • examples/audio/sft/asr/README.md (1 hunks)
  • examples/audio/sft/asr/wenetspeech/config/Kimi-Audio-7B-Instruct.json (1 hunks)
  • examples/audio/sft/asr/wenetspeech/config/Kimi-Audio-7B.json (1 hunks)
  • examples/audio/sft/asr/wenetspeech/config/Qwen2-Audio-7B.json (1 hunks)
  • examples/audio/sft/asr/wenetspeech/run.sh (4 hunks)
  • touchnet/models/kimi_audio/modeling_kimi_audio.py (1 hunks)
  • touchnet/models/kimi_audio/processing_kimi_audio.py (1 hunks)
  • touchnet/models/qwen2_audio/__init__.py (3 hunks)
  • touchnet/utils/metrics.py (1 hunks)
🧰 Additional context used
🪛 LanguageTool
examples/audio/sft/asr/README.md

[grammar] ~6-~6: There might be a problem here.
Context: ...used the same WER calculation method as SpeechIO. ## WenetSpeech | exp id | model | note | instruct...

(QB_NEW_EN_MERGED_MATCH)


[grammar] ~22-~22: Insert the missing word
Context: ...5 del, 8927 sub ] | 1. Comparing 0 & 1, Finetuning Qwen2-Audio on wenetspeech tr...

(QB_NEW_EN_OTHER_ERROR_IDS_32)


[grammar] ~22-~22: Use articles correctly
Context: ...Comparing 0 & 1, Finetuning Qwen2-Audio on wenetspeech training set get much better...

(QB_NEW_EN_OTHER_ERROR_IDS_11)


[grammar] ~22-~22: Make sure you are using the right part of speech
Context: ...Qwen2-Audio on wenetspeech training set get much better results. 2. Comparing 1 & 2...

(QB_NEW_EN_OTHER_ERROR_IDS_21)


[grammar] ~23-~23: Ensure spelling is correct
Context: ...uch better results. 2. Comparing 1 & 2, Pretraining benifits a lot on downstream task. 3. Comparing ...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~23-~23: Make sure to use plural and singular nouns correctly
Context: ...retraining benifits a lot on downstream task. 3. Comparing 3 & 4, Kimi-Audio-7B-Inst...

(QB_NEW_EN_OTHER_ERROR_IDS_10)


[style] ~24-~24: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...g benifits a lot on downstream task. 3. Comparing 3 & 4, Kimi-Audio-7B-Instruct is highly...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[uncategorized] ~26-~26: Do not mix variants of the same word (‘pre-train’ and ‘pretrain’) within a single text.
Context: ...an order-of-magnitude difference in the pre-training data between Qwen2-Audio-7B and Kimi-Au...

(EN_WORD_COHERENCY)

README.md

[grammar] ~17-~17: Insert the missing word
Context: ...> ## Latest News 🔥 - [2025/07/07] We support finetuning Qwen2-Audio-7B & `Kimi-Audi...

(QB_NEW_EN_OTHER_ERROR_IDS_32)


[grammar] ~17-~17: Make sure to use plural and singular nouns correctly
Context: ...wen2-Audio-7B&Kimi-Audio-7B` on ASR task! See [WeneSpeech results](examples/audio...

(QB_NEW_EN_OTHER_ERROR_IDS_10)


[grammar] ~17-~17: Use correct spacing
Context: ...(examples/audio/sft//asr/README.md) for details. ## Overview 👆 touchnet is highly motiv...

(QB_NEW_EN_OTHER_ERROR_IDS_5)

🪛 Shellcheck (0.10.0)
examples/audio/sft/asr/wenetspeech/run.sh

[warning] 125-125: Quote this to prevent word splitting.

(SC2046)


[warning] 205-205: Quote this to prevent word splitting.

(SC2046)


[warning] 254-280: Quote this to prevent word splitting.

(SC2046)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: unit-test (ubuntu-22.04, 3.10.16)
🔇 Additional comments (6)
touchnet/models/kimi_audio/processing_kimi_audio.py (1)

66-66: LGTM - Instruction format improvement

Adding the colon to the instruction string aligns with standard prompt formatting conventions and improves consistency.

touchnet/utils/metrics.py (1)

93-93: LGTM - Device support expansion

Adding support for the "H20Z" device variant with the same peak FLOPS as H200 is appropriate.

touchnet/models/qwen2_audio/__init__.py (1)

198-198: Attribute rename verified across codebase

Search results show no remaining audio_token_id references and only three uses of audio_token_index in touchnet/models/qwen2_audio/__init__.py:

• Line 198
• Line 207
• Line 226

Please ensure your configuration class defines audio_token_index (replacing the old audio_token_id) to prevent runtime errors.

touchnet/models/kimi_audio/modeling_kimi_audio.py (1)

1069-1081: Ignore audio_logits removal – no downstream usage detected

A search across the repository shows that audio_logits only appears in internal modeling methods (e.g., sample_audio_logits) and is never unpacked or referenced by any calling or inference code. Removing it from the forward output does not break any existing code paths.

• All rg "audio_logits" hits are in modeling_kimi_audio.py (lines around 748, 1067, 1178–1184).
inference_kimi_audio.py instantiates the model and calls .generate() or sample_audio_logits, but never unpacks audio_logits from forward.
• No other modules reference audio_logits in output tuples or expect two logits in forward response.

You can proceed with ASR-only support and reintroduce audio_logits later for TTS without backward-compatibility concerns.

Likely an incorrect or invalid review comment.

examples/audio/sft/asr/wenetspeech/run.sh (1)

185-187: --local-ranks-filter mismatches nproc_per_node

You launch all GPUs with torchrun --nproc_per_node=$num_gpus, yet immediately filter to "0,1,2,3,4,5,6,7".
On machines with fewer than 8 GPUs (or when CUDA_VISIBLE_DEVICES hides some), this silently drops ranks and hangs. Either:

  1. Drop --local-ranks-filter, or
  2. Derive the list dynamically from $gpu_list.

[further verification recommended]

examples/audio/sft/asr/wenetspeech/config/Qwen2-Audio-7B.json (1)

24-25: Confirm audio_token_index within vocabulary range

audio_token_index=151646 < vocab_size=156032 – OK.
Just a quick sanity check; no action needed.

Comment thread examples/audio/sft/asr/wenetspeech/run.sh
Comment thread examples/audio/sft/asr/wenetspeech/run.sh
@xingchensong xingchensong merged commit 013a7e5 into main Jul 9, 2025
4 checks passed
@xingchensong xingchensong deleted the recipe branch July 9, 2025 06:38
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