Skip to content
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

Add sdxl lightning quant use #992

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Conversation

lixiang007666
Copy link
Contributor

@lixiang007666 lixiang007666 commented Jun 30, 2024

This PR is done:

  • Add sdxl lightning int8.

Summary by CodeRabbit

  • New Features

    • Introduced a comprehensive README file for SDXL-Lightning, detailing environment setup and model execution.
    • Added a command-line interface for generating images with the Stable Diffusion XL model, allowing parameter customization.
    • Enhanced quantization options in the quantization script, permitting the use of the SDXL Lightning model.
  • Bug Fixes

    • Updated file paths in the Bash script to ensure correct execution of the image generation script.
  • Documentation

    • Expanded documentation to cover new features and usage instructions for the SDXL-Lightning model and related tools.
  • Chores

    • Implemented a performance monitoring tool for measuring inference time efficiently.

Copy link
Contributor

coderabbitai bot commented Aug 9, 2024

Warning

Rate limit exceeded

@lixiang007666 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 23 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 8d0f589 and 42c4300.

Walkthrough

The recent changes introduce comprehensive documentation and new functionalities for using SDXL-Lightning with OneDiff. Key enhancements include a structured README for setup and execution, a command-line interface for image generation, performance monitoring tools, and updates to quantization scripts. These improvements aim to optimize model performance, facilitate user experience, and support advanced configurations, ultimately enhancing the utility of the Stable Diffusion XL model.

Changes

Files Change Summary
.../lightning/README.md Introduces documentation for SDXL-Lightning setup, including environment configuration, model execution, quantization, performance comparisons, and quality assurance resources.
.../lightning/text_to_image_sdxl_light.py Adds a command-line script for image generation, allowing parameter customization, model loading with LoRA weights, and supporting quantization.
.../save_and_load_pipeline.sh Updates file paths for text_to_image_sdxl_light.py, reflecting its new location in the directory structure, while maintaining core functionality.
.../utils/performance_monitor.py Implements a context manager for measuring inference time, supporting warmup and normal runs with precision timing via CUDA when available.
.../quantization/quantize-sd-fast.py Adds new command-line options for utilizing the SDXL Lightning model, enhancing flexibility in model selection and loading.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Model
    participant Quantizer

    User->>CLI: Run image generation command
    CLI->>Model: Load specified model
    Model-->>CLI: Return model instance
    CLI->>Quantizer: Optional quantization
    Quantizer-->>CLI: Return quantized model
    CLI->>User: Save generated image
Loading

🐇 In a world where models shine bright,
A rabbit hops with delight,
New paths to explore, with features galore,
Image magic, oh what a sight!
With quantization and speed,
We flourish, we succeed! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range, codebase verification and nitpick comments (4)
onediff_diffusers_extensions/examples/lightning/README.md (4)

20-23: Use markdown links instead of bare URLs.

The setup instructions contain bare URLs. Consider using markdown links for better readability and consistency with markdown standards.

- Follow the instructions to set up OneDiff from the https://github.com/siliconflow/onediff?tab=readme-ov-file#installation.
+ Follow the instructions to set up OneDiff from the [OneDiff Installation Guide](https://github.com/siliconflow/onediff?tab=readme-ov-file#installation).
- Follow the setup instructions for these backends from the https://github.com/siliconflow/onediff?tab=readme-ov-file#install-a-compiler-backend.
+ Follow the setup instructions for these backends from the [Compiler Backend Setup Guide](https://github.com/siliconflow/onediff?tab=readme-ov-file#install-a-compiler-backend).
Tools
Markdownlint

20-20: null
Bare URL used

(MD034, no-bare-urls)


23-23: null
Bare URL used

(MD034, no-bare-urls)


32-33: Correct grammatical number in the note.

The phrase "an 8 steps distillation model" should be corrected for grammatical consistency.

- Current test is based on an 8 steps distillation model.
+ Current test is based on an 8-step distillation model.
Tools
LanguageTool

[uncategorized] ~33-~33: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...> [!NOTE] Current test is based on an 8 steps distillation model. ### Run 1024x1024 ...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)


68-68: Use markdown links instead of bare URLs.

The quantization instructions contain a bare URL. Consider using markdown links for better readability and consistency with markdown standards.

- For an introduction to the quantization parameters, refer to: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md#diffusers-with-onediff-enterprise
+ For an introduction to the quantization parameters, refer to: [Quantization Parameters Guide](https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md#diffusers-with-onediff-enterprise)
Tools
Markdownlint

68-68: null
Bare URL used

(MD034, no-bare-urls)


122-122: Use markdown links instead of bare URLs.

The quality section contains a bare URL. Consider using markdown links for better readability and consistency with markdown standards.

- https://github.com/siliconflow/odeval/tree/main/models/lightning
+ [Quality Evaluation Guide](https://github.com/siliconflow/odeval/tree/main/models/lightning)
Tools
Markdownlint

122-122: null
Bare URL used

(MD034, no-bare-urls)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d0f1f09 and 8d0f589.

Files selected for processing (5)
  • onediff_diffusers_extensions/examples/lightning/README.md (1 hunks)
  • onediff_diffusers_extensions/examples/lightning/text_to_image_sdxl_light.py (1 hunks)
  • onediff_diffusers_extensions/examples/save_and_load_pipeline.sh (1 hunks)
  • onediff_diffusers_extensions/onediffx/utils/performance_monitor.py (1 hunks)
  • onediff_diffusers_extensions/tools/quantization/quantize-sd-fast.py (3 hunks)
Files skipped from review due to trivial changes (1)
  • onediff_diffusers_extensions/examples/save_and_load_pipeline.sh
Additional context used
LanguageTool
onediff_diffusers_extensions/examples/lightning/README.md

[uncategorized] ~33-~33: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...> [!NOTE] Current test is based on an 8 steps distillation model. ### Run 1024x1024 ...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)

Markdownlint
onediff_diffusers_extensions/examples/lightning/README.md

20-20: null
Bare URL used

(MD034, no-bare-urls)


23-23: null
Bare URL used

(MD034, no-bare-urls)


68-68: null
Bare URL used

(MD034, no-bare-urls)


122-122: null
Bare URL used

(MD034, no-bare-urls)


8-8: null
Link fragments should be valid

(MD051, link-fragments)


9-9: null
Link fragments should be valid

(MD051, link-fragments)


10-10: null
Link fragments should be valid

(MD051, link-fragments)


11-11: null
Link fragments should be valid

(MD051, link-fragments)


12-12: null
Link fragments should be valid

(MD051, link-fragments)


13-13: null
Link fragments should be valid

(MD051, link-fragments)

Ruff
onediff_diffusers_extensions/examples/lightning/text_to_image_sdxl_light.py

4-4: time imported but unused

Remove unused import: time

(F401)


14-14: Undefined name diffusers

(F821)


15-15: Local variable e is assigned to but never used

Remove assignment to unused variable e

(F841)

Additional comments not posted (10)
onediff_diffusers_extensions/onediffx/utils/performance_monitor.py (1)

5-33: LGTM: Well-structured context manager for inference timing.

The context manager track_inference_time is correctly implemented to handle both CUDA and non-CUDA scenarios. The use of torch.cuda.Event for timing when CUDA is available is appropriate. The documentation is clear and concise.

onediff_diffusers_extensions/tools/quantization/quantize-sd-fast.py (2)

69-80: LGTM: New command-line arguments for SDXL Lightning are well-integrated.

The new arguments --use_lightning and --lightning_ckpt are correctly added with appropriate types and default values. The lambda function for boolean parsing is used effectively, and the documentation is clear.


120-134: LGTM: Conditional logic for SDXL Lightning model loading is correctly implemented.

The conditional block properly checks the args.use_lightning flag and loads the model using the specified checkpoint. The pipeline setup is consistent with the existing logic.

onediff_diffusers_extensions/examples/lightning/README.md (1)

106-119: LGTM: Performance comparison section is well-structured.

The performance comparison provides clear and useful metrics, enhancing the documentation's value.

onediff_diffusers_extensions/examples/lightning/text_to_image_sdxl_light.py (6)

18-57: Argument parsing is well-structured.

The argument parser is comprehensive and covers various configuration options for the model.


170-194: Verify output image path.

Ensure that the path for saving the output image is valid and accessible.

Verification successful

Output image path is valid and writable.

The directory for saving the output image is confirmed to be writable, ensuring that the image can be saved without any issues. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the output image path.

# Test: Check if the directory for saving the output image is writable.
test -w "$(dirname 'sdxl-light-out.png')" && echo "Directory is writable."

Length of output: 96


83-116: Verify calibration info file.

Ensure that the calibrate_info.txt file exists and contains the correct format and data for quantization.


143-168: Verify backend configurations.

Ensure that the backend configurations for oneflow and nexfort are correctly handled and that the necessary options are provided.

Verification successful

Backend configurations are correctly handled.

The --compiler-config and --quantize-config arguments are present in the script, ensuring that the necessary configurations for the nexfort backend are properly managed through command-line arguments. No issues found regarding the backend configurations.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify backend configurations for compilation.

# Test: Check for the presence of necessary configurations in the argument parsing section.
rg --type python 'compiler-config|quantize-config'

Length of output: 83


Script:

#!/bin/bash
# Description: Verify backend configurations for compilation.

# Test: Check for the presence of necessary configurations in the argument parsing section.
rg --type py 'compiler-config|quantize-config'

Length of output: 1220


65-80: Verify file path handling and device allocation.

Ensure that the file paths for model loading are correct and that the device allocation (to("cuda")) is appropriate for the environment.


196-198: Verify graph saving directory.

Ensure that the directory specified for saving graphs is valid and accessible.

import argparse
import json
import os
import time
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unused import: time.

The time module is imported but not used in the code.

-import time
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import time
Tools
Ruff

4-4: time imported but unused

Remove unused import: time

(F401)


try:
USE_PEFT_BACKEND = diffusers.utils.USE_PEFT_BACKEND
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unused variable e.

The exception variable e is assigned but never used. Consider removing it.

-except Exception as e:
+except Exception:
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
except Exception as e:
except Exception:
Tools
Ruff

15-15: Local variable e is assigned to but never used

Remove assignment to unused variable e

(F841)

from safetensors.torch import load_file

try:
USE_PEFT_BACKEND = diffusers.utils.USE_PEFT_BACKEND
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix undefined name: diffusers.

The variable diffusers is used without being defined or imported, causing a potential error.

-    USE_PEFT_BACKEND = diffusers.utils.USE_PEFT_BACKEND
+    from diffusers import utils
+    USE_PEFT_BACKEND = utils.USE_PEFT_BACKEND
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
USE_PEFT_BACKEND = diffusers.utils.USE_PEFT_BACKEND
from diffusers import utils
USE_PEFT_BACKEND = utils.USE_PEFT_BACKEND
Tools
Ruff

14-14: Undefined name diffusers

(F821)

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.

2 participants