Skip to content

Conversation

@tenderness-git
Copy link
Member

No description provided.

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.

Summary of Changes

Hello @tenderness-git, 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 a robust system for predicting GPU memory usage of deep learning models, particularly VRAM. It provides the necessary infrastructure to profile a model's memory footprint under varying input conditions, train a linear regression model on this collected data, and then leverage the trained model to accurately estimate memory requirements for new, unseen inputs. This capability is crucial for optimizing resource management and preventing out-of-memory errors in large-scale deep learning deployments.

Highlights

  • New Memory Prediction Module: Introduced a new memory utility package under diffsynth_engine/utils to provide tools for GPU memory profiling and prediction for deep learning models.
  • Custom Linear Regression Implementation: Added a LinearRegression class in linear_regression.py that leverages PyTorch's torch.linalg.lstsq for ordinary least squares fitting. This class includes methods for prediction, as well as serialization and deserialization for model persistence.
  • GPU Memory Profiling Utilities: Implemented functions in memory_predcit_model.py to accurately profile both activation memory (memory used during forward pass) and weight memory (memory consumed by model parameters) on CUDA devices.
  • Predictive Model for Memory Usage: Developed a MemoryPredictModel class that utilizes the custom LinearRegression model. This class can be trained on collected memory profiling data and then used to predict the total GPU memory consumption for a given model based on its input parameters.
  • Example Usage Scripts: Provided example scripts (profile_model.py and train_model.py) demonstrating the end-to-end workflow: profiling a model (e.g., FluxDiT) to gather memory data, training the MemoryPredictModel with this data, and subsequently using the trained model for memory prediction.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 or fill out our survey to provide feedback.

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

The code changes introduce a new module for predicting GPU memory usage based on a linear regression model.

@tenderness-git tenderness-git changed the title 添加显存预测模块(based on lr) add Aug 7, 2025
@tenderness-git tenderness-git changed the title add add offload to disk Aug 7, 2025
Copy link
Contributor

@weiyilwy weiyilwy left a comment

Choose a reason for hiding this comment

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

lgtm

@tenderness-git tenderness-git merged commit a460711 into main Aug 7, 2025
@tenderness-git tenderness-git deleted the wangguan branch August 7, 2025 11:31
vae_tile_stride: int | Tuple[int, int] = 256
device: str = "cuda"
offload_mode: Optional[str] = None
offload_to_disk: bool = False
Copy link
Contributor

Choose a reason for hiding this comment

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

感觉应该换个名字,看了一下实现我觉得跟offload是两个正交的能力,这个名字太困惑了。一般理解上的offload_to_disk是真的在磁盘上存点数据,然后通过一个方法能还原回来,但是现在实现上没有这么一个方法;而且我们的目的是节省一次性运行过程中的内存占用,应该也不需要这样的能力,结合model lifecycle换给名字会更好理解一些

logger.warning("must set an non cpu device for pipeline before calling enable_cpu_offload")
return
if offload_mode == "cpu_offload":
if offload_mode is None or offload_mode == "disable":
Copy link
Contributor

Choose a reason for hiding this comment

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

都是在初始化的时候设置的,感觉disable这个选项没啥用呀


def enable_cpu_offload(self, offload_mode: str):
valid_offload_mode = ("cpu_offload", "sequential_cpu_offload")
def enable_cpu_offload(self, offload_mode: str | None, offload_to_disk:bool = False):
Copy link
Contributor

Choose a reason for hiding this comment

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

另外是正交方法的话应该拆成另外一个函数,而不是作为这个函数的参数会更好一些

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.

4 participants