File size: 803 Bytes
b11cd65
 
 
 
 
 
 
 
 
 
030a9e9
b11cd65
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from transformers import AutoTokenizer, AutoModelForCausalLM

checkpoint = 'alexghergh/gpt1'
model = AutoModelForCausalLM.from_pretrained(checkpoint, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(checkpoint, trust_remote_code=True)

prompt = 'The mastermind behind the plan was, all along, '
inputs = tokenizer(prompt, return_tensors='pt')

generate_ids = model.generate(inputs.input_ids,
                              max_new_tokens=40,
                              num_beams=1,
                              do_sample=True,
                              top_p=0.9,
                              temperature=0.8)

print(tokenizer.batch_decode(generate_ids,
                             skip_special_tokens=True,
                             clean_up_tokenization_spaces=False)[0])