ZhouZJ36DL commited on
Commit
84a1d6d
·
1 Parent(s): 9db2fe3

modified: src/flux/modules/conditioner.py

Browse files
src/flux/__pycache__/__init__.cpython-310.pyc CHANGED
Binary files a/src/flux/__pycache__/__init__.cpython-310.pyc and b/src/flux/__pycache__/__init__.cpython-310.pyc differ
 
src/flux/__pycache__/_version.cpython-310.pyc CHANGED
Binary files a/src/flux/__pycache__/_version.cpython-310.pyc and b/src/flux/__pycache__/_version.cpython-310.pyc differ
 
src/flux/__pycache__/math.cpython-310.pyc CHANGED
Binary files a/src/flux/__pycache__/math.cpython-310.pyc and b/src/flux/__pycache__/math.cpython-310.pyc differ
 
src/flux/__pycache__/model.cpython-310.pyc CHANGED
Binary files a/src/flux/__pycache__/model.cpython-310.pyc and b/src/flux/__pycache__/model.cpython-310.pyc differ
 
src/flux/__pycache__/sampling.cpython-310.pyc CHANGED
Binary files a/src/flux/__pycache__/sampling.cpython-310.pyc and b/src/flux/__pycache__/sampling.cpython-310.pyc differ
 
src/flux/__pycache__/util.cpython-310.pyc CHANGED
Binary files a/src/flux/__pycache__/util.cpython-310.pyc and b/src/flux/__pycache__/util.cpython-310.pyc differ
 
src/flux/modules/__pycache__/autoencoder.cpython-310.pyc CHANGED
Binary files a/src/flux/modules/__pycache__/autoencoder.cpython-310.pyc and b/src/flux/modules/__pycache__/autoencoder.cpython-310.pyc differ
 
src/flux/modules/__pycache__/conditioner.cpython-310.pyc CHANGED
Binary files a/src/flux/modules/__pycache__/conditioner.cpython-310.pyc and b/src/flux/modules/__pycache__/conditioner.cpython-310.pyc differ
 
src/flux/modules/__pycache__/layers.cpython-310.pyc CHANGED
Binary files a/src/flux/modules/__pycache__/layers.cpython-310.pyc and b/src/flux/modules/__pycache__/layers.cpython-310.pyc differ
 
src/flux/modules/conditioner.py CHANGED
@@ -1,6 +1,6 @@
1
  from torch import Tensor, nn
2
  from transformers import (CLIPTextModel, CLIPTokenizer, T5EncoderModel,
3
- T5Tokenizer)
4
  import os
5
 
6
  class HFEmbedder(nn.Module):
@@ -12,35 +12,15 @@ class HFEmbedder(nn.Module):
12
 
13
  if self.is_clip:
14
  self.tokenizer: CLIPTokenizer = CLIPTokenizer.from_pretrained(version, max_length=max_length)
15
- self.hf_module: CLIPTextModel = CLIPTextModel.from_pretrained(version, **hf_kwargs)
 
 
16
  else:
17
  self.tokenizer: T5Tokenizer = T5Tokenizer.from_pretrained(version, max_length=max_length)
18
  self.hf_module: T5EncoderModel = T5EncoderModel.from_pretrained(version, **hf_kwargs)
19
 
20
  self.hf_module = self.hf_module.eval().requires_grad_(False)
21
 
22
- # In your HFEmbedder class's __init__ method, or after loading the clip model
23
- # Assuming 'self.hf_module' is the CLIPTextModel instance for your CLIP embedder
24
- if self.is_clip: # Add this check if HFEmbedder is used for both T5 and CLIP
25
- clip_model_config = self.hf_module.config
26
- print(f"CLIP Model Version: {self.hf_module.name_or_path}") # or 'version' if that's the attribute
27
- print(f"CLIP Config max_position_embeddings: {clip_model_config.max_position_embeddings}")
28
-
29
- # Accessing the CLIPTextEmbeddings module
30
- # Path is typically model.embeddings for CLIPTextModel
31
- text_embeddings_module = self.hf_module.embeddings
32
-
33
- print(f"CLIP Position Embedding Layer num_embeddings: {text_embeddings_module.position_embedding.num_embeddings}")
34
- print(f"CLIP Position IDs buffer 'position_ids' (from CLIPTextEmbeddings) shape: {text_embeddings_module.position_ids.shape}")
35
-
36
- if text_embeddings_module.position_ids.shape[1] != text_embeddings_module.position_embedding.num_embeddings:
37
- print("CRITICAL WARNING: Mismatch between position_ids buffer length and actual embedding layer size!")
38
- if clip_model_config.max_position_embeddings != text_embeddings_module.position_embedding.num_embeddings:
39
- print("CRITICAL WARNING: Mismatch between config.max_position_embeddings and actual embedding layer size!")
40
- if self.max_length != text_embeddings_module.position_embedding.num_embeddings:
41
- print(f"WARNING: Tokenizer max_length ({self.max_length}) "
42
- f"does not match position embedding size ({text_embeddings_module.position_embedding.num_embeddings})")
43
-
44
 
45
  def forward(self, text: list[str]) -> Tensor:
46
  batch_encoding = self.tokenizer(
 
1
  from torch import Tensor, nn
2
  from transformers import (CLIPTextModel, CLIPTokenizer, T5EncoderModel,
3
+ T5Tokenizer, AutoConfig)
4
  import os
5
 
6
  class HFEmbedder(nn.Module):
 
12
 
13
  if self.is_clip:
14
  self.tokenizer: CLIPTokenizer = CLIPTokenizer.from_pretrained(version, max_length=max_length)
15
+ config = AutoConfig.from_pretrained(version, max_position_embeddings=77)
16
+ self.hf_module = CLIPTextModel.from_pretrained(version, config=config, **hf_kwargs)
17
+ #self.hf_module: CLIPTextModel = CLIPTextModel.from_pretrained(version, **hf_kwargs)
18
  else:
19
  self.tokenizer: T5Tokenizer = T5Tokenizer.from_pretrained(version, max_length=max_length)
20
  self.hf_module: T5EncoderModel = T5EncoderModel.from_pretrained(version, **hf_kwargs)
21
 
22
  self.hf_module = self.hf_module.eval().requires_grad_(False)
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  def forward(self, text: list[str]) -> Tensor:
26
  batch_encoding = self.tokenizer(