Usage with transformers
Can text_encoders/qwen_3_4b_fp4_flux2.safetensors also be loaded directly using huggingface transformers?
Usually, a model.safetensors.index.json is required, but somehow ComfyUI works anyways. I've tried using the configs from https://huggingface.co/black-forest-labs/FLUX.2-klein-4B/tree/main/text_encoder but this doesn't seem to work either:
from transformers import Qwen3ForCausalLM
text_encoder = Qwen3ForCausalLM.from_pretrained(
"qwen_3_4b_fp4_flux2",
use_safetensors=True,
config="black-forest-labs/FLUX.2-klein-4B",
subfolder="text_encoder",
dtype=torch.bfloat16,
)
I'm happy for ideas/suggestions
Two chefs may source the same ingredients, but they don't often appreciate each other's cooking.
We can ponder the best handling instructions using blobs/diffusers , but if you prefer to just execute you may paste this in a notebook and change the text encoder path to your own local file or URL:
import torch, diffusers, transformers
model_id = "black-forest-labs/FLUX.2-klein-4B"
text_encoder_config = transformers.AutoConfig.from_pretrained(model_id, subfolder="text_encoder")
text_encoder = transformers.AutoModel.from_pretrained("/media/dogbowl/bidi/models/text_encoders/qwen_3_4b.safetensors",config=text_encoder_config,torch_dtype=torch.bfloat16)
vae = diffusers.AutoencoderKLFlux2.from_pretrained("black-forest-labs/FLUX.2-small-decoder",torch_dtype=torch.bfloat16)
pipe = diffusers.DiffusionPipeline.from_pretrained(model_id,text_encoder=text_encoder,vae=vae,torch_dtype=torch.bfloat16).to("cuda")
display(pipe(prompt="A casserole looking into a mirror showing the reflection of a pizza.",num_inference_steps=4,guidance_scale=1).images[0])