Skip to content

Conversation

@Cui-yshoho
Copy link
Contributor

What does this PR do?

Fixes # (issue)

Adds # (feature)

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

@Cui-yshoho Cui-yshoho requested a review from vigo999 as a code owner October 24, 2025 11:16
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Cui-yshoho, 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 integrates the advanced PRX text-to-image generation model into the diffusers library. The changes encompass the full model architecture, a specialized inference pipeline, and foundational utilities for efficient attention processing in MindSpore, ensuring robust functionality and ease of use for high-quality image synthesis.

Highlights

  • PRX Model Integration: Introduces the PRX text-to-image generation model, known for high-quality image synthesis using a simplified MMDIT architecture and flow matching with discrete scheduling.
  • MindSpore Attention Dispatch: Adds a new utility (attention_dispatch.py) to efficiently handle attention mechanisms within the MindSpore framework, including Flash Attention, and addresses PyTorch/MindSpore mask differences.
  • Comprehensive Pipeline Implementation: Provides a complete PRXPipeline with text preprocessing, flexible VAE support (Flux VAE, DC-AE), and resolution binning for optimized image generation, leveraging Google's T5Gemma-2B-2B-UL2 for text encoding.
  • Extensive Documentation and Testing: Includes dedicated documentation for the PRX model and pipeline, along with new unit tests to ensure functionality and MindSpore/PyTorch compatibility for the new transformer and pipeline.
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 the PRX model, a new text-to-image transformer, into the diffusers library. The changes are comprehensive, including the PRXTransformer2DModel, the PRXPipeline, along with corresponding documentation and tests. I've identified a critical issue in the Rotary Positional Embedding (RoPE) application logic within the transformer model that needs to be addressed. Additionally, there are a few minor issues in the documentation and a bug in the new test case that I've flagged for correction. Overall, this is a great contribution.

Comment on lines +60 to +78
def apply_rope(xq: ms.Tensor, freqs_cis: ms.Tensor) -> ms.Tensor:
r"""
Applies rotary positional embeddings (RoPE) to a query tensor.

Args:
xq (`ms.Tensor`):
Input tensor of shape `(..., dim)` representing the queries.
freqs_cis (`ms.Tensor`):
Precomputed rotary frequency components of shape `(..., dim/2, 2)` containing cosine and sine pairs.

Returns:
`ms.Tensor`:
Tensor of the same shape as `xq` with rotary embeddings applied.
"""
xq_ = xq.float().reshape(*xq.shape[:-1], -1, 1, 2)
# Ensure freqs_cis is on the same device as queries to avoid device mismatches with offloading
freqs_cis = freqs_cis.to(dtype=xq_.dtype)
xq_out = freqs_cis[..., 0] * xq_[..., 0] + freqs_cis[..., 1] * xq_[..., 1]
return xq_out.reshape(*xq.shape).type_as(xq)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The implementation of apply_rope has a bug that will cause a runtime error due to a shape mismatch during multiplication. The rotary embeddings should be applied using matrix multiplication. The current implementation attempts an element-wise operation that is not broadcast-compatible.

I've provided a corrected version that performs the intended batched matrix-vector product. I've also updated the docstring to reflect the correct shape of freqs_cis.

Suggested change
def apply_rope(xq: ms.Tensor, freqs_cis: ms.Tensor) -> ms.Tensor:
r"""
Applies rotary positional embeddings (RoPE) to a query tensor.
Args:
xq (`ms.Tensor`):
Input tensor of shape `(..., dim)` representing the queries.
freqs_cis (`ms.Tensor`):
Precomputed rotary frequency components of shape `(..., dim/2, 2)` containing cosine and sine pairs.
Returns:
`ms.Tensor`:
Tensor of the same shape as `xq` with rotary embeddings applied.
"""
xq_ = xq.float().reshape(*xq.shape[:-1], -1, 1, 2)
# Ensure freqs_cis is on the same device as queries to avoid device mismatches with offloading
freqs_cis = freqs_cis.to(dtype=xq_.dtype)
xq_out = freqs_cis[..., 0] * xq_[..., 0] + freqs_cis[..., 1] * xq_[..., 1]
return xq_out.reshape(*xq.shape).type_as(xq)
def apply_rope(xq: ms.Tensor, freqs_cis: ms.Tensor) -> ms.Tensor:
r"""
Applies rotary positional embeddings (RoPE) to a query tensor.
Args:
xq (`ms.Tensor`):
Input tensor of shape `(..., dim)` representing the queries.
freqs_cis (`ms.Tensor`):
Precomputed rotary frequency components of shape `(..., dim/2, 2, 2)` containing rotation matrices.
Returns:
`ms.Tensor`:
Tensor of the same shape as `xq` with rotary embeddings applied.
"""
xq_ = xq.float().reshape(*xq.shape[:-1], -1, 2)
# Ensure freqs_cis is on the same device as queries to avoid device mismatches with offloading
freqs_cis = freqs_cis.to(dtype=xq_.dtype)
xq_ = xq_.unsqueeze(-2)
xq_out = mint.matmul(xq_, freqs_cis).squeeze(-2)
return xq_out.reshape(*xq.shape).type_as(xq)

torch.manual_seed(0)
pt_image = pt_pipe(**inputs).images[0, -3:, -3:, -1]
torch.manual_seed(0)
ms_image = ms_pipe(**inputs)[0][0, -3:, -3:, -1]
Copy link
Contributor

Choose a reason for hiding this comment

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

high

When return_dict=True (the default), the pipeline returns a PRXPipelineOutput object. Accessing the output with [0] will cause a TypeError. You should access the generated images using the .images attribute to be consistent with the PyTorch implementation and to avoid the error.

Suggested change
ms_image = ms_pipe(**inputs)[0][0, -3:, -3:, -1]
ms_image = ms_pipe(**inputs).images[0, -3:, -3:, -1]

| [`Photoroom/prx-512-t2i-sft-distilled`](https://huggingface.co/Photoroom/prx-512-t2i-sft-distilled)| 512 | Yes | Yes | 8-step distilled model from [`Photoroom/prx-512-t2i-sft`](https://huggingface.co/Photoroom/prx-512-t2i-sft) | Can handle less detailed prompts in natural language|8 steps, cfg=1.0| `mindspore.bfloat16` |
| [`Photoroom/prx-512-t2i-dc-ae`](https://huggingface.co/Photoroom/prx-512-t2i-dc-ae)| 512 | No | No | Base model pre-trained at 512 with [Deep Compression Autoencoder (DC-AE)](https://hanlab.mit.edu/projects/dc-ae)|Works best with detailed prompts in natural language|28 steps, cfg=5.0| `mindspore.bfloat16` |
| [`Photoroom/prx-512-t2i-dc-ae-sft`](https://huggingface.co/Photoroom/prx-512-t2i-dc-ae-sft)| 512 | Yes | No | Fine-tuned on the [Alchemist dataset](https://huggingface.co/datasets/yandex/alchemist) dataset with [Deep Compression Autoencoder (DC-AE)](https://hanlab.mit.edu/projects/dc-ae) | Can handle less detailed prompts in natural language|28 steps, cfg=5.0| `mindspore.bfloat16` |
| [`Photoroom/prx-512-t2i-dc-ae-sft-distilled`](https://huggingface.co/Photoroom/prx-512-t2i-dc-ae-sft-distilled)| 512 | Yes | Yes | 8-step distilled model from [`Photoroom/prx-512-t2i-dc-ae-sft-distilled`](https://huggingface.co/Photoroom/prx-512-t2i-dc-ae-sft-distilled) | Can handle less detailed prompts in natural language|8 steps, cfg=1.0| `mindspore.bfloat16` |s
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There appears to be a typo (s) at the end of this line. Additionally, the description for Photoroom/prx-512-t2i-dc-ae-sft-distilled incorrectly states that it is distilled from itself. It should likely be distilled from Photoroom/prx-512-t2i-dc-ae-sft.

Suggested change
| [`Photoroom/prx-512-t2i-dc-ae-sft-distilled`](https://huggingface.co/Photoroom/prx-512-t2i-dc-ae-sft-distilled)| 512 | Yes | Yes | 8-step distilled model from [`Photoroom/prx-512-t2i-dc-ae-sft-distilled`](https://huggingface.co/Photoroom/prx-512-t2i-dc-ae-sft-distilled) | Can handle less detailed prompts in natural language|8 steps, cfg=1.0| `mindspore.bfloat16` |s
| [`Photoroom/prx-512-t2i-dc-ae-sft-distilled`](https://huggingface.co/Photoroom/prx-512-t2i-dc-ae-sft-distilled)| 512 | Yes | Yes | 8-step distilled model from [`Photoroom/prx-512-t2i-dc-ae-sft`](https://huggingface.co/Photoroom/prx-512-t2i-dc-ae-sft) | Can handle less detailed prompts in natural language|8 steps, cfg=1.0| `mindspore.bfloat16` |

# Load pipeline - VAE and text encoder will be loaded from HuggingFace
pipe = PRXPipeline.from_pretrained("Photoroom/prx-512-t2i-sft", mindspore_dtype=ms.bfloat16)

prompt = "A front-facing portrait of a lion the golden savanna at sunset."
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The example prompt appears to be missing a preposition. It should probably be "...a lion in the golden savanna..." for better grammatical correctness.

Suggested change
prompt = "A front-facing portrait of a lion the golden savanna at sunset."
prompt = "A front-facing portrait of a lion in the golden savanna at sunset."

@Cui-yshoho Cui-yshoho added the new model add new model to mindone label Oct 25, 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