Skip to content

keep text encoders in fp32 in flux #9677

@saeedkhanehgir

Description

@saeedkhanehgir

Hi,
I want to test outputs when text encoders are fp32 and pipeline is fp16 in FLUX according this issue. I write below code but get error.

code :

import torch
from diffusers import FluxPipeline
from transformers import T5EncoderModel, CLIPTextModel
from time import time 
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell",text_encoder_2=None, torch_dtype=torch.float16)
text_encoder_2 = T5EncoderModel.from_pretrained("black-forest-labs/FLUX.1-schnell", subfolder="text_encoder_2", torch_dtype=torch.float32)
pipe.text_encoder_2 = text_encoder_2
pipe.to('cuda')
pipe.vae.enable_tiling()
prompt = "a dog"
image = pipe(
    prompt,
    num_inference_steps=4,
    num_images_per_prompt=1,
    guidance_scale=0.0,
    height=1024,
    width=1024,
).images[0]
image.save("result.png")

error :

mat1 and mat2 must have the same dtype, but got Float and Half
  File "/mnt/saeed.khanehgir/projects/flux/flux-schnell/fp16-te32.py", line 17, in <module>
    image = pipe(
RuntimeError: mat1 and mat2 must have the same dtype, but got Float and Half

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions