buyi89 commited on
Commit
a246edd
1 Parent(s): 666eecc

add Demo usage

Browse files
Files changed (1) hide show
  1. README.md +32 -1
README.md CHANGED
@@ -9,7 +9,6 @@ metrics:
9
  library_name: transformers
10
  pipeline_tag: text-generation
11
  ---
12
-
13
  <p align="center"><h2 align="center">Unleashing Reasoning Capability of LLMs via Scalable Question Synthesis from Scratch</h2></p>
14
 
15
  # Model Card for Qwen2-Math-7B-ScaleQuest
@@ -46,6 +45,38 @@ We release two question generator models and four problem-solving models.
46
 
47
  Below is an example using `Qwen2-Math-7B-ScaleQuest`
48
  ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  ```
50
 
51
  ## Citation
 
9
  library_name: transformers
10
  pipeline_tag: text-generation
11
  ---
 
12
  <p align="center"><h2 align="center">Unleashing Reasoning Capability of LLMs via Scalable Question Synthesis from Scratch</h2></p>
13
 
14
  # Model Card for Qwen2-Math-7B-ScaleQuest
 
45
 
46
  Below is an example using `Qwen2-Math-7B-ScaleQuest`
47
  ```python
48
+ import torch
49
+ from transformers import AutoModelForCausalLM, AutoTokenizer
50
+
51
+ model_name = "dyyyyyyyy/Qwen2-Math-7B-ScaleQuest"
52
+
53
+ model = AutoModelForCausalLM.from_pretrained(
54
+ model_name,
55
+ torch_dtype=torch.bfloat16,
56
+ device_map="auto"
57
+ )
58
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
59
+
60
+ question = "Find the value of $x$ that satisfies the equation $4x+5 = 6x+7$."
61
+
62
+ sys_prompt="<|im_start|>system\nPlease reason step by step, and put your final answer within \\boxed{{}}.<|im_end|>\n"
63
+ query_prompt="<|im_start|>user" + "\n"
64
+ # {query}
65
+ prompt_after_query="<|im_end|>" + "\n"
66
+ resp_prompt="<|im_start|>assistant" + "\n"
67
+ prompt_before_resp=""
68
+ # {resp}
69
+ delim="<|im_end|>" + "\n"
70
+
71
+ prefix_prompt = f"{query_prompt}{question}{prompt_after_query}{resp_prompt}{prompt_before_resp}".rstrip(" ")
72
+ full_prompt = sys_prompt + delim.join([prefix_prompt])
73
+
74
+ # print(full_prompt)
75
+
76
+ inputs = tokenizer(full_prompt, return_tensors="pt").to(model.device)
77
+ outputs = model.generate(**inputs, max_new_tokens=512, do_sample=False)
78
+ print(tokenizer.decode(outputs[0][len(inputs.input_ids[0]):], skip_special_tokens=True))
79
+
80
  ```
81
 
82
  ## Citation