Tianshuo-Xu commited on
Commit
d84e45a
·
1 Parent(s): 142c40b

fix local cache path embedder type detection

Browse files
src/flux/modules/conditioner.py CHANGED
@@ -4,9 +4,9 @@ from transformers import (CLIPTextModel, CLIPTokenizer, T5EncoderModel,
4
 
5
 
6
  class HFEmbedder(nn.Module):
7
- def __init__(self, version: str, max_length: int, **hf_kwargs):
8
  super().__init__()
9
- self.is_clip = version.startswith("openai")
10
  self.max_length = max_length
11
  self.output_key = "pooler_output" if self.is_clip else "last_hidden_state"
12
 
 
4
 
5
 
6
  class HFEmbedder(nn.Module):
7
+ def __init__(self, version: str, max_length: int, is_clip: bool | None = None, **hf_kwargs):
8
  super().__init__()
9
+ self.is_clip = version.startswith("openai") if is_clip is None else is_clip
10
  self.max_length = max_length
11
  self.output_key = "pooler_output" if self.is_clip else "last_hidden_state"
12
 
src/flux/util.py CHANGED
@@ -366,12 +366,12 @@ def load_controlnet(name, device, transformer=None):
366
  def load_t5(device: str | torch.device = "cuda", max_length: int = 512) -> HFEmbedder:
367
  # max length 64, 128, 256 and 512 should work (if your sequence is short enough)
368
  t5_source = os.environ.get("XFLUX_TEXT_ENCODER_PATH", "xlabs-ai/xflux_text_encoders")
369
- return HFEmbedder(t5_source, max_length=max_length, torch_dtype=torch.float32).to(device)
370
  # return HFEmbedder("google/mt5-base", max_length=max_length, torch_dtype=torch.float32).to(device)
371
 
372
  def load_clip(device: str | torch.device = "cuda") -> HFEmbedder:
373
  clip_source = os.environ.get("XFLUX_CLIP_ENCODER_PATH", "openai/clip-vit-large-patch14")
374
- return HFEmbedder(clip_source, max_length=77, torch_dtype=torch.float32).to(device)
375
 
376
 
377
  def load_ae(name: str, device: str | torch.device = "cuda", hf_download: bool = True) -> AutoEncoder:
 
366
  def load_t5(device: str | torch.device = "cuda", max_length: int = 512) -> HFEmbedder:
367
  # max length 64, 128, 256 and 512 should work (if your sequence is short enough)
368
  t5_source = os.environ.get("XFLUX_TEXT_ENCODER_PATH", "xlabs-ai/xflux_text_encoders")
369
+ return HFEmbedder(t5_source, max_length=max_length, is_clip=False, torch_dtype=torch.float32).to(device)
370
  # return HFEmbedder("google/mt5-base", max_length=max_length, torch_dtype=torch.float32).to(device)
371
 
372
  def load_clip(device: str | torch.device = "cuda") -> HFEmbedder:
373
  clip_source = os.environ.get("XFLUX_CLIP_ENCODER_PATH", "openai/clip-vit-large-patch14")
374
+ return HFEmbedder(clip_source, max_length=77, is_clip=True, torch_dtype=torch.float32).to(device)
375
 
376
 
377
  def load_ae(name: str, device: str | torch.device = "cuda", hf_download: bool = True) -> AutoEncoder: