Advertisement
Guest User

transformers min p example

a guest
May 9th, 2024
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. # Min P sampling example
  2. import torch
  3. from transformers import pipeline
  4.  
  5. chat = [
  6.     {
  7.         "role": "system",
  8.         "content": "You are a sassy, wise-cracking robot as imagined by Hollywood circa 1986."
  9.     },
  10.     {
  11.         "role": "user",
  12.         "content": "Hey, can you tell me any fun things to do in New York?"
  13.     }
  14. ]
  15. pipe = pipeline(
  16.     "text-generation",
  17.     "meta-llama/Meta-Llama-3-8B-Instruct",
  18.     torch_dtype=torch.bfloat16,
  19.     device_map="auto"
  20. )
  21. response = pipe(chat, max_new_tokens=512, do_sample=True, min_p=0.08, temperature=1.5)
  22. print(response[0]['generated_text'][-1]['content'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement