siliconflow / onediff

OneDiff: An out-of-the-box acceleration library for diffusion models.
https://github.com/siliconflow/onediff/wiki
Apache License 2.0
1.72k stars 107 forks source link

Add flux example #1142

Open clackhan opened 2 weeks ago

clackhan commented 2 weeks ago

Summary by CodeRabbit

coderabbitai[bot] commented 2 weeks ago

Walkthrough

The changes introduce a detailed README file for the Flux example in the OneDiff Diffusers Extensions, covering environment setup, execution instructions, performance comparisons, dynamic shape handling, and quality assurance for image generation with the NexFort backend. Additionally, a new Python script (text_to_image_flux.py) is added to facilitate image generation using command-line inputs, incorporating optimizations and a structured approach for users to specify parameters and manage the image generation process.

Changes

File Path Change Summary
onediff_diffusers_extensions/examples/flux/README.md Added comprehensive sections for environment setup, execution instructions, performance comparison, dynamic shape, and quality.
onediff_diffusers_extensions/examples/flux/text_to_image_flux.py Introduced a command-line interface for image generation using the Flux model, including argument parsing and performance optimizations.

Possibly related PRs

Suggested reviewers

🐰 In the meadow where ideas bloom,
A README now clears the room.
With commands and setups laid out,
Image generation, there’s no doubt!
Flux and NexFort, side by side,
Hop along, let creativity glide! 🌼✨


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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
πŸͺ§ Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@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 using 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. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
liho00 commented 1 week ago

from nexfort.compilers import transform 0|comfy-0 | ImportError: cannot import name 'transform' from 'nexfort.compilers' (/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/nexfort/compilers/init.cpython-310-x86_64-linux-gnu.so)

Name: nexfort Version: 0.1.dev291 Summary: Next Generation Extension for PyTorch

@strint @clackhan

liho00 commented 1 week ago

and can we have comfyui example as well?

strint commented 1 week ago

from nexfort.compilers import transform 0|comfy-0 | ImportError: cannot import name 'transform' from 'nexfort.compilers' (/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/nexfort/compilers/init.cpython-310-x86_64-linux-gnu.so)

Name: nexfort Version: 0.1.dev291 Summary: Next Generation Extension for PyTorch

@strint @clackhan

@liho00 Please update nexfort https://pypi.org/project/nexfort/#history

liho00 commented 1 week ago

from nexfort.compilers import transform 0|comfy-0 | ImportError: cannot import name 'transform' from 'nexfort.compilers' (/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/nexfort/compilers/init.cpython-310-x86_64-linux-gnu.so) Name: nexfort Version: 0.1.dev291 Summary: Next Generation Extension for PyTorch @strint @clackhan

@liho00 Please update nexfort https://pypi.org/project/nexfort/#history

@strint @clackhan got new error

Name: torch Version: 2.4.1

Name: nexfort Version: 0.1.dev293

NEXFORT_ENABLE_FP8_QUANTIZE_ATTENTION=0 python3 onediff_diffusers_extensions/examples/flux/text_to_image_flux.py     --transform     --saved-image flux_compile.png
/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/onnxscript/converter.py:820: FutureWarning: 'onnxscript.values.Op.param_schemas' is deprecated in version 0.1 and will be removed in the future. Please use '.op_signature' instead.
  param_schemas = callee.param_schemas()
/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/onnxscript/converter.py:820: FutureWarning: 'onnxscript.values.OnnxFunction.param_schemas' is deprecated in version 0.1 and will be removed in the future. Please use '.op_signature' instead.
  param_schemas = callee.param_schemas()
Loading checkpoint shards: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 2/2 [00:00<00:00, 14.00it/s]
Loading pipeline components...:  43%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                        | 3/7 [00:00<00:00, 14.61it/s]You set `add_prefix_space`. The tokenizer needs to be converted from the slow tokenizers
Loading pipeline components...: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 7/7 [00:00<00:00,  8.65it/s]
compile...
Traceback (most recent call last):
  File "/home/shadeform/onediff/onediff_diffusers_extensions/examples/flux/text_to_image_flux.py", line 231, in <module>
    main()
  File "/home/shadeform/onediff/onediff_diffusers_extensions/examples/flux/text_to_image_flux.py", line 186, in main
    flux = FluxGenerator(args.model, args.quantize, args.transform, args.speedup_t5)
  File "/home/shadeform/onediff/onediff_diffusers_extensions/examples/flux/text_to_image_flux.py", line 153, in __init__
    self.pipe.transformer = transform(self.pipe.transformer)
  File "src/nexfort/compilers/transform_model.py", line 42, in nexfort.compilers.transform_model.transform_model
  File "src/nexfort/compilers/register_diffusers.py", line 15, in init nexfort.compilers.register_diffusers
  File "src/nexfort/nn/modules.py", line 14, in init nexfort.nn.modules
  File "src/nexfort/kernels/activations.py", line 43, in init nexfort.kernels.activations
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/triton/runtime/jit.py", line 882, in jit
    return decorator(fn)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/triton/runtime/jit.py", line 871, in decorator
    return JITFunction(
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/triton/runtime/jit.py", line 704, in __init__
    self.starting_line_number = inspect.getsourcelines(fn)[1]
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/inspect.py", line 1121, in getsourcelines
    lines, lnum = findsource(object)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/inspect.py", line 940, in findsource
    file = getsourcefile(object)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/inspect.py", line 817, in getsourcefile
    filename = getfile(object)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/torch/package/package_importer.py", line 712, in _patched_getfile
    return _orig_getfile(object)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/inspect.py", line 797, in getfile
    raise TypeError('module, class, method, function, traceback, frame, or '
TypeError: module, class, method, function, traceback, frame, or code object was expected, got cython_function_or_method
clackhan commented 1 week ago

from nexfort.compilers import transform 0|comfy-0 | ImportError: cannot import name 'transform' from 'nexfort.compilers' (/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/nexfort/compilers/init.cpython-310-x86_64-linux-gnu.so) Name: nexfort Version: 0.1.dev291 Summary: Next Generation Extension for PyTorch @strint @clackhan

@liho00 Please update nexfort https://pypi.org/project/nexfort/#history

@strint @clackhan got new error

Name: torch Version: 2.4.1

Name: nexfort Version: 0.1.dev293

NEXFORT_ENABLE_FP8_QUANTIZE_ATTENTION=0 python3 onediff_diffusers_extensions/examples/flux/text_to_image_flux.py     --transform     --saved-image flux_compile.png
/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/onnxscript/converter.py:820: FutureWarning: 'onnxscript.values.Op.param_schemas' is deprecated in version 0.1 and will be removed in the future. Please use '.op_signature' instead.
  param_schemas = callee.param_schemas()
/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/onnxscript/converter.py:820: FutureWarning: 'onnxscript.values.OnnxFunction.param_schemas' is deprecated in version 0.1 and will be removed in the future. Please use '.op_signature' instead.
  param_schemas = callee.param_schemas()
Loading checkpoint shards: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 2/2 [00:00<00:00, 14.00it/s]
Loading pipeline components...:  43%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                        | 3/7 [00:00<00:00, 14.61it/s]You set `add_prefix_space`. The tokenizer needs to be converted from the slow tokenizers
Loading pipeline components...: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 7/7 [00:00<00:00,  8.65it/s]
compile...
Traceback (most recent call last):
  File "/home/shadeform/onediff/onediff_diffusers_extensions/examples/flux/text_to_image_flux.py", line 231, in <module>
    main()
  File "/home/shadeform/onediff/onediff_diffusers_extensions/examples/flux/text_to_image_flux.py", line 186, in main
    flux = FluxGenerator(args.model, args.quantize, args.transform, args.speedup_t5)
  File "/home/shadeform/onediff/onediff_diffusers_extensions/examples/flux/text_to_image_flux.py", line 153, in __init__
    self.pipe.transformer = transform(self.pipe.transformer)
  File "src/nexfort/compilers/transform_model.py", line 42, in nexfort.compilers.transform_model.transform_model
  File "src/nexfort/compilers/register_diffusers.py", line 15, in init nexfort.compilers.register_diffusers
  File "src/nexfort/nn/modules.py", line 14, in init nexfort.nn.modules
  File "src/nexfort/kernels/activations.py", line 43, in init nexfort.kernels.activations
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/triton/runtime/jit.py", line 882, in jit
    return decorator(fn)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/triton/runtime/jit.py", line 871, in decorator
    return JITFunction(
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/triton/runtime/jit.py", line 704, in __init__
    self.starting_line_number = inspect.getsourcelines(fn)[1]
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/inspect.py", line 1121, in getsourcelines
    lines, lnum = findsource(object)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/inspect.py", line 940, in findsource
    file = getsourcefile(object)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/inspect.py", line 817, in getsourcefile
    filename = getfile(object)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/torch/package/package_importer.py", line 712, in _patched_getfile
    return _orig_getfile(object)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/inspect.py", line 797, in getfile
    raise TypeError('module, class, method, function, traceback, frame, or '
TypeError: module, class, method, function, traceback, frame, or code object was expected, got cython_function_or_method

please install torch==2.4.0 and try Again

liho00 commented 1 week ago

from nexfort.compilers import transform 0|comfy-0 | ImportError: cannot import name 'transform' from 'nexfort.compilers' (/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/nexfort/compilers/init.cpython-310-x86_64-linux-gnu.so) Name: nexfort Version: 0.1.dev291 Summary: Next Generation Extension for PyTorch @strint @clackhan

@liho00 Please update nexfort https://pypi.org/project/nexfort/#history

@strint @clackhan got new error Name: torch Version: 2.4.1 Name: nexfort Version: 0.1.dev293

NEXFORT_ENABLE_FP8_QUANTIZE_ATTENTION=0 python3 onediff_diffusers_extensions/examples/flux/text_to_image_flux.py     --transform     --saved-image flux_compile.png
/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/onnxscript/converter.py:820: FutureWarning: 'onnxscript.values.Op.param_schemas' is deprecated in version 0.1 and will be removed in the future. Please use '.op_signature' instead.
  param_schemas = callee.param_schemas()
/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/onnxscript/converter.py:820: FutureWarning: 'onnxscript.values.OnnxFunction.param_schemas' is deprecated in version 0.1 and will be removed in the future. Please use '.op_signature' instead.
  param_schemas = callee.param_schemas()
Loading checkpoint shards: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 2/2 [00:00<00:00, 14.00it/s]
Loading pipeline components...:  43%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                        | 3/7 [00:00<00:00, 14.61it/s]You set `add_prefix_space`. The tokenizer needs to be converted from the slow tokenizers
Loading pipeline components...: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 7/7 [00:00<00:00,  8.65it/s]
compile...
Traceback (most recent call last):
  File "/home/shadeform/onediff/onediff_diffusers_extensions/examples/flux/text_to_image_flux.py", line 231, in <module>
    main()
  File "/home/shadeform/onediff/onediff_diffusers_extensions/examples/flux/text_to_image_flux.py", line 186, in main
    flux = FluxGenerator(args.model, args.quantize, args.transform, args.speedup_t5)
  File "/home/shadeform/onediff/onediff_diffusers_extensions/examples/flux/text_to_image_flux.py", line 153, in __init__
    self.pipe.transformer = transform(self.pipe.transformer)
  File "src/nexfort/compilers/transform_model.py", line 42, in nexfort.compilers.transform_model.transform_model
  File "src/nexfort/compilers/register_diffusers.py", line 15, in init nexfort.compilers.register_diffusers
  File "src/nexfort/nn/modules.py", line 14, in init nexfort.nn.modules
  File "src/nexfort/kernels/activations.py", line 43, in init nexfort.kernels.activations
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/triton/runtime/jit.py", line 882, in jit
    return decorator(fn)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/triton/runtime/jit.py", line 871, in decorator
    return JITFunction(
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/triton/runtime/jit.py", line 704, in __init__
    self.starting_line_number = inspect.getsourcelines(fn)[1]
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/inspect.py", line 1121, in getsourcelines
    lines, lnum = findsource(object)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/inspect.py", line 940, in findsource
    file = getsourcefile(object)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/inspect.py", line 817, in getsourcefile
    filename = getfile(object)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/site-packages/torch/package/package_importer.py", line 712, in _patched_getfile
    return _orig_getfile(object)
  File "/home/shadeform/miniconda3/envs/image/lib/python3.10/inspect.py", line 797, in getfile
    raise TypeError('module, class, method, function, traceback, frame, or '
TypeError: module, class, method, function, traceback, frame, or code object was expected, got cython_function_or_method

please install torch==2.4.0 and try Again

@strint @clackhan

Name: torch Version: 2.4.0

same issue happend tho, could you share us your environment list in correct requirements.txt?