Guest User

Untitled

a guest
Apr 18th, 2026
104
0
Never
8
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.64 KB | None | 0 0
  1. import os
  2. import time
  3.  
  4. import torch
  5. from torch import Tensor
  6. from transformers import AutoTokenizer, T5Gemma2Model, BatchEncoding
  7.  
  8. # Parameters
  9. prompt = "A category-five hurricane, viewed from inside the eye, reveals a circular stadium of cloud walls rising to fifty thousand feet with an eerie disk of blue sky directly overhead. Shot from a NOAA reconnaissance aircraft mounted camera, the perspective looks outward toward the eyewall — a near-vertical curtain of rotating cloud and lightning that is simultaneously terrifying and transcendent. The inner surface of the eyewall catches the setting sun, painting it in improbable shades of peach and rose. The camera slowly pans 360 degrees to complete one full revolution, capturing the entire coliseum of the storm. Below, the ocean surface is a white blur of foam and spray. The documentary-style cinematography strips away all artifice to present the storm as an entity of pure elemental power."
  10. negative_prompt = ""
  11. model_path = "./"
  12.  
  13. device = "cuda"
  14. dtype = torch.bfloat16
  15.  
  16. # Load Components
  17. tokenizer = AutoTokenizer.from_pretrained(model_path, subfolder="tokenizer")
  18. text_encoder = T5Gemma2Model.from_pretrained(model_path, subfolder="text_encoder", torch_dtype=dtype)
  19. text_encoder.eval()
  20.  
  21. # ==========================================
  22. # Step 1: Encode Text
  23. # ==========================================
  24. def encode_prompt(prompt, tokenizer, text_encoder, device):
  25.     prompt = [prompt] if isinstance(prompt, str) else prompt
  26.    
  27.     text_inputs = tokenizer(
  28.         prompt,
  29.         padding="max_length",
  30.         max_length=512,
  31.         truncation=True,
  32.         add_special_tokens=True,
  33.         return_attention_mask=True,
  34.         return_tensors="pt",
  35.     )
  36.     #input_ids = text_inputs.input_ids.to(device)
  37.     #attention_mask = text_inputs.attention_mask.to(device)
  38.  
  39.     text_inputs = BatchEncoding(
  40.         {k: v.to(device) if isinstance(v, torch.Tensor) else v for k, v in text_inputs.items()}
  41.     )
  42.     attention_mask = text_inputs.attention_mask.to(device)
  43.  
  44.     '''# Encode text sequence
  45.    # T5Gemma2Model bundles encoder and decoder/LM head, while _get_default_embeds expects an encoder-only model (similar to T5EncoderModel/T5GemmaEncoderModel), so use the encoder submodule explicitly here
  46.    outputs = text_encoder.encoder(input_ids=input_ids, attention_mask=attention_mask, output_hidden_states=False, return_dict=True)
  47.    
  48.     # T5Gemma2Model returns an encoder_last_hidden_state or last_hidden_state depending on version — check both:
  49.    if hasattr(outputs, "encoder_last_hidden_state") and outputs.encoder_last_hidden_state is not None:
  50.        prompt_embeds = outputs.encoder_last_hidden_state
  51.    else:
  52.        prompt_embeds = outputs.last_hidden_state'''
  53.    
  54.     prompt_embeds = text_encoder.encoder(**text_inputs)[0]
  55.     prompt_embeds = prompt_embeds.to(device=device)
  56.  
  57.     pooled_prompt_embeds = average_pool(prompt_embeds, attention_mask)
  58.    
  59.     return prompt_embeds, attention_mask, pooled_prompt_embeds
  60.  
  61. def average_pool(last_hidden_states: Tensor, attention_mask: Tensor) -> Tensor:
  62.     last_hidden = last_hidden_states.masked_fill(~attention_mask[..., None].bool(), 0.0)
  63.     denom = attention_mask.sum(dim=1, keepdim=True).clamp(min=1)  # avoid div by zero
  64.     return last_hidden.sum(dim=1) / denom
  65.  
  66. print("Encoding prompt...")
  67. text_encoder.to(device)
  68. with torch.no_grad():
  69.     prompt_embeds, attn_mask, pooled_prompt_embeds = encode_prompt(prompt, tokenizer, text_encoder, device)
  70.     neg_prompt_embeds, neg_attn_mask, neg_pooled_prompt_embeds = encode_prompt(negative_prompt, tokenizer, text_encoder, device)
  71.  
  72. text_encoder.to("cpu")
  73. torch.cuda.empty_cache()
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • Sardalyy
    6 days
    # CSS 0.44 KB | 0 0
    1. Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1Cz5fHkwyaApTWwqfgBBtpvConU8Lo_qJ9xtn7RazWpk/edit?usp=sharing
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
  • Icpegmo
    1 day
    # CSS 0.44 KB | 0 0
    1. Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1Cz5fHkwyaApTWwqfgBBtpvConU8Lo_qJ9xtn7RazWpk/edit?usp=sharing
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment