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

support flux example #1073

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

support flux example #1073

wants to merge 4 commits into from

Conversation

marigoold
Copy link
Contributor

@marigoold marigoold commented Aug 8, 2024

Summary by CodeRabbit

  • New Features

    • Command-line enhancements for image generation, including options to specify data type, model revision, and local file restrictions.
    • Introduction of a comprehensive README for running the FLUX model, detailing setup, execution, and performance comparisons.
    • New script for generating images with the Flux model, allowing user-defined parameters for better usability.
  • Bug Fixes

    • Improved handling of module availability checks, enhancing efficiency.
  • Documentation

    • Added detailed instructions for the FLUX model's setup and execution to assist users.

Copy link
Contributor

coderabbitai bot commented Aug 8, 2024

Walkthrough

The recent updates enhance flexibility and usability across several scripts. Key improvements include new command-line arguments in the image generation script, the introduction of a README for the FLUX model, and optimizations in module availability checks. These changes streamline user interactions with the scripts, allowing for better control over model parameters and environment setup, ultimately leading to improved performance and ease of use.

Changes

Files Change Summary
benchmarks/text_to_image.py Added command-line arguments for --dtype, --revision, and --local-files-only; modified load_pipe and main functions accordingly.
onediff_diffusers_extensions/examples/flux/README.md Introduced a comprehensive README for running the FLUX model, detailing setup, execution methods, performance comparisons, and dynamic shape support.
onediff_diffusers_extensions/examples/text_to_image_flux.py Implemented a command-line interface for image generation with options for model and image parameters; supports multiple resolutions.
src/onediff/utils/import_utils.py Changed _oneflow_available to a lazy evaluation model, improving efficiency of module availability checks.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant LoadPipe
    participant Model

    User->>CLI: Execute command with parameters
    CLI->>LoadPipe: Pass parameters (dtype, revision, local_files_only)
    LoadPipe->>Model: Load model with given parameters
    Model-->>LoadPipe: Model ready
    LoadPipe-->>CLI: Pipeline loaded
    CLI-->>User: Execution complete
Loading

🐰 In the meadow, changes bloom bright,
New arguments added, oh what a sight!
With headers and flags, the scripts now sing,
A dance of code, like spring's joyful fling.
So hop along, dear friends, let's cheer,
For enhancements that bring us all near! 🌼✨


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 (5)
onediff_diffusers_extensions/examples/text_to_image_flux.py (1)

56-56: Avoid unused loop variable i.

The loop variable i is not used within the loop body. Consider using _ to indicate that it is intentionally unused.

-for i in range(args.warmup):
+for _ in range(args.warmup):
Tools
Ruff

56-56: Loop control variable i not used within loop body

(B007)

onediff_diffusers_extensions/examples/flux/README.md (3)

16-16: Use proper markdown for URLs.

Replace bare URLs with markdown links for better readability and adherence to markdown best practices.

[Set up onediff](https://github.com/siliconflow/onediff?tab=readme-ov-file#installation)

[Set up nexfort backend](https://github.com/siliconflow/onediff/tree/main/src/onediff/infer_compiler/backends/nexfort)

[Model version for diffusers](https://huggingface.co/black-forest-labs/FLUX.1-schnell)

[HF pipeline](https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/pipelines/flux.md)

Also applies to: 19-19, 27-27, 29-29

Tools
Markdownlint

16-16: null
Bare URL used

(MD034, no-bare-urls)


23-23: Specify language for fenced code block.

Specify the language for the fenced code block to improve syntax highlighting and readability.

```bash
pip3 install --upgrade diffusers[torch]

<details>
<summary>Tools</summary>

<details>
<summary>Markdownlint</summary><blockquote>

23-23: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</blockquote></details>

</details>

---

`81-81`: **Correct grammatical number.**

The phrase "on different CPU" should be corrected to "on different CPUs" for grammatical accuracy.

```diff
- and it varies a lot on different CPU.
+ and it varies a lot on different CPUs.
Tools
LanguageTool

[uncategorized] ~81-~81: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...rence, and it varies a lot on different CPU. ## Dynamic shape for FLUX Run: ```...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)

benchmarks/text_to_image.py (1)

Line range hint 49-97:
Validate the --dtype argument.

Consider adding validation for the --dtype argument to ensure it corresponds to a valid PyTorch data type. This can prevent runtime errors due to invalid input.

parser.add_argument("--dtype", type=str, default="half", choices=["float16", "float32", "float64", "half"])
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d0f1f09 and 3091b5d.

Files selected for processing (4)
  • benchmarks/text_to_image.py (8 hunks)
  • onediff_diffusers_extensions/examples/flux/README.md (1 hunks)
  • onediff_diffusers_extensions/examples/text_to_image_flux.py (1 hunks)
  • src/onediff/utils/import_utils.py (2 hunks)
Additional context used
Ruff
onediff_diffusers_extensions/examples/text_to_image_flux.py

4-4: cv2 imported but unused

Remove unused import: cv2

(F401)


5-5: numpy imported but unused

Remove unused import: numpy

(F401)


9-9: PIL.Image imported but unused

Remove unused import: PIL.Image

(F401)


56-56: Loop control variable i not used within loop body

(B007)

LanguageTool
onediff_diffusers_extensions/examples/flux/README.md

[uncategorized] ~81-~81: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...rence, and it varies a lot on different CPU. ## Dynamic shape for FLUX Run: ```...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)

Markdownlint
onediff_diffusers_extensions/examples/flux/README.md

16-16: null
Bare URL used

(MD034, no-bare-urls)


19-19: null
Bare URL used

(MD034, no-bare-urls)


27-27: null
Bare URL used

(MD034, no-bare-urls)


29-29: null
Bare URL used

(MD034, no-bare-urls)


23-23: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

Additional comments not posted (4)
src/onediff/utils/import_utils.py (2)

26-26: Use lazy initialization for _oneflow_available.

The change to initialize _oneflow_available as None and perform the check when needed is a good optimization for lazy evaluation. This avoids unnecessary module checks.


36-38: Ensure thread safety when using global variables.

The use of a global variable _oneflow_available can lead to race conditions in a multithreaded environment. Consider using a lock to ensure thread safety if this function is accessed concurrently.

Verification successful

Global variable _oneflow_available is not accessed in multithreading/multiprocessing contexts.

The global variable _oneflow_available does not appear to be accessed in parts of the codebase that utilize threading or multiprocessing. This suggests that the risk of race conditions affecting this variable is minimal. No further action is needed regarding thread safety for _oneflow_available.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for multithreading usage that might affect `_oneflow_available`.

# Test: Search for threading or multiprocessing usage in the codebase.
rg --type python 'threading|multiprocessing'

Length of output: 77


Script:

#!/bin/bash
# Description: Check for multithreading usage that might affect `_oneflow_available`.

# Test: Search for threading or multiprocessing usage in the codebase.
rg 'threading|multiprocessing'

Length of output: 310


Script:

#!/bin/bash
# Description: Check if `_oneflow_available` or related functions are accessed in multithreading/multiprocessing contexts.

# Test: Search for `_oneflow_available` references in files using threading or multiprocessing.
rg '_oneflow_available' onediff_comfy_nodes/benchmarks/src/core/service_client.py onediff_diffusers_extensions/examples/text_to_image_sdxl_mp_load.py

# Test: Search for function calls from `import_utils.py` in files using threading or multiprocessing.
rg 'import_utils' onediff_comfy_nodes/benchmarks/src/core/service_client.py onediff_diffusers_extensions/examples/text_to_image_sdxl_mp_load.py

Length of output: 293

benchmarks/text_to_image.py (2)

Line range hint 114-137:
LGTM! Verify usage of new parameters.

The changes to include revision and local_files_only are well-integrated. The assertion for dtype is a good practice.

Ensure that the usage of these new parameters is consistent throughout the codebase.

Verification successful

Consistent Usage of revision and local_files_only Parameters

The parameters revision and local_files_only are consistently used throughout the codebase, as evidenced by their presence in function calls and argument parsing. This aligns with the changes made in the load_pipe function.

  • Instances of revision and local_files_only were found in argument parsing and function calls, indicating consistent usage.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `revision` and `local_files_only` parameters in the codebase.

# Test: Search for the usage of these parameters in function calls. Expect: Consistent usage.
rg --type python -A 5 $'revision|local_files_only'

Length of output: 82


Script:

#!/bin/bash
# Description: Verify the usage of `revision` and `local_files_only` parameters in the codebase.

# Find all Python files and search for the usage of `revision` and `local_files_only` parameters.
fd --extension py --exec rg 'revision|local_files_only' {}

Length of output: 1197


246-253: Ensure proper integration of new arguments.

The changes to pass dtype, revision, and local_files_only to load_pipe are well-implemented.

Verify that these arguments are correctly integrated and utilized in the pipeline setup.

Verification successful

Integration of dtype, revision, and local_files_only is correct.

The dtype, revision, and local_files_only arguments are properly integrated into the pipeline setup in benchmarks/text_to_image.py. These arguments are correctly passed to the load_pipe function and utilized in the pipeline configuration.

  • dtype is used to set the torch_dtype.
  • revision is added to extra_kwargs.
  • local_files_only is handled as a boolean flag.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `dtype`, `revision`, and `local_files_only` in the pipeline setup.

# Test: Search for the integration points in the pipeline setup. Expect: Correct usage and handling.
rg --type python -A 5 $'dtype|revision|local_files_only'

Length of output: 88


Script:

#!/bin/bash
# Description: Verify the integration of `dtype`, `revision`, and `local_files_only` in the pipeline setup.

# Test: Search for the integration points in the pipeline setup. Expect: Correct usage and handling.
rg --glob '*.py' -A 5 'dtype|revision|local_files_only'

Length of output: 214146

import argparse
import time

import cv2
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 imports.

The imports cv2, numpy, and PIL.Image are not used in the script and should be removed to clean up the code.

-import cv2
-import numpy as np
-import PIL.Image

Also applies to: 5-5, 9-9

Tools
Ruff

4-4: cv2 imported but unused

Remove unused import: cv2

(F401)

end = time.time()
print(f"Inference time: {end - begin:.3f}s")

image.save(f"{i=}th_{args.saved_image}.png")
Copy link
Contributor

@coderabbitai coderabbitai bot Aug 8, 2024

Choose a reason for hiding this comment

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

Fix incorrect string interpolation in image.save.

The use of f"{i=}th_{args.saved_image}.png" is incorrect for filename generation. Correct the string formatting to avoid syntax errors.

-    image.save(f"{i=}th_{args.saved_image}.png")
+    image.save(f"{i}th_{args.saved_image}.png")
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
image.save(f"{i=}th_{args.saved_image}.png")
image.save(f"{i}th_{args.saved_image}.png")

Copy link
Collaborator

@jackalcooper jackalcooper Aug 9, 2024

Choose a reason for hiding this comment

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

这个等号去掉吧,在文件名里面比较麻烦

Copy link
Contributor

Choose a reason for hiding this comment

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

@jackalcooper,好的,去掉等号是正确的选择。这样文件名会更简洁。感谢您的确认!

).images[0]
end_time = time.time()
print(f"Inference time: {end_time - start_time:.2f} seconds")
image.save(f"{i=}th_{args.saved_image}_{h}x{w}.png")
Copy link
Contributor

@coderabbitai coderabbitai bot Aug 8, 2024

Choose a reason for hiding this comment

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

Fix incorrect string interpolation in image.save.

The use of f"{i=}th_{args.saved_image}_{h}x{w}.png" is incorrect for filename generation. Correct the string formatting to avoid syntax errors.

-    image.save(f"{i=}th_{args.saved_image}_{h}x{w}.png")
+    image.save(f"{i}th_{args.saved_image}_{h}x{w}.png")
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
image.save(f"{i=}th_{args.saved_image}_{h}x{w}.png")
image.save(f"{i}th_{args.saved_image}_{h}x{w}.png")

Copy link
Collaborator

Choose a reason for hiding this comment

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

这个等号去掉吧,在文件名里面比较麻烦

Copy link
Contributor

Choose a reason for hiding this comment

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

@jackalcooper, 正如建议中所示,我已经去掉了文件名中的等号。请查看是否符合您的要求!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

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