Uglevod7 commited on
Commit
2beedbe
1 Parent(s): c7c476b
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2
+
3
+ model_name_or_path = "TheBloke/Unholy-v1-12L-13B-GPTQ"
4
+ # To use a different branch, change revision
5
+ # For example: revision="main"
6
+ model = AutoModelForCausalLM.from_pretrained(model_name_or_path,
7
+ device_map="auto",
8
+ trust_remote_code=False,
9
+ revision="main")
10
+
11
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
12
+
13
+ prompt = "Tell me about AI"
14
+ prompt_template=f'''Below is an instruction that describes a task. Write a response that appropriately completes the request.
15
+
16
+ ### Instruction:
17
+ {prompt}
18
+
19
+ ### Response:
20
+
21
+ '''
22
+
23
+ print("\n\n*** Generate:")
24
+
25
+ input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
26
+ output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, top_p=0.95, top_k=40, max_new_tokens=512)
27
+ print(tokenizer.decode(output[0]))
28
+
29
+ # Inference can also be done using transformers' pipeline
30
+
31
+ print("*** Pipeline:")
32
+ pipe = pipeline(
33
+ "text-generation",
34
+ model=model,
35
+ tokenizer=tokenizer,
36
+ max_new_tokens=512,
37
+ do_sample=True,
38
+ temperature=0.7,
39
+ top_p=0.95,
40
+ top_k=40,
41
+ repetition_penalty=1.1
42
+ )
43
+
44
+ print(pipe(prompt_template)[0]['generated_text'])