Update README.md
Browse filesgive an vllm inference example.
README.md
CHANGED
@@ -31,60 +31,47 @@ Reinforcement learning (RL) for large language models is an energy-intensive end
|
|
31 |
|
32 |
## 🚀 Quick Start (Inference)
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
First, install the necessary packages by cloning the repository and installing its dependencies:
|
37 |
```bash
|
38 |
-
|
39 |
-
cd RLEP
|
40 |
-
pip3 install -e .[vllm]
|
41 |
```
|
42 |
-
|
43 |
-
Then, you can use the model in your Python code:
|
44 |
|
45 |
```python
|
46 |
-
import
|
47 |
-
|
48 |
-
from
|
49 |
-
from
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
model = EaModel.from_pretrained(
|
59 |
-
base_model_path=base_model_path,
|
60 |
-
ea_model_path=rlep_model_path,
|
61 |
-
torch_dtype=torch.float16, # or torch.bfloat16 for Qwen2 models
|
62 |
-
low_cpu_mem_usage=True,
|
63 |
-
device_map="auto",
|
64 |
-
total_token=-1 # -1 allows EAGLE-2 to auto-configure this parameter
|
65 |
)
|
66 |
-
model.eval()
|
67 |
|
68 |
-
|
69 |
-
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
input_ids = torch.as_tensor(input_ids).cuda()
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
output = model.tokenizer.decode(output_ids[0])
|
84 |
|
85 |
-
print(output)
|
86 |
```
|
87 |
|
|
|
|
|
88 |
## Evaluation Results
|
89 |
|
90 |
We evaluated the converged RLEP model at 320 training steps and the DAPO-nodyn-bs64 baseline at 400 steps.
|
|
|
31 |
|
32 |
## 🚀 Quick Start (Inference)
|
33 |
|
34 |
+
Here’s a simple example of running inference with vLLM.
|
35 |
+
First, install vLLM (version ≥ 0.7.3):
|
|
|
36 |
```bash
|
37 |
+
pip3 install vllm
|
|
|
|
|
38 |
```
|
39 |
+
After installation, you can load and run the model in your Python code like this:
|
|
|
40 |
|
41 |
```python
|
42 |
+
import os
|
43 |
+
|
44 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
45 |
+
from vllm import LLM, SamplingParams
|
46 |
+
|
47 |
+
model_path = 'Kwai-Klear/qwen2.5-math-rlep'
|
48 |
+
sampling_params = SamplingParams(temperature=1.0, top_p=1.0, max_tokens=1024 * 3, n=1)
|
49 |
+
llm = LLM(
|
50 |
+
model=model_path,
|
51 |
+
enforce_eager=False,
|
52 |
+
tensor_parallel_size=1,
|
53 |
+
seed=0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
)
|
|
|
55 |
|
56 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
57 |
+
question = '''Find the sum of all integer bases $b>9$ for which $17_b$ is a divisor of $97_b.$'''
|
58 |
|
59 |
+
prefix="Solve the following math problem step by step. The last line of your response should be of the form Answer: $Answer (without quotes) where $Answer is the answer to the problem.\n\n"
|
60 |
+
post_fix = '\n\nRemember to put your answer on its own line after "Answer:".'
|
61 |
+
question_with_instruct = prefix + question + post_fix # the model is trained with this instruct.
|
62 |
+
messages = [{'content': question_with_instruct, 'role':'user'}]
|
63 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
64 |
|
65 |
+
output =llm.generate([text], sampling_params)[0]
|
66 |
+
answer = output.outputs[0].text
|
|
|
67 |
|
68 |
+
print(question)
|
69 |
+
print(answer)
|
|
|
70 |
|
|
|
71 |
```
|
72 |
|
73 |
+
To evaluete the model on benchmarks like AIME-2024, AIME-2025 and AMC-2023 etc. please refer to [our repo](http://github.com/Kwai-Klear/RLEP?tab=readme-ov-file#evaluation).
|
74 |
+
|
75 |
## Evaluation Results
|
76 |
|
77 |
We evaluated the converged RLEP model at 320 training steps and the DAPO-nodyn-bs64 baseline at 400 steps.
|