[Diffusion] test vide coding ability#19647
Conversation
Summary of ChangesHello, 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 introduces significant optimizations and refactorings across several multimodal generation models. The core changes involve enhancing layer normalization with flexible scaling, leveraging PyTorch's compilation capabilities for critical forward passes, and implementing CUDA-optimized rotary embedding applications. These updates are designed to improve the overall performance and efficiency of the models by utilizing fused kernels and better memory management. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a series of optimizations and refactorings across various DiT models and their layers. Key changes include:
- Refactoring
layernormand model implementations to use fused kernels for operations like(residual + gate * x)followed by normalization and modulation. This improves performance and code clarity. - Adding
@torch.compileto several forward methods for just-in-time compilation, which should speed up execution. - Utilizing optimized kernels like
flashinferfor rotary position embeddings where applicable, with added checks for tensor contiguity for correctness. - Improving memory layout by explicitly making tensors contiguous after reshaping operations.
My review identifies a potential bug in zimage.py where a change in logic for adaptive layer norm scaling might have been unintentionally introduced. Other changes appear to be solid improvements.
| gate_msa = gate_msa.clone().tanh() | ||
| gate_mlp = gate_mlp.clone().tanh() | ||
| scale_msa = scale_msa.clone() | ||
| scale_mlp = scale_mlp.clone() |
There was a problem hiding this comment.
The 1.0 + operation on scale_msa and scale_mlp has been removed. The RMSNormScaleShift is initialized with scale_constant=0.0, which results in the computation norm(x) * scale. The original logic was norm(x) * (1.0 + scale). This change in logic is likely a bug, as similar refactorings in other files in this PR preserve the (1 + scale) logic. To restore the original behavior, you can add 1.0 + back to the scales.
| gate_msa = gate_msa.clone().tanh() | |
| gate_mlp = gate_mlp.clone().tanh() | |
| scale_msa = scale_msa.clone() | |
| scale_mlp = scale_mlp.clone() | |
| gate_msa = gate_msa.clone().tanh() | |
| gate_mlp = gate_mlp.clone().tanh() | |
| scale_msa = 1.0 + scale_msa.clone() | |
| scale_mlp = 1.0 + scale_mlp.clone() | |
Motivation
Created by #19540 and claude code (Thanks @Lyken17 )
run.sh
Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci