Views
No views yet
| Metric | DeepSeek-V2-0628 | DeepSeek-Coder-V2-0724 | DeepSeek-V2.5 |
|---|---|---|---|
| AlpacaEval 2.0 | 46.6 | 44.5 | 50.5 |
| ArenaHard | 68.3 | 66.3 | 76.2 |
| AlignBench | 7.88 | 7.91 | 8.04 |
| MT-Bench | 8.85 | 8.91 | 9.02 |
| HumanEval python | 84.5 | 87.2 | 89 |
| HumanEval Multi | 73.8 | 74.8 | 73.8 |
| LiveCodeBench(01-09) | 36.6 | 39.7 | 41.8 |
| Aider | 69.9 | 72.9 | 72.2 |
| SWE-verified | N/A | 19 | 16.8 |
| DS-FIM-Eval | N/A | 73.2 | 78.3 |
| DS-Arena-Code | N/A | 49.5 | 63.1 |
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
3
4model_name = "deepseek-ai/DeepSeek-V2.5"
5tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
6# `max_memory` should be set based on your devices
7max_memory = {i: "75GB" for i in range(8)}
8# `device_map` cannot be set to `auto`
9model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, device_map="sequential", torch_dtype=torch.bfloat16, max_memory=max_memory, attn_implementation="eager")
10model.generation_config = GenerationConfig.from_pretrained(model_name)
11model.generation_config.pad_token_id = model.generation_config.eos_token_id
12
13messages = [
14 {"role": "user", "content": "Write a piece of quicksort code in C++"}
15]
16input_tensor = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
17outputs = model.generate(input_tensor.to(model.device), max_new_tokens=100)
18
19result = tokenizer.decode(outputs[0][input_tensor.shape[1]:], skip_special_tokens=True)
20print(result)tokenizer_config.json located in the huggingface model repository.<|begin▁of▁sentence|><|User|>{user_message_1}<|Assistant|>{assistant_message_1}<|end▁of▁sentence|><|User|>{user_message_2}<|Assistant|><|begin▁of▁sentence|>{system_message}<|User|>{user_message_1}<|Assistant|>{assistant_message_1}<|end▁of▁sentence|><|User|>{user_message_2}<|Assistant|>1from transformers import AutoTokenizer
2from vllm import LLM, SamplingParams
3
4max_model_len, tp_size = 8192, 8
5model_name = "deepseek-ai/DeepSeek-V2.5"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7llm = LLM(model=model_name, tensor_parallel_size=tp_size, max_model_len=max_model_len, trust_remote_code=True, enforce_eager=True)
8sampling_params = SamplingParams(temperature=0.3, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
9
10messages_list = [
11 [{"role": "user", "content": "Who are you?"}],
12 [{"role": "user", "content": "Translate the following content into Chinese directly: DeepSeek-V2 adopts innovative architectures to guarantee economical training and efficient inference."}],
13 [{"role": "user", "content": "Write a piece of quicksort code in C++."}],
14]
15
16prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
17
18outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
19
20generated_text = [output.outputs[0].text for output in outputs]
21print(generated_text)1# Assume that `model` and `tokenizer` are loaded
2model.generation_config = GenerationConfig(do_sample=False, max_new_tokens=128, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.eos_token_id)
3
4tool_system_prompt = """You are a helpful Assistant.
5
6## Tools
7
8### Function
9
10You have the following functions available:
11
12- `get_current_weather`:
13```json
14{
15 "name": "get_current_weather",
16 "description": "Get the current weather in a given location",
17 "parameters": {
18 "type": "object",
19 "properties": {
20 "location": {
21 "type": "string",
22 "description": "The city and state, e.g. San Francisco, CA"
23 },
24 "unit": {
25 "type": "string",
26 "enum": [
27 "celsius",
28 "fahrenheit"
29 ]
30 }
31 },
32 "required": [
33 "location"
34 ]
35 }
36}
37```"""
38
39tool_call_messages = [{"role": "system", "content": tool_system_prompt}, {"role": "user", "content": "What's the weather like in Tokyo and Paris?"}]
40tool_call_inputs = tokenizer.apply_chat_template(tool_call_messages, add_generation_prompt=True, return_tensors="pt")
41tool_call_outputs = model.generate(tool_call_inputs.to(model.device))
42# Generated text: '<|tool▁calls▁begin|><|tool▁call▁begin|>function<|tool▁sep|>get_current_weather\n```json\n{"location": "Tokyo"}\n```<|tool▁call▁end|>\n<|tool▁call▁begin|>function<|tool▁sep|>get_current_weather\n```json\n{"location": "Paris"}\n```<|tool▁call▁end|><|tool▁calls▁end|><|end▁of▁sentence|>'
43
44# Mock response of calling `get_current_weather`
45tool_messages = [{"role": "tool", "content": '{"location": "Tokyo", "temperature": "10", "unit": null}'}, {"role": "tool", "content": '{"location": "Paris", "temperature": "22", "unit": null}'}]
46tool_inputs = tokenizer.apply_chat_template(tool_messages, add_generation_prompt=False, return_tensors="pt")[:, 1:]
47tool_inputs = torch.cat([tool_call_outputs, tool_inputs.to(model.device)], dim=1)
48tool_outputs = model.generate(tool_inputs)
49# Generated text: The current weather in Tokyo is 10 degrees, and in Paris, it is 22 degrees.<|end▁of▁sentence|>1# Assume that `model` and `tokenizer` are loaded
2model.generation_config = GenerationConfig(do_sample=False, max_new_tokens=128, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.eos_token_id)
3
4user_system_prompt = 'The user will provide some exam text. Please parse the "question" and "answer" and output them in JSON format.'
5json_system_prompt = f"""{user_system_prompt}
6
7## Response Format
8
9Reply with JSON object ONLY."""
10
11json_messages = [{"role": "system", "content": json_system_prompt}, {"role": "user", "content": "Which is the highest mountain in the world? Mount Everest."}]
12json_inputs = tokenizer.apply_chat_template(json_messages, add_generation_prompt=True, return_tensors="pt")
13json_outpus = model.generate(json_inputs.to(model.device))
14# Generated text: '```json\n{\n "question": "Which is the highest mountain in the world?",\n "answer": "Mount Everest."\n}\n```<|end▁of▁sentence|>'1# Assume that `model` and `tokenizer` are loaded
2model.generation_config = GenerationConfig(do_sample=False, max_new_tokens=128, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.eos_token_id)
3
4prefix = """def quick_sort(arr):
5 if len(arr) <= 1:
6 return arr
7 pivot = arr[0]
8 left = []
9 right = []
10"""
11
12suffix = """
13 if arr[i] < pivot:
14 left.append(arr[i])
15 else:
16 right.append(arr[i])
17 return quick_sort(left) + [pivot] + quick_sort(right)"""
18
19fim_prompt = f"<|fim▁begin|>{prefix}<|fim▁hole|>{suffix}<|fim▁end|>"
20fim_inputs = tokenizer(fim_prompt, add_special_tokens=True, return_tensors="pt").input_ids
21fim_outputs = model.generate(fim_inputs.to(model.device))
22# Generated text: " for i in range(1, len(arr)):<|end▁of▁sentence|>"@misc{deepseekv2,
title={DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model},
author={DeepSeek-AI},
year={2024},
eprint={2405.04434},
archivePrefix={arXiv},
primaryClass={cs.CL}
}