wondervictor commited on
Commit
18af252
1 Parent(s): 0e7e92c
Files changed (3) hide show
  1. autoregressive/models/generate.py +7 -5
  2. language/t5.py +2 -2
  3. model.py +1 -1
autoregressive/models/generate.py CHANGED
@@ -57,6 +57,7 @@ def top_k_top_p_filtering(
57
 
58
 
59
  def sample(logits, temperature: float=1.0, top_k: int=2000, top_p: float=1.0, sample_logits=True):
 
60
  logits = logits[:, -1, :] / max(temperature, 1e-5)
61
  if top_k > 0 or top_p < 1.0:
62
  logits = top_k_top_p_filtering(logits, top_k=top_k, top_p=top_p)
@@ -137,15 +138,16 @@ def decode_n_tokens(
137
 
138
  @torch.no_grad()
139
  def generate(model, cond, max_new_tokens, emb_masks=None, cfg_scale=1.0, cfg_interval=-1, condition=None, condition_null=None, condition_token_nums=0, **sampling_kwargs):
 
140
  if condition is not None:
141
  with torch.no_grad():
142
- print(f'nan: {torch.any(torch.isnan(model.adapter.model.embeddings.patch_embeddings.projection.weight))}')
143
- print(model.adapter.model.embeddings.patch_embeddings.projection.weight)
144
  condition = model.adapter(condition)
145
- print(condition)
146
- condition = torch.ones_like(condition)
147
  condition = model.adapter_mlp(condition)
148
- #print(condition)
149
  if model.model_type == 'c2i':
150
  if cfg_scale > 1.0:
151
  cond_null = torch.ones_like(cond) * model.num_classes
 
57
 
58
 
59
  def sample(logits, temperature: float=1.0, top_k: int=2000, top_p: float=1.0, sample_logits=True):
60
+ # print(logits, torch.any(torch.isnan(logits)))
61
  logits = logits[:, -1, :] / max(temperature, 1e-5)
62
  if top_k > 0 or top_p < 1.0:
63
  logits = top_k_top_p_filtering(logits, top_k=top_k, top_p=top_p)
 
138
 
139
  @torch.no_grad()
140
  def generate(model, cond, max_new_tokens, emb_masks=None, cfg_scale=1.0, cfg_interval=-1, condition=None, condition_null=None, condition_token_nums=0, **sampling_kwargs):
141
+ print("cond", torch.any(torch.isnan(cond)))
142
  if condition is not None:
143
  with torch.no_grad():
144
+ # print(f'nan: {torch.any(torch.isnan(model.adapter.model.embeddings.patch_embeddings.projection.weight))}')
145
+ # print(model.adapter.model.embeddings.patch_embeddings.projection.weight)
146
  condition = model.adapter(condition)
147
+ # print("before condition", condition)
148
+ # condition = torch.ones_like(condition)
149
  condition = model.adapter_mlp(condition)
150
+ print("condition", torch.any(torch.isnan(condition)))
151
  if model.model_type == 'c2i':
152
  if cfg_scale > 1.0:
153
  cond_null = torch.ones_like(cond) * model.num_classes
language/t5.py CHANGED
@@ -18,7 +18,7 @@ class T5Embedder:
18
 
19
  def __init__(self, device, dir_or_name='t5-v1_1-xxl', *, local_cache=False, cache_dir=None, hf_token=None, use_text_preprocessing=True,
20
  t5_model_kwargs=None, torch_dtype=None, use_offload_folder=None, model_max_length=120):
21
- self.device = torch.device('cuda:0')
22
  self.torch_dtype = torch_dtype or torch.bfloat16
23
  if t5_model_kwargs is None:
24
  t5_model_kwargs = {'low_cpu_mem_usage': True, 'torch_dtype': self.torch_dtype}
@@ -53,7 +53,7 @@ class T5Embedder:
53
  print(tokenizer_path)
54
  self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_path)
55
  self.model = T5EncoderModel.from_pretrained(path, **t5_model_kwargs).eval()
56
- self.model.to('cuda')
57
  self.model_max_length = model_max_length
58
 
59
  def get_text_embeddings(self, texts):
 
18
 
19
  def __init__(self, device, dir_or_name='t5-v1_1-xxl', *, local_cache=False, cache_dir=None, hf_token=None, use_text_preprocessing=True,
20
  t5_model_kwargs=None, torch_dtype=None, use_offload_folder=None, model_max_length=120):
21
+ self.device = torch.device('cpu')
22
  self.torch_dtype = torch_dtype or torch.bfloat16
23
  if t5_model_kwargs is None:
24
  t5_model_kwargs = {'low_cpu_mem_usage': True, 'torch_dtype': self.torch_dtype}
 
53
  print(tokenizer_path)
54
  self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_path)
55
  self.model = T5EncoderModel.from_pretrained(path, **t5_model_kwargs).eval()
56
+ # self.model.to('cuda')
57
  self.model_max_length = model_max_length
58
 
59
  def get_text_embeddings(self, texts):
model.py CHANGED
@@ -123,9 +123,9 @@ class Model:
123
  image = resize_image_to_16_multiple(image, 'canny')
124
  W, H = image.size
125
  print(W, H)
126
- print("before cuda", self.gpt_model_canny.adapter.model.embeddings.patch_embeddings.projection.weight)
127
  self.t5_model.model.to('cuda')
128
  self.gpt_model_canny.to('cuda')
 
129
 
130
  condition_img = self.get_control_canny(np.array(image), low_threshold,
131
  high_threshold)
 
123
  image = resize_image_to_16_multiple(image, 'canny')
124
  W, H = image.size
125
  print(W, H)
 
126
  self.t5_model.model.to('cuda')
127
  self.gpt_model_canny.to('cuda')
128
+ print("after cuda", self.gpt_model_canny.adapter.model.embeddings.patch_embeddings.projection.weight)
129
 
130
  condition_img = self.get_control_canny(np.array(image), low_threshold,
131
  high_threshold)