Skip to content

Conversation

@alien-0119
Copy link
Collaborator

@alien-0119 alien-0119 commented Oct 31, 2025

What does this PR do?

Adds # (feature)
Add Kyutai Speech-To-Text model and fast ut.

Usage Example:

import mindspore as ms
from datasets import load_dataset, Audio
from transformers import KyutaiSpeechToTextProcessor
from mindone.transformers import KyutaiSpeechToTextForConditionalGeneration

model_id = "kyutai/stt-2.6b-en-trfs"

processor = KyutaiSpeechToTextProcessor.from_pretrained(model_id)
model = KyutaiSpeechToTextForConditionalGeneration.from_pretrained(model_id)

ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")

ds = ds.cast_column("audio", Audio(sampling_rate=24000))
inputs = processor(ds[0]["audio"]["array"])
inputs = {k: ms.tensor(v.numpy()) for k, v in inputs.items()}

output_tokens = model.generate(**inputs)
print(processor.batch_decode(output_tokens, skip_special_tokens=True))
# ['Mr. Quilter is the apostle of the middle classes, and we are glad to welcome his gospel.']

Performance:
Experiments were tested on Ascend Atlas 800T A2 machines with mindspore 2.7.0 pynative mode.

model precision weight load(s) s/step
kyutai/stt-2.6b-en-trfs fp32 85.151 0.187
kyutai/stt-2.6b-en-trfs fp16 104.240 0.143
kyutai/stt-2.6b-en-trfs bf16 64.224 0.212

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline?
  • Did you make sure to update the documentation with your changes? E.g. record bug fixes or new features in What's New. Here are the
    documentation guidelines
  • Did you build and run the code without any errors?
  • Did you report the running environment (NPU type/MS version) and performance in the doc? (better record it for data loading, model inference, or training tasks)
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@xxx

@alien-0119 alien-0119 requested a review from vigo999 as a code owner October 31, 2025 06:58
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @alien-0119, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Mimi model by introducing robust streaming capabilities for its convolutional encoder, allowing for more efficient processing of continuous audio. It achieves this through a new padding cache mechanism, alongside a general cleanup and simplification of attention and initialization logic, ensuring better alignment with MindSpore's current API and improved model performance for real-time applications.

Highlights

  • Streaming Support for Convolutions: Introduced MimiConv1dPaddingCache and integrated it into MimiConv1d, MimiResnetBlock, and MimiEncoder to enable efficient streaming for causal convolutional layers.
  • Encoder Refactoring for Streaming: The MimiEncoder now tracks and initializes layer_idx for its convolutional sub-layers, and the MimiModel's encode method supports use_streaming with automatic padding_cache initialization.
  • Output Length and Masking Utilities: Added get_encoded_length and get_audio_codes_mask methods to MimiModel for better control over audio code processing.
  • Attention Mechanism Simplification: Removed dynamic frequency update logic from MimiRotaryEmbedding and streamlined the return values of attention layers by removing past_key_value from their direct outputs.
  • MindSpore Adaptations and Cleanup: Updated MindSpore-specific imports, refined weight initialization, and removed deprecated cache handling logic, aligning the model with current MindSpore practices and transformers library conventions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 introduces streaming support for the Mimi speech-to-text model by adding a padding cache for convolutions. The changes also include several refactorings and updates to align with newer conventions in the library. While the implementation for streaming is mostly on the right track, I've identified a couple of critical issues where methods are removed but still called, which will cause runtime errors. There's also a minor issue of dead code that can be cleaned up.

@alien-0119 alien-0119 force-pushed the kyutai_master branch 2 times, most recently from 2ffcc83 to ebf6f2f Compare October 31, 2025 08:34
@alien-0119 alien-0119 added the new model add new model to mindone label Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new model add new model to mindone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant