siliconflow / onediff

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

[Bug] get_weighted_text_embeddings_sdxl Error #1138

Closed todochenxi closed 1 week ago

todochenxi commented 2 weeks ago

Your current environment information

PyTorch version: 2.5.1+cu121 Is debug build: False CUDA used to build PyTorch: 12.1 ROCM used to build PyTorch: N/A

OneFlow version: path: ['/data3/anaconda3/envs/photomaker/lib/python3.10/site-packages/oneflow'], version: 0.9.1.dev20240803+cu121, git_commit: d23c061, cmake_build_type: Release, rdma: True, mlir: True, enterprise: False Nexfort version: none OneDiff version: 1.2.1.dev27+ga6eafe57 OneDiffX version: 1.2.1.dev27+ga6eafe57

OS: Ubuntu 22.04.4 LTS (x86_64) GCC version: (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0 Clang version: Could not collect CMake version: version 3.22.1 Libc version: glibc-2.35

Python version: 3.10.13 | packaged by conda-forge | (main, Dec 23 2023, 15:36:39) [GCC 12.3.0] (64-bit runtime) Python platform: Linux-6.8.0-40-generic-x86_64-with-glibc2.35 Is CUDA available: True CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090 GPU 1: NVIDIA GeForce RTX 3090

Nvidia driver version: 535.179 cuDNN version: Could not collect HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 46 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 16 On-line CPU(s) list: 0-15 Vendor ID: GenuineIntel Model name: 12th Gen Intel(R) Core(TM) i5-12600K CPU family: 6 Model: 151 Thread(s) per core: 2 Core(s) per socket: 10 Socket(s): 1 Stepping: 2 CPU max MHz: 4900.0000 CPU min MHz: 800.0000 BogoMIPS: 7372.80 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault cat_l2 cdp_l2 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 416 KiB (10 instances) L1i cache: 448 KiB (10 instances) L2 cache: 9.5 MiB (7 instances) L3 cache: 20 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0-15 Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Reg file data sampling: Mitigation; Clear Register File Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

Versions of relevant libraries: [pip3] diffusers==0.30.2 [pip3] numpy==1.26.4 [pip3] onnx==1.16.1 [pip3] onnxruntime==1.16.3 [pip3] pytorch-triton==3.1.0+cf34004b8a [pip3] torch==2.5.1+cu121 [pip3] torchaudio==2.5.1+cu121 [pip3] torchvision==0.20.1+cu121 [pip3] transformers==4.46.1 [pip3] triton==3.1.0 [pip3] triton-nightly==3.0.0.post20240716052845 [conda] numpy 1.26.4 pypi_0 pypi [conda] pytorch-triton 3.1.0+cf34004b8a pypi_0 pypi [conda] torch 2.5.1+cu121 pypi_0 pypi [conda] torchaudio 2.5.1+cu121 pypi_0 pypi [conda] torchvision 0.20.1+cu121 pypi_0 pypi [conda] triton 3.1.0 pypi_0 pypi [conda] triton-nightly 3.0.0.post20240716052845 pypi_0 pypi

🐛 Describe the bug

import argparse

import torch
from diffusers import StableDiffusionXLPipeline, StableDiffusionPipeline
from onediffx import compile_pipe, load_pipe, save_pipe

pipe = StableDiffusionPipeline.from_single_file(
    "/data3/ml/sbphotomaker/mymodels/CyberRealistic_V5_FP16.safetensors",
    torch_dtype=torch.float16,
    variant="fp16",
    use_safetensors=True,
)
pipe.to("cuda")
pipe = compile_pipe(pipe)
(
            prompt_embeds,
            negative_prompt_embeds,
            pooled_prompt_embeds,
            negative_pooled_prompt_embeds,
        ) = get_weighted_text_embeddings_sdxl(  # can be found in https://huggingface.co/spaces/ennov8ion/Animagine-XL/resolve/main/lpw_stable_diffusion_xl.py?download=true
            pipe=pipe,
            prompt="1 cat",
            neg_prompt="nsfw",
            num_images_per_prompt=1,
        )

then will be error: prompt_embeds_1 = pipe.text_encoder(token_tensor.to(device), output_hidden_states=True) File "/data3/anaconda3/envs/photomaker/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, kwargs) File "/data3/anaconda3/envs/photomaker/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1844, in _call_impl return inner() File "/data3/anaconda3/envs/photomaker/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1790, in inner result = forward_call(*args, *kwargs) File "/data3/ml/onediff/src/onediff/infer_compiler/backends/oneflow/deployable_module.py", line 38, in wrapper return func(self, args, kwargs) File "/data3/ml/onediff/src/onediff/infer_compiler/backends/oneflow/online_quantization_utils.py", line 65, in wrapper output = func(self, *args, kwargs) File "/data3/ml/onediff/src/onediff/infer_compiler/backends/oneflow/graph_management_utils.py", line 123, in wrapper ret = func(self, *args, *kwargs) File "/data3/ml/onediff/src/onediff/infer_compiler/backends/oneflow/args_tree_util.py", line 74, in wrapper else func(self, mapped_args, mapped_kwargs) File "/data3/ml/onediff/src/onediff/infer_compiler/backends/oneflow/deployable_module.py", line 144, in forward output = dpl_graph(*args, *kwargs) File "/data3/anaconda3/envs/photomaker/lib/python3.10/site-packages/oneflow/nn/graph/graph.py", line 297, in call return self.__run(args, **kwargs) File "/data3/anaconda3/envs/photomaker/lib/python3.10/site-packages/oneflow/nn/graph/graph.py", line 1862, in __run _eager_outputs = oneflow._oneflow_internal.nn.graph.RunLazyNNGraphByVM( oneflow._oneflow_internal.exception.RuntimeError: Error: Reshape infered output element count is different with input in op_name: model.text_model-reshape-0 input shape is : (1,5) , output shape is : (1,77) , output logical shape is (1,77) , and reshape shape conf is : (1,77) op_loc:

todochenxi commented 1 week ago

The reason for the error is that my code was written incorrectly. Thanks for the great work!