siliconflow / onediff

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

Upscaling interference #221

Closed NicholasKao1029 closed 1 year ago

NicholasKao1029 commented 1 year ago

Running upscaler for simple stable diffusion in a server that has oneflow in it causes issues

from PIL import Image
from io import BytesIO
from diffusers import StableDiffusionUpscalePipeline
import torch
import requests

def upscale_ai(img_url):
    response = requests.get(img_url)
    low_res_img = Image.open(BytesIO(response.content)).convert("RGB")

    low_res_img = low_res_img.resize((512, 768))
    prompt = "beautiful woman"
    model_id = "stabilityai/stable-diffusion-x4-upscaler"
    pipeline = StableDiffusionUpscalePipeline.from_pretrained(model_id, torch_dtype=torch.float16)
    upscaled_image = pipeline(prompt=prompt, image=low_res_img, num_inference_steps=50).images[0]
    return upscaled_image 
Cannot find the kernel matching Current OperatorConf.  The Info of OperatorConf are
 op_name: rsqrt30
 op_type_name: rsqrt
 DeviceType_Name: kCPU
 DataType_Name of x_0: kFloat16
 DataType_Name of y_0: kFloat16
  File "oneflow/core/framework/op_interpreter/op_interpreter_util.cpp", line 144, in Dispatch<oneflow::one::Tensor>
    Dispatch<TensorTuple>(op_expr, inputs, ctx)
  File "oneflow/core/framework/op_interpreter/op_interpreter_util.cpp", line 135, in Dispatch<oneflow::one::TensorTuple>
    Dispatch(op_expr, inputs, outputs.get(), ctx)
  File "oneflow/core/framework/op_interpreter/op_interpreter.cpp", line 103, in Apply
    internal_->Apply(op_expr, inputs, outputs, ctx)
  File "oneflow/core/framework/op_interpreter/eager_local_op_interpreter.cpp", line 155, in NaiveInterpret
    PhysicalRun([&](InstructionsBuilder* builder) -> Maybe ... output_eager_blob_objects), ctx, result->stream()); })
  File "oneflow/core/framework/instructions_builder.h", line 166, in PhysicalRun
    Build(&instructions_builder)
  File "oneflow/core/framework/instructions_builder.cpp", line 400, in Call
    vm::OpCallInstructionPolicy::New( vm_stream, opkernel ... global_tensor_infer_result, ctx, *one::CurrentDevVmDepObjectConsumeMode())
  File "oneflow/core/vm/op_call_instruction_policy.h", line 50, in New
    ptr->Init()
  File "oneflow/user/kernels/stateful_opkernel.cpp", line 920, in ChooseOpKernel
    user_op::UserOpRegistryMgr::Get().GetOpKernelRegistryResult(op_type_name, reg_ctx)
Error Type: oneflow.ErrorProto.op_kernel_not_found_error
NicholasKao1029 commented 1 year ago

Changed to

from PIL import Image
from io import BytesIO
from diffusers import StableDiffusionUpscalePipeline
import torch
import requests
import oneflow as flow

def url_to_image(url):
    # Send a HTTP request to the URL of the image
    response = requests.get(url)

    # Raise an exception if the GET request was unsuccessful
    response.raise_for_status()

    # Get the content of the response and turn it into a PIL image
    img = Image.open(BytesIO(response.content))
    return img

def upscale_ai(img_url, scale):
    low_res_img = url_to_image(img_url)
    print('low res image got')
    prompt = "beautiful woman"
    model_id = "stabilityai/stable-diffusion-x4-upscaler"
    flow.mock_torch.disable()
    pipeline = StableDiffusionUpscalePipeline.from_pretrained(model_id)
    print('pipe')
    upscaled_image = pipeline(prompt=prompt, image=low_res_img, num_inference_steps=50).images[0]
    flow.mock_torch.enable()
    return upscaled_image 

and now getting

pipe
to() received an invalid combination of arguments - got (oneflow._oneflow_internal.device), but expected one of:
 * (torch.device device, torch.dtype dtype, bool non_blocking, bool copy, *, torch.memory_format memory_format)
 * (torch.dtype dtype, bool non_blocking, bool copy, *, torch.memory_format memory_format)
 * (Tensor tensor, bool non_blocking, bool copy, *, torch.memory_format memory_format)

^CStack trace (most recent call last):
[2023-06-01 01:54:37 +0000] [6585] [INFO] Handling signal: int
Stack trace (most recent call last) in thread 6651:
   Object "/opt/conda/lib/python3.8/site-packages/oneflow/../oneflow.libs/liboneflow-f60617dd.so", at 0x7f07310e3f15, in AbortSignalHandler(int)

Aborted (Signal sent by tkill() 6587 0)