Skip to content

Commit

Permalink
[Fix] black images issues with diffusers SD2.1 (#725)
Browse files Browse the repository at this point in the history
This PR is done:

- [x] Related issue:
#722 (comment)
  • Loading branch information
lixiang007666 authored Mar 14, 2024
1 parent 5cadf1e commit cf16776
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions onediff_diffusers_extensions/examples/image_to_image.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import argparse
from PIL import Image

import oneflow as flow
import torch

import argparse
from onediff.infer_compiler import oneflow_compile
from diffusers import StableDiffusionImg2ImgPipeline
import oneflow as flow
import torch


prompt = "sea,beach,the waves crashed on the sand,blue sky whit white cloud"

Expand All @@ -28,6 +29,7 @@ def parse_args():

pipe = pipe.to("cuda")
pipe.unet = oneflow_compile(pipe.unet)
pipe.vae.decoder = oneflow_compile(pipe.vae.decoder)


img = Image.new("RGB", (512, 512), "#1f80f0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ def head_to_batch_dim(self, tensor, out_dim=3):

def get_attention_scores(self, query, key, attention_mask=None):
if self.upcast_attention and parse_boolean_from_env(
"ONEFLOW_KERENL_FMHA_ENABLE_TRT_FLASH_ATTN_IMPL", True
"ONEFLOW_ATTENTION_ALLOW_HALF_PRECISION_ACCUMULATION", True
):
set_boolean_env_var("ONEFLOW_KERENL_FMHA_ENABLE_TRT_FLASH_ATTN_IMPL", False)
set_boolean_env_var("ONEFLOW_ATTENTION_ALLOW_HALF_PRECISION_ACCUMULATION", False)
dtype = query.dtype
# if self.upcast_attention:
# query = query.float()
Expand Down
4 changes: 2 additions & 2 deletions src/onediff/optimization/attention_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def __call__(
)

if attn.upcast_attention and parse_boolean_from_env(
"ONEFLOW_KERENL_FMHA_ENABLE_TRT_FLASH_ATTN_IMPL", True
"ONEFLOW_ATTENTION_ALLOW_HALF_PRECISION_ACCUMULATION", True
):
set_boolean_env_var(
"ONEFLOW_KERENL_FMHA_ENABLE_TRT_FLASH_ATTN_IMPL", False
"ONEFLOW_ATTENTION_ALLOW_HALF_PRECISION_ACCUMULATION", False
)
hidden_states = flow._C.fused_multi_head_attention_inference_v2(
query=qkv,
Expand Down

0 comments on commit cf16776

Please sign in to comment.