Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,101 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
---
|
4 |
+
license: cc-by-nc-sa-4.0
|
5 |
+
language:
|
6 |
+
- en
|
7 |
+
- zh
|
8 |
+
base_model:
|
9 |
+
- Qwen/Qwen2.5-7B-Instruct
|
10 |
+
tags:
|
11 |
+
- machine tranlsation
|
12 |
+
- O1-like model
|
13 |
+
- Chat
|
14 |
+
pipeline_tag: text-generation
|
15 |
+
---
|
16 |
+
|
17 |
+
# DeepTrans-7B
|
18 |
+
|
19 |
+
|
20 |
+
## Quickstart
|
21 |
+
- ⛷️ Huggingface Transformers:
|
22 |
+
|
23 |
+
```python
|
24 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
25 |
+
|
26 |
+
model_name = "Krystalan/DeepTrans-7B"
|
27 |
+
|
28 |
+
model = AutoModelForCausalLM.from_pretrained(
|
29 |
+
model_name,
|
30 |
+
torch_dtype="auto",
|
31 |
+
device_map="auto"
|
32 |
+
)
|
33 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
34 |
+
|
35 |
+
prompt = "你是一个翻译专家,擅长将英文翻译成中文。你在翻译过程中非常擅长思考,会先进行思考再给出翻译结果。你的输出格式为:\n<think>\n[思考过程]\n</think>[翻译结果]\n\n在你思考完之后,也就是</think>之后,你会给出最终的翻译即“[翻译结果]”,且[翻译结果]中不需要给出任何解释和描述,只需要提供英文的翻译结果。\n现在请你翻译以下这句英语:\n" + "The mother, with her feet propped up on a stool, seemed to be trying to get to the bottom of that answer, whose feminine profundity had struck her all of a heap."
|
36 |
+
|
37 |
+
messages = [
|
38 |
+
{"role": "user", "content": prompt}
|
39 |
+
]
|
40 |
+
text = tokenizer.apply_chat_template(
|
41 |
+
messages,
|
42 |
+
tokenize=False,
|
43 |
+
add_generation_prompt=True
|
44 |
+
)
|
45 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
46 |
+
|
47 |
+
generated_ids = model.generate(
|
48 |
+
**model_inputs,
|
49 |
+
max_new_tokens=2048
|
50 |
+
)
|
51 |
+
generated_ids = [
|
52 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
53 |
+
]
|
54 |
+
|
55 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
56 |
+
print(response)
|
57 |
+
```
|
58 |
+
|
59 |
+
- ⛷️ vllm:
|
60 |
+
|
61 |
+
Deploying LLMs:
|
62 |
+
```bash
|
63 |
+
python3 -m vllm.entrypoints.openai.api_server --model [model_ckpt] --served-model-name [model_name]
|
64 |
+
```
|
65 |
+
|
66 |
+
Calling LLMs:
|
67 |
+
```python
|
68 |
+
from openai import OpenAI
|
69 |
+
# Set OpenAI's API key and API base to use vLLM's API server.
|
70 |
+
openai_api_key = "EMPTY"
|
71 |
+
openai_api_base = "http://localhost:8000/v1"
|
72 |
+
|
73 |
+
client = OpenAI(
|
74 |
+
api_key=openai_api_key,
|
75 |
+
base_url=openai_api_base,
|
76 |
+
)
|
77 |
+
|
78 |
+
prompt = "你是一个翻译专家,擅长将英文翻译成中文。你在翻译过程中非常擅长思考,会先进行思考再给出翻译结果。你的输出格式为:\n<think>\n[思考过程]\n</think>[翻译结果]\n\n在你思考完之后,也就是</think>之后,你会给出最终的翻译即“[翻译结果]”,且[翻译结果]中不需要给出任何解释和描述,只需要提供英文的翻译结果。\n现在请你翻译以下这句英语:\n" + "The mother, with her feet propped up on a stool, seemed to be trying to get to the bottom of that answer, whose feminine profundity had struck her all of a heap."
|
79 |
+
|
80 |
+
chat_response = client.chat.completions.create(
|
81 |
+
model=[model_name],
|
82 |
+
messages=[
|
83 |
+
{"role": "user", "content": prompt},
|
84 |
+
],
|
85 |
+
temperature=0.1,
|
86 |
+
top_p=0.8,
|
87 |
+
max_tokens=2048,
|
88 |
+
extra_body={
|
89 |
+
"repetition_penalty": 1.05,
|
90 |
+
},
|
91 |
+
)
|
92 |
+
print("Chat response:", chat_response)
|
93 |
+
```
|
94 |
+
|
95 |
+
|
96 |
+
|
97 |
+
## License
|
98 |
+
This work is licensed under cc-by-nc-sa-4.0
|
99 |
+
|
100 |
+
|
101 |
+
|