Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -195,6 +195,7 @@ def generate_30(
|
|
195 |
|
196 |
pooled_prompt_embeds_list=[]
|
197 |
prompt_embeds_list=[]
|
|
|
198 |
text_inputs1 = pipe.tokenizer(
|
199 |
prompt,
|
200 |
padding="max_length",
|
@@ -202,7 +203,9 @@ def generate_30(
|
|
202 |
truncation=True,
|
203 |
return_tensors="pt",
|
204 |
)
|
|
|
205 |
text_input_ids1 = text_inputs1.input_ids
|
|
|
206 |
text_inputs2 = pipe.tokenizer(
|
207 |
prompt2,
|
208 |
padding="max_length",
|
@@ -210,8 +213,28 @@ def generate_30(
|
|
210 |
truncation=True,
|
211 |
return_tensors="pt",
|
212 |
)
|
|
|
213 |
text_input_ids2 = text_inputs2.input_ids
|
214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
# 2. Encode with the two text encoders
|
216 |
prompt_embeds_a = pipe.text_encoder(text_input_ids1.to(torch.device('cuda')), output_hidden_states=True)
|
217 |
pooled_prompt_embeds_a = prompt_embeds_a[0] # Pooled output from encoder 1
|
@@ -221,6 +244,14 @@ def generate_30(
|
|
221 |
pooled_prompt_embeds_b = prompt_embeds_b[0] # Pooled output from encoder 2
|
222 |
prompt_embeds_b = prompt_embeds_b.hidden_states[-2] # Penultimate hidden state from encoder 2
|
223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
# 3. Concatenate the embeddings
|
225 |
prompt_embeds = torch.cat([prompt_embeds_a, prompt_embeds_b])
|
226 |
print('catted shape: ', prompt_embeds.shape)
|
@@ -231,6 +262,15 @@ def generate_30(
|
|
231 |
pooled_prompt_embeds = torch.mean(pooled_prompt_embeds,dim=0)
|
232 |
print('pooled averaged shape: ', pooled_prompt_embeds.shape)
|
233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
options = {
|
235 |
#"prompt": prompt,
|
236 |
"prompt_embeds": prompt_embeds,
|
@@ -279,6 +319,7 @@ def generate_60(
|
|
279 |
|
280 |
pooled_prompt_embeds_list=[]
|
281 |
prompt_embeds_list=[]
|
|
|
282 |
text_inputs1 = pipe.tokenizer(
|
283 |
prompt,
|
284 |
padding="max_length",
|
@@ -286,7 +327,9 @@ def generate_60(
|
|
286 |
truncation=True,
|
287 |
return_tensors="pt",
|
288 |
)
|
|
|
289 |
text_input_ids1 = text_inputs1.input_ids
|
|
|
290 |
text_inputs2 = pipe.tokenizer(
|
291 |
prompt2,
|
292 |
padding="max_length",
|
@@ -294,8 +337,28 @@ def generate_60(
|
|
294 |
truncation=True,
|
295 |
return_tensors="pt",
|
296 |
)
|
|
|
297 |
text_input_ids2 = text_inputs2.input_ids
|
298 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
# 2. Encode with the two text encoders
|
300 |
prompt_embeds_a = pipe.text_encoder(text_input_ids1.to(torch.device('cuda')), output_hidden_states=True)
|
301 |
pooled_prompt_embeds_a = prompt_embeds_a[0] # Pooled output from encoder 1
|
@@ -305,6 +368,14 @@ def generate_60(
|
|
305 |
pooled_prompt_embeds_b = prompt_embeds_b[0] # Pooled output from encoder 2
|
306 |
prompt_embeds_b = prompt_embeds_b.hidden_states[-2] # Penultimate hidden state from encoder 2
|
307 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
# 3. Concatenate the embeddings
|
309 |
prompt_embeds = torch.cat([prompt_embeds_a, prompt_embeds_b])
|
310 |
print('catted shape: ', prompt_embeds.shape)
|
@@ -315,7 +386,15 @@ def generate_60(
|
|
315 |
pooled_prompt_embeds = torch.mean(pooled_prompt_embeds,dim=0)
|
316 |
print('pooled averaged shape: ', pooled_prompt_embeds.shape)
|
317 |
|
318 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
319 |
options = {
|
320 |
#"prompt": prompt,
|
321 |
"prompt_embeds": prompt_embeds,
|
@@ -364,6 +443,7 @@ def generate_90(
|
|
364 |
|
365 |
pooled_prompt_embeds_list=[]
|
366 |
prompt_embeds_list=[]
|
|
|
367 |
text_inputs1 = pipe.tokenizer(
|
368 |
prompt,
|
369 |
padding="max_length",
|
@@ -371,7 +451,9 @@ def generate_90(
|
|
371 |
truncation=True,
|
372 |
return_tensors="pt",
|
373 |
)
|
|
|
374 |
text_input_ids1 = text_inputs1.input_ids
|
|
|
375 |
text_inputs2 = pipe.tokenizer(
|
376 |
prompt2,
|
377 |
padding="max_length",
|
@@ -379,8 +461,28 @@ def generate_90(
|
|
379 |
truncation=True,
|
380 |
return_tensors="pt",
|
381 |
)
|
|
|
382 |
text_input_ids2 = text_inputs2.input_ids
|
383 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
# 2. Encode with the two text encoders
|
385 |
prompt_embeds_a = pipe.text_encoder(text_input_ids1.to(torch.device('cuda')), output_hidden_states=True)
|
386 |
pooled_prompt_embeds_a = prompt_embeds_a[0] # Pooled output from encoder 1
|
@@ -389,7 +491,15 @@ def generate_90(
|
|
389 |
prompt_embeds_b = pipe.text_encoder(text_input_ids2.to(torch.device('cuda')), output_hidden_states=True)
|
390 |
pooled_prompt_embeds_b = prompt_embeds_b[0] # Pooled output from encoder 2
|
391 |
prompt_embeds_b = prompt_embeds_b.hidden_states[-2] # Penultimate hidden state from encoder 2
|
392 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
393 |
# 3. Concatenate the embeddings
|
394 |
prompt_embeds = torch.cat([prompt_embeds_a, prompt_embeds_b])
|
395 |
print('catted shape: ', prompt_embeds.shape)
|
@@ -400,6 +510,15 @@ def generate_90(
|
|
400 |
pooled_prompt_embeds = torch.mean(pooled_prompt_embeds,dim=0)
|
401 |
print('pooled averaged shape: ', pooled_prompt_embeds.shape)
|
402 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
options = {
|
404 |
#"prompt": prompt,
|
405 |
"prompt_embeds": prompt_embeds,
|
|
|
195 |
|
196 |
pooled_prompt_embeds_list=[]
|
197 |
prompt_embeds_list=[]
|
198 |
+
|
199 |
text_inputs1 = pipe.tokenizer(
|
200 |
prompt,
|
201 |
padding="max_length",
|
|
|
203 |
truncation=True,
|
204 |
return_tensors="pt",
|
205 |
)
|
206 |
+
|
207 |
text_input_ids1 = text_inputs1.input_ids
|
208 |
+
|
209 |
text_inputs2 = pipe.tokenizer(
|
210 |
prompt2,
|
211 |
padding="max_length",
|
|
|
213 |
truncation=True,
|
214 |
return_tensors="pt",
|
215 |
)
|
216 |
+
|
217 |
text_input_ids2 = text_inputs2.input_ids
|
218 |
|
219 |
+
text_inputs1b = pipe.tokenizer_2(
|
220 |
+
prompt,
|
221 |
+
padding="max_length",
|
222 |
+
max_length=77,
|
223 |
+
truncation=True,
|
224 |
+
return_tensors="pt",
|
225 |
+
)
|
226 |
+
|
227 |
+
text_input_ids1b = text_inputs1b.input_ids
|
228 |
+
|
229 |
+
text_inputs2b = pipe.tokenizer_2(
|
230 |
+
prompt2,
|
231 |
+
padding="max_length",
|
232 |
+
max_length=77,
|
233 |
+
truncation=True,
|
234 |
+
return_tensors="pt",
|
235 |
+
)
|
236 |
+
text_input_ids2b = text_inputs2b.input_ids
|
237 |
+
|
238 |
# 2. Encode with the two text encoders
|
239 |
prompt_embeds_a = pipe.text_encoder(text_input_ids1.to(torch.device('cuda')), output_hidden_states=True)
|
240 |
pooled_prompt_embeds_a = prompt_embeds_a[0] # Pooled output from encoder 1
|
|
|
244 |
pooled_prompt_embeds_b = prompt_embeds_b[0] # Pooled output from encoder 2
|
245 |
prompt_embeds_b = prompt_embeds_b.hidden_states[-2] # Penultimate hidden state from encoder 2
|
246 |
|
247 |
+
prompt_embeds_a2 = pipe.text_encoder_2(text_input_ids1b.to(torch.device('cuda')), output_hidden_states=True)
|
248 |
+
pooled_prompt_embeds_a2 = prompt_embeds_a2[0] # Pooled output from encoder 1
|
249 |
+
prompt_embeds_a2 = prompt_embeds_a2.hidden_states[-2] # Penultimate hidden state from encoder 1
|
250 |
+
print('encoder shape: ', prompt_embeds_a2.shape)
|
251 |
+
prompt_embeds_b2 = pipe.text_encoder_2(text_input_ids2b.to(torch.device('cuda')), output_hidden_states=True)
|
252 |
+
pooled_prompt_embeds_b2 = prompt_embeds_b2[0] # Pooled output from encoder 2
|
253 |
+
prompt_embeds_b2 = prompt_embeds_b2.hidden_states[-2] # Penultimate hidden state from encoder 2
|
254 |
+
|
255 |
# 3. Concatenate the embeddings
|
256 |
prompt_embeds = torch.cat([prompt_embeds_a, prompt_embeds_b])
|
257 |
print('catted shape: ', prompt_embeds.shape)
|
|
|
262 |
pooled_prompt_embeds = torch.mean(pooled_prompt_embeds,dim=0)
|
263 |
print('pooled averaged shape: ', pooled_prompt_embeds.shape)
|
264 |
|
265 |
+
# 3. Concatenate the text_encoder_2 embeddings
|
266 |
+
prompt_embeds2 = torch.cat([prompt_embeds_a2, prompt_embeds_b2])
|
267 |
+
print('catted shape2: ', prompt_embeds.shape)
|
268 |
+
pooled_prompt_embeds2 = torch.cat([pooled_prompt_embeds_a2, pooled_prompt_embeds_b2])
|
269 |
+
pooled_prompt_embeds2 = torch.cat([pooled_prompt_embeds, pooled_prompt_embeds2], dim=2)
|
270 |
+
# 4. (Optional) Average the pooled embeddings
|
271 |
+
pooled_prompt_embeds = torch.mean(pooled_prompt_embeds2,dim=0)
|
272 |
+
print('pooled averaged shape: ', pooled_prompt_embeds.shape)
|
273 |
+
|
274 |
options = {
|
275 |
#"prompt": prompt,
|
276 |
"prompt_embeds": prompt_embeds,
|
|
|
319 |
|
320 |
pooled_prompt_embeds_list=[]
|
321 |
prompt_embeds_list=[]
|
322 |
+
|
323 |
text_inputs1 = pipe.tokenizer(
|
324 |
prompt,
|
325 |
padding="max_length",
|
|
|
327 |
truncation=True,
|
328 |
return_tensors="pt",
|
329 |
)
|
330 |
+
|
331 |
text_input_ids1 = text_inputs1.input_ids
|
332 |
+
|
333 |
text_inputs2 = pipe.tokenizer(
|
334 |
prompt2,
|
335 |
padding="max_length",
|
|
|
337 |
truncation=True,
|
338 |
return_tensors="pt",
|
339 |
)
|
340 |
+
|
341 |
text_input_ids2 = text_inputs2.input_ids
|
342 |
|
343 |
+
text_inputs1b = pipe.tokenizer_2(
|
344 |
+
prompt,
|
345 |
+
padding="max_length",
|
346 |
+
max_length=77,
|
347 |
+
truncation=True,
|
348 |
+
return_tensors="pt",
|
349 |
+
)
|
350 |
+
|
351 |
+
text_input_ids1b = text_inputs1b.input_ids
|
352 |
+
|
353 |
+
text_inputs2b = pipe.tokenizer_2(
|
354 |
+
prompt2,
|
355 |
+
padding="max_length",
|
356 |
+
max_length=77,
|
357 |
+
truncation=True,
|
358 |
+
return_tensors="pt",
|
359 |
+
)
|
360 |
+
text_input_ids2b = text_inputs2b.input_ids
|
361 |
+
|
362 |
# 2. Encode with the two text encoders
|
363 |
prompt_embeds_a = pipe.text_encoder(text_input_ids1.to(torch.device('cuda')), output_hidden_states=True)
|
364 |
pooled_prompt_embeds_a = prompt_embeds_a[0] # Pooled output from encoder 1
|
|
|
368 |
pooled_prompt_embeds_b = prompt_embeds_b[0] # Pooled output from encoder 2
|
369 |
prompt_embeds_b = prompt_embeds_b.hidden_states[-2] # Penultimate hidden state from encoder 2
|
370 |
|
371 |
+
prompt_embeds_a2 = pipe.text_encoder_2(text_input_ids1b.to(torch.device('cuda')), output_hidden_states=True)
|
372 |
+
pooled_prompt_embeds_a2 = prompt_embeds_a2[0] # Pooled output from encoder 1
|
373 |
+
prompt_embeds_a2 = prompt_embeds_a2.hidden_states[-2] # Penultimate hidden state from encoder 1
|
374 |
+
print('encoder shape: ', prompt_embeds_a2.shape)
|
375 |
+
prompt_embeds_b2 = pipe.text_encoder_2(text_input_ids2b.to(torch.device('cuda')), output_hidden_states=True)
|
376 |
+
pooled_prompt_embeds_b2 = prompt_embeds_b2[0] # Pooled output from encoder 2
|
377 |
+
prompt_embeds_b2 = prompt_embeds_b2.hidden_states[-2] # Penultimate hidden state from encoder 2
|
378 |
+
|
379 |
# 3. Concatenate the embeddings
|
380 |
prompt_embeds = torch.cat([prompt_embeds_a, prompt_embeds_b])
|
381 |
print('catted shape: ', prompt_embeds.shape)
|
|
|
386 |
pooled_prompt_embeds = torch.mean(pooled_prompt_embeds,dim=0)
|
387 |
print('pooled averaged shape: ', pooled_prompt_embeds.shape)
|
388 |
|
389 |
+
# 3. Concatenate the text_encoder_2 embeddings
|
390 |
+
prompt_embeds2 = torch.cat([prompt_embeds_a2, prompt_embeds_b2])
|
391 |
+
print('catted shape2: ', prompt_embeds.shape)
|
392 |
+
pooled_prompt_embeds2 = torch.cat([pooled_prompt_embeds_a2, pooled_prompt_embeds_b2])
|
393 |
+
pooled_prompt_embeds2 = torch.cat([pooled_prompt_embeds, pooled_prompt_embeds2], dim=2)
|
394 |
+
# 4. (Optional) Average the pooled embeddings
|
395 |
+
pooled_prompt_embeds = torch.mean(pooled_prompt_embeds2,dim=0)
|
396 |
+
print('pooled averaged shape: ', pooled_prompt_embeds.shape)
|
397 |
+
|
398 |
options = {
|
399 |
#"prompt": prompt,
|
400 |
"prompt_embeds": prompt_embeds,
|
|
|
443 |
|
444 |
pooled_prompt_embeds_list=[]
|
445 |
prompt_embeds_list=[]
|
446 |
+
|
447 |
text_inputs1 = pipe.tokenizer(
|
448 |
prompt,
|
449 |
padding="max_length",
|
|
|
451 |
truncation=True,
|
452 |
return_tensors="pt",
|
453 |
)
|
454 |
+
|
455 |
text_input_ids1 = text_inputs1.input_ids
|
456 |
+
|
457 |
text_inputs2 = pipe.tokenizer(
|
458 |
prompt2,
|
459 |
padding="max_length",
|
|
|
461 |
truncation=True,
|
462 |
return_tensors="pt",
|
463 |
)
|
464 |
+
|
465 |
text_input_ids2 = text_inputs2.input_ids
|
466 |
|
467 |
+
text_inputs1b = pipe.tokenizer_2(
|
468 |
+
prompt,
|
469 |
+
padding="max_length",
|
470 |
+
max_length=77,
|
471 |
+
truncation=True,
|
472 |
+
return_tensors="pt",
|
473 |
+
)
|
474 |
+
|
475 |
+
text_input_ids1b = text_inputs1b.input_ids
|
476 |
+
|
477 |
+
text_inputs2b = pipe.tokenizer_2(
|
478 |
+
prompt2,
|
479 |
+
padding="max_length",
|
480 |
+
max_length=77,
|
481 |
+
truncation=True,
|
482 |
+
return_tensors="pt",
|
483 |
+
)
|
484 |
+
text_input_ids2b = text_inputs2b.input_ids
|
485 |
+
|
486 |
# 2. Encode with the two text encoders
|
487 |
prompt_embeds_a = pipe.text_encoder(text_input_ids1.to(torch.device('cuda')), output_hidden_states=True)
|
488 |
pooled_prompt_embeds_a = prompt_embeds_a[0] # Pooled output from encoder 1
|
|
|
491 |
prompt_embeds_b = pipe.text_encoder(text_input_ids2.to(torch.device('cuda')), output_hidden_states=True)
|
492 |
pooled_prompt_embeds_b = prompt_embeds_b[0] # Pooled output from encoder 2
|
493 |
prompt_embeds_b = prompt_embeds_b.hidden_states[-2] # Penultimate hidden state from encoder 2
|
494 |
+
|
495 |
+
prompt_embeds_a2 = pipe.text_encoder_2(text_input_ids1b.to(torch.device('cuda')), output_hidden_states=True)
|
496 |
+
pooled_prompt_embeds_a2 = prompt_embeds_a2[0] # Pooled output from encoder 1
|
497 |
+
prompt_embeds_a2 = prompt_embeds_a2.hidden_states[-2] # Penultimate hidden state from encoder 1
|
498 |
+
print('encoder shape: ', prompt_embeds_a2.shape)
|
499 |
+
prompt_embeds_b2 = pipe.text_encoder_2(text_input_ids2b.to(torch.device('cuda')), output_hidden_states=True)
|
500 |
+
pooled_prompt_embeds_b2 = prompt_embeds_b2[0] # Pooled output from encoder 2
|
501 |
+
prompt_embeds_b2 = prompt_embeds_b2.hidden_states[-2] # Penultimate hidden state from encoder 2
|
502 |
+
|
503 |
# 3. Concatenate the embeddings
|
504 |
prompt_embeds = torch.cat([prompt_embeds_a, prompt_embeds_b])
|
505 |
print('catted shape: ', prompt_embeds.shape)
|
|
|
510 |
pooled_prompt_embeds = torch.mean(pooled_prompt_embeds,dim=0)
|
511 |
print('pooled averaged shape: ', pooled_prompt_embeds.shape)
|
512 |
|
513 |
+
# 3. Concatenate the text_encoder_2 embeddings
|
514 |
+
prompt_embeds2 = torch.cat([prompt_embeds_a2, prompt_embeds_b2])
|
515 |
+
print('catted shape2: ', prompt_embeds.shape)
|
516 |
+
pooled_prompt_embeds2 = torch.cat([pooled_prompt_embeds_a2, pooled_prompt_embeds_b2])
|
517 |
+
pooled_prompt_embeds2 = torch.cat([pooled_prompt_embeds, pooled_prompt_embeds2], dim=2)
|
518 |
+
# 4. (Optional) Average the pooled embeddings
|
519 |
+
pooled_prompt_embeds = torch.mean(pooled_prompt_embeds2,dim=0)
|
520 |
+
print('pooled averaged shape: ', pooled_prompt_embeds.shape)
|
521 |
+
|
522 |
options = {
|
523 |
#"prompt": prompt,
|
524 |
"prompt_embeds": prompt_embeds,
|