StableCascadeCombinedPipeLine accepts an images argument that can be a PIL image, a torch tensor, or a list of either. Unfortunately, I can't get it to accept a bfloat16 type for the image. It raises a runtime error in CLIP. I tried float32, but HF's A10G Large runs out of memory.
Here's the error I'm seeing when I try to pass an image encoded as torch.bfloat16
File"/home/user/app/app.py", line50, ingenerate_imageresults=pipe(
File"/home/user/.pyenv/versions/3.10.14/lib/python3.10/site-packages/torch/utils/_contextlib.py", line115, indecorate_contextreturnfunc(*args, **kwargs)
File"/home/user/.pyenv/versions/3.10.14/lib/python3.10/site-packages/diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py", line268, in__call__prior_outputs=self.prior_pipe(
File"/home/user/.pyenv/versions/3.10.14/lib/python3.10/site-packages/torch/utils/_contextlib.py", line115, indecorate_contextreturnfunc(*args, **kwargs)
File"/home/user/.pyenv/versions/3.10.14/lib/python3.10/site-packages/diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py", line504, in__call__image_embeds_pooled, uncond_image_embeds_pooled=self.encode_image(
File"/home/user/.pyenv/versions/3.10.14/lib/python3.10/site-packages/diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py", line254, inencode_imageimage=self.feature_extractor(image, return_tensors="pt").pixel_valuesFile"/home/user/.pyenv/versions/3.10.14/lib/python3.10/site-packages/transformers/image_processing_utils.py", line551, in__call__returnself.preprocess(images, **kwargs)
File"/home/user/.pyenv/versions/3.10.14/lib/python3.10/site-packages/transformers/models/clip/image_processing_clip.py", line306, inpreprocessimages= [to_numpy_array(image) forimageinimages]
File"/home/user/.pyenv/versions/3.10.14/lib/python3.10/site-packages/transformers/models/clip/image_processing_clip.py", line306, in<listcomp>images= [to_numpy_array(image) forimageinimages]
File"/home/user/.pyenv/versions/3.10.14/lib/python3.10/site-packages/transformers/image_utils.py", line174, into_numpy_arrayreturnto_numpy(img)
File"/home/user/.pyenv/versions/3.10.14/lib/python3.10/site-packages/transformers/utils/generic.py", line308, into_numpyreturnframework_to_numpy[framework](obj)
File"/home/user/.pyenv/versions/3.10.14/lib/python3.10/site-packages/transformers/utils/generic.py", line293, in<lambda>"pt": lambdaobj: obj.detach().cpu().numpy(),
TypeError: GotunsupportedScalarTypeBFloat16
FWIW, here are relevant snippets from the code that produced the above error:
# Define a transform to convert a PIL (method given by Claude 3 Sonnet)deftransform(image):
# Convert the image to a PyTorch tensorinput_tensor=torch.from_numpy(np.array(image)).permute(2, 0, 1).unsqueeze(0)
# Convert the tensor to 'bfloat16' dtypeinput_tensor=input_tensor.to(torch.bfloat16)
returninput_tensor# Ensure model and scheduler are initialized in GPU-enabled functioniftorch.cuda.is_available():
pipe=StableCascadeCombinedPipeline.from_pretrained(repo, torch_dtype=torch.bfloat16)
pipe.to("cuda")
# The generate function@spaces.GPU(enable_queue=True)defgenerate_image(prompt, image): ifimageisnotNone:
# Convert the PIL image to Torch tensor# and move it to GPUimg_tensor=transform(image)
img_tensor= [img_tensor.to("cuda")]
else:
img_tensor=Noneseed=random.randint(-100000,100000)
results=pipe(
prompt=prompt,
images=img_tensor,
height=1024,
width=1024,
num_inference_steps=20, generator=torch.Generator(device="cuda").manual_seed(seed)
)
returnresults.images[0]Originally posted by @Michael-F-Ellis in #7571 (comment)
StableCascadeCombinedPipeLineaccepts animagesargument that can be a PIL image, a torch tensor, or a list of either. Unfortunately, I can't get it to accept a bfloat16 type for the image. It raises a runtime error in CLIP. I tried float32, but HF's A10G Large runs out of memory.Here's the error I'm seeing when I try to pass an image encoded as
torch.bfloat16FWIW, here are relevant snippets from the code that produced the above error:
Originally posted by @Michael-F-Ellis in #7571 (comment)