Skip to content

Qualcomm AI Engine Direct - Mimi Enablement Stage 2 #10098

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

Merged
merged 2 commits into from
Apr 15, 2025

Conversation

winskuo-quic
Copy link
Collaborator

@winskuo-quic winskuo-quic commented Apr 11, 2025

Summary

  • Support Mimi Encoder
  • Support Mimi Decoder
  • Support OP: CDist
  • Workaround for 0D tensor scenario since QNN does not support 0D tensor

Commands to Execute the model
10 sec as a batch (1 inference for 10 sec audio):
python examples/qualcomm/oss_scripts/moshi/mimi.py -b build-android -s $DEVICE -m SM8650 --chunks_per_batch 125

80s as a batch (125 inferences for 10 sec audio)
python examples/qualcomm/oss_scripts/moshi/mimi.py -b build-android -s $DEVICE -m SM8650

Test plan

  • UT for CDist
  • UT for 0D tensor

@winskuo-quic winskuo-quic requested a review from cccclai as a code owner April 11, 2025 03:28
Copy link

pytorch-bot bot commented Apr 11, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/10098

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 08759d6 with merge base e29a4b5 (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 11, 2025
@winskuo-quic winskuo-quic force-pushed the dev1/winskuo/mimi_stage2 branch from 3377f9d to a7cd07a Compare April 11, 2025 05:45
@winskuo-quic winskuo-quic force-pushed the dev1/winskuo/mimi_stage2 branch from a7cd07a to 4501ff2 Compare April 11, 2025 08:41
@winskuo-quic
Copy link
Collaborator Author

Hi @cccclai, @iseeyuan, @billmguo,
This PR is to enable mimi without streaming mode.
I have listed to execution commands in the summary section.
Please have a look.
Thanks

@facebook-github-bot
Copy link
Contributor

@cccclai has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

from executorch.exir.pass_base import ExportPass, PassResult


class Remove0DTensor(ExportPass):
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @cccclai,
Thanks for reviewing the PR.
I believe the pass you are suggesting is to change input from 0d to 1d tensor.
However, for our case, this 0D tensor happened during select op in the middle of graph. We just removed this select op since it does not affect the logic of the graph.
The exact point where 0D tensor occurs in mimi is under moshi/quantization/core_vq.py, where is tries to create a 1D tensor and retrieve index 0.
image

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, I guess for this specific logic, it's more efficient to remove the select op.

A more generic way to handle 0-d tensor is to convert it to 1-d tensor. Like following

class Rank0ToRank1Pass(ExportPass):
    """
    Replace Rank-0 Tensor to Rank-1 Tensor for all the inputs.
    """

    def __init__(self) -> None:
        super().__init__()

    def call(self, graph_module: torch.fx.GraphModule) -> PassResult:
        for node in graph_module.graph.nodes:
            // we can make the pass configurable to decide what kind of node we want to reshape to 1-d tensor
            if node.op == "call_function" and node.meta["val"].shape == ():
                node.meta["val"] = node.meta["val"].reshape(1, 1)
        graph_module.recompile()
        return PassResult(graph_module, True)

Copy link
Contributor

@cccclai cccclai left a comment

Choose a reason for hiding this comment

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

Thank you for enabling mimi!

@cccclai cccclai added the release notes: qualcomm Changes to the Qualcomm backend delegate label Apr 15, 2025
@cccclai cccclai merged commit 4559a61 into pytorch:main Apr 15, 2025
89 of 91 checks passed
keyprocedure pushed a commit to keyprocedure/executorch that referenced this pull request Apr 21, 2025
### Summary

- Support Mimi Encoder
- Support Mimi Decoder
- Support OP: CDist
- Workaround for 0D tensor scenario since QNN does not support 0D tensor

Commands to Execute the model
10 sec as a batch (1 inference for 10 sec audio):
`python examples/qualcomm/oss_scripts/moshi/mimi.py -b build-android -s
$DEVICE -m SM8650 --chunks_per_batch 125`

80s as a batch (125 inferences for 10 sec audio)
`python examples/qualcomm/oss_scripts/moshi/mimi.py -b build-android -s
$DEVICE -m SM8650`

### Test plan

- UT for CDist
- UT for 0D tensor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: qualcomm Changes to the Qualcomm backend delegate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants