uf-aice-lab commited on
Commit
1db7a04
1 Parent(s): bb48f67

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +78 -0
README.md ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ pipeline_tag: question-answering
6
+ ---
7
+ # Llama-mt-lora
8
+
9
+ <!-- Provide a quick summary of what the model is/does. -->
10
+
11
+ This model is fine-tuned with LLaMA with 8 Nvidia A100-80G GPUs using 3,000,000 groups of conversations in the context of mathematics by students and facilitators on Algebra Nation (https://www.mathnation.com/). Llama-mt-lora consists of 32 layers and over 7 billion parameters, consuming up to 13.5 gigabytes of disk space. Researchers can experiment with and finetune the model to help construct math conversational AI that can effectively respond generation in a mathematical context.
12
+ ### Here is how to use it with texts in HuggingFace
13
+ ```python
14
+ import torch
15
+ import transformers
16
+ from transformers import LlamaTokenizer, AutoModelForCausalLM
17
+ tokenizer = LlamaTokenizer.from_pretrained("Fan21/Llama-mt-lora")
18
+ mdoel = LlamaForCausalLM.from_pretrained(
19
+ "Fan21/Llama-mt-lora",
20
+ load_in_8bit=False,
21
+ torch_dtype=torch.float16,
22
+ device_map="auto",
23
+ )
24
+ def generate_prompt(instruction, input=None):
25
+ if input:
26
+ return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
27
+ ### Instruction:
28
+ {instruction}
29
+ ### Input:
30
+ {input}
31
+ ### Response:"""
32
+ else:
33
+ return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
34
+ ### Instruction:
35
+ {instruction}
36
+ ### Response:"""
37
+
38
+ def evaluate(
39
+ instruction,
40
+ input=None,
41
+ temperature=0.1,
42
+ top_p=0.75,
43
+ top_k=40,
44
+ num_beams=4,
45
+ max_new_tokens=128,
46
+ **kwargs,
47
+ ):
48
+ prompt = generate_prompt(instruction, input)
49
+ inputs = tokenizer(prompt, return_tensors="pt")
50
+ input_ids = inputs["input_ids"].to(device)
51
+ generation_config = GenerationConfig(
52
+ temperature=temperature,
53
+ top_p=top_p,
54
+ top_k=top_k,
55
+ num_beams=num_beams,
56
+ **kwargs,
57
+ )
58
+ with torch.no_grad():
59
+ generation_output = model.generate(
60
+ input_ids=input_ids,
61
+ generation_config=generation_config,
62
+ return_dict_in_generate=True,
63
+ output_scores=True,
64
+ max_new_tokens=max_new_tokens,
65
+ )
66
+ s = generation_output.sequences[0]
67
+ output = tokenizer.decode(s)
68
+ return output.split("### Response:")[1].strip()
69
+ instruction = 'write your instruction here'
70
+ inputs = 'write your inputs here'
71
+ output= evaluate(instruction,
72
+ input=inputs,
73
+ temperature=0.1,#change the parameters by yourself
74
+ top_p=0.75,
75
+ top_k=40,
76
+ num_beams=4,
77
+ max_new_tokens=128,)
78
+ ```