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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
datasets:
|
| 3 |
+
- NeelNanda/pile-10k
|
| 4 |
+
base_model:
|
| 5 |
+
- deepseek-ai/DeepSeek-R1
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
## Model Details
|
| 12 |
+
|
| 13 |
+
This model is an int4 model with group_size 64 and asymmetric quantization of [deepseek-ai/DeepSeek-R1](https://huggingface.co/deepseek-ai/DeepSeek-R1) generated by [intel/auto-round](https://github.com/intel/auto-round) algorithm.
|
| 14 |
+
|
| 15 |
+
Please follow the license of the original model.
|
| 16 |
+
|
| 17 |
+
## How To Use
|
| 18 |
+
|
| 19 |
+
**INT4 VLLM Inference on CUDA**(**at least 8*80G**)
|
| 20 |
+
|
| 21 |
+
To serve using vLLM with 8x 80GB GPUs, use the following command:
|
| 22 |
+
```sh
|
| 23 |
+
VLLM_WORKER_MULTIPROC_METHOD=spawn python -m vllm.entrypoints.openai.api_server --host 0.0.0.0 --port 12345 --max-model-len 65536 --max-num-batched-tokens 65536 --trust-remote-code --tensor-parallel-size 8 --gpu-memory-utilization 0.97 --dtype bfloat16 --served-model-name deepseek-reasoner --model OPEA/DeepSeek-R1-int4-asym-AutoRound-awq
|
| 24 |
+
```
|
| 25 |
+
You can download the wheel I built for PyTorch 2.6, Python 3.12 by clicking [here](https://huggingface.co/x2ray/wheels/resolve/main/vllm-0.7.3.dev187%2Bg0ff1a4df.d20220101.cu126-cp312-cp312-linux_x86_64.whl).
|
| 26 |
+
|
| 27 |
+
~~~python
|
| 28 |
+
import requests
|
| 29 |
+
|
| 30 |
+
url = "http://localhost:12345/v1/completions"
|
| 31 |
+
headers = {"Content-Type": "application/json"}
|
| 32 |
+
data = {
|
| 33 |
+
"model": "deepseek-reasoner",
|
| 34 |
+
"prompt": "请用我给你的4个数字,通过加、减、乘、除、括号,组成一个运算,使得结果为24。注意:数字需要全部使用我提供的数字,4468",
|
| 35 |
+
"max_tokens": 512
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
response = requests.post(url, json=data, headers=headers)
|
| 39 |
+
print(response.json()["choices"][0]["text"])
|
| 40 |
+
|
| 41 |
+
"""
|
| 42 |
+
prompt: 一个汉字具有左右结构,左边是木,右边是乞,这个字是什么字,只需要回答这个字即可。
|
| 43 |
+
|
| 44 |
+
好
|
| 45 |
+
|
| 46 |
+
判断一个字的左右结构中左边是“木”、右边是“乞”的汉字是否存在,需要通过查阅现代汉语词典和汉字结构分析来确认。
|
| 47 |
+
|
| 48 |
+
首先,根据字形结构拆分左边的“木”和右边的“乞”,假设存在这样的组合的话,我们需要确认这个字是否被收录进《现代汉语词典》或《新华字典》中。通过初步检索,例如使用在线字典查询工具,“
|
| 49 |
+
”字旁的字如“杨”、“林”等,但带有“乞”作为右边部分的字较不常见。
|
| 50 |
+
|
| 51 |
+
可能的情形包括:“仡”(yì,左右结构但右边是“乞”,左边是“人”);或者可能存在生僻字或古代变体,但常规现代汉字中可能不存在。也可能存在输入法误录或地方方言中的特殊写法,但标准规范
|
| 52 |
+
字中未必收录。
|
| 53 |
+
|
| 54 |
+
因此,在标准现代汉字中,似乎没有符合左边是“木”,右边是“乞”的汉字。因此可以初步认为这个字并不存在,或者是某种误写、生僻字、异体字未被广泛接受的情况。需要进一步的专业工具或古籍
|
| 55 |
+
献查证是否曾有该字存在。如果按照要求只需要回答这个字,而在不存在的情况下可能需要指出不存在。但按照题目要求可能需要提供一个可能的答案,因此可能需要考虑是不是“杚”(gài,用手取
|
| 56 |
+
的一种动作,但通常右边部分是否“乞”需要核对具体字形差异)。
|
| 57 |
+
--------------------------------------------------
|
| 58 |
+
|
| 59 |
+
prompt: 请用我给你的4个数字,通过加、减、乘、除、括号,组成一个运算,使得结果为24。注意:数字需要全部使用我提供的数字,4468
|
| 60 |
+
|
| 61 |
+
,请用代码解决这个问题。不要依赖其他人的解法,独自思考给出答案。
|
| 62 |
+
|
| 63 |
+
嗯,我现在需要解决这个问题:用数字4、4、6、8,通过加、减、乘、除以及括号,组合成一个表达式,得到结果24。这四个数都必须使用到。我记得怎么解这种24点的问题呢,通常需要尝试不同的
|
| 64 |
+
算组合,然后检查结果是否正确。
|
| 65 |
+
|
| 66 |
+
首先,我会先考虑这四个数是否能直接通过简单的加减乘除组合得到24。比如,先看看是否能将较大的两个数相乘,比如8×6是48,然后看看剩下的两个数如何调整。比如说,48除以(4-4/4),或者
|
| 67 |
+
似的。不过我这个组合并没有用全四个数字,因为用了两个4,可能是不是正确?
|
| 68 |
+
|
| 69 |
+
或者想是否有办法将大的数拆解。比如用乘法将较小的数凑出较大的数。比如,8×(6 - (4/4))。这里用了8×(6 -1)也就是8×5等于40,这不够。
|
| 70 |
+
|
| 71 |
+
另一个可能的尝试是:有没有能把其中一个数除以后再相乘得到大的数。比如,6×8×(4/4)。这样的话,6×8=48,4/4=1,48×1=48,不对。或者,6×(8×(4/4))同样不行。
|
| 72 |
+
|
| 73 |
+
再试试用减法。比如,8×4 - 6×4,这样的话,得到的是32-24=8,也不对。
|
| 74 |
+
|
| 75 |
+
那可能需要混合运算,例如用加法和乘法共同作用。例如,(4×4)+ 8 +6= 16+8+6=30,不够24。那这样的话可能并不合适。
|
| 76 |
+
|
| 77 |
+
或者试着用括号,组合运算顺序。比如,先处理4和4,比如4+4=8,那么我们有8、6、8。然后这三个数如何组合?8×(6×(8/(8))?), 这样反而有点像复杂的步骤,似乎难��得出24。
|
| 78 |
+
|
| 79 |
+
换一种思路,可能可以使用分数或者除法。比如,6 ÷ ( (4/4) ) × 8?4除以4等于1,6除以1等于6,再乘以8得到48,不够。
|
| 80 |
+
|
| 81 |
+
或者(8 - (6/4)) ×4?计算的话,先做6/4=1.5,那么8-1.5=6.5,6.5×4=26,还不够。
|
| 82 |
+
|
| 83 |
+
或者考虑减法结合乘法,比如,(8 -4) ×6 + 4×0?这显然不行
|
| 84 |
+
--------------------------------------------------
|
| 85 |
+
|
| 86 |
+
prompt: How should I explain the Internet?
|
| 87 |
+
|
| 88 |
+
The most common association people have with the Internet is a quick email reply or a Google search. The Internet was once new and now it is completely normal and in some cases even taken for granted. Therefore, before covering how one can demystify this complex computer network, first let me answer a basic starting question: what exactly is the Internet?
|
| 89 |
+
|
| 90 |
+
The Internet is a global network of interconnected computers that communicate through standard protocols. These protocols, such as TCP/IP, are sets of rules that allow devices to exchange data. Think of the Internet as a vast system of roads and highways where information travels instead of cars. Each device, like a computer or smartphone, is like a vehicle that can navigate this network to access websites, send emails, or stream videos. The information is broken into packets, which are like individual carriages on a train, each carrying a piece of data. Routers and servers act as traffic controllers, directing these packets to their destinations efficiently. While the infrastructure is highly technical, the Internet’s purpose is to facilitate communication and information sharing on an unprecedented scale. Its architecture is designed for redundancy and resilience, ensuring that even if parts of the network fail, the rest can continue operating.
|
| 91 |
+
|
| 92 |
+
Now that we have a basic understanding of the Internet, let's explore how to explain its components, structure, and functionality in a comprehensible way.
|
| 93 |
+
|
| 94 |
+
## Key Components of the Internet
|
| 95 |
+
|
| 96 |
+
### 1. Devices and Endpoints
|
| 97 |
+
|
| 98 |
+
At the most basic level, the Internet consists of devices like computers, smartphones, and servers. These are the entry and exit points where data originates or is consumed.
|
| 99 |
+
|
| 100 |
+
### 2. Internet Service Providers (ISPs)
|
| 101 |
+
|
| 102 |
+
ISPs are the companies that provide access to the Internet. They maintain the infrastructure, such as fiber-optic cables, that connects individual devices to the broader network.
|
| 103 |
+
|
| 104 |
+
### 3. Data Centers and Servers
|
| 105 |
+
|
| 106 |
+
Servers store the data that makes up websites, apps, and services. Data centers are facilities housing numerous servers, often managed by companies like Google, Amazon, or Microsoft.
|
| 107 |
+
|
| 108 |
+
### 4. Protocols
|
| 109 |
+
|
| 110 |
+
Protocols like TCP/IP (Transmission Control Protocol/Internet Protocol) are the rules governing how data is sent and received. They ensure that different devices can communicate effectively.
|
| 111 |
+
|
| 112 |
+
## Structure of the Internet
|
| 113 |
+
|
| 114 |
+
### 1. Physical Infrastructure
|
| 115 |
+
|
| 116 |
+
The Internet isn't just an abstract concept; it has a physical presence. This includes undersea cables, satellites, routers, and data centers spread across the globe.
|
| 117 |
+
|
| 118 |
+
### 2. IP Addresses
|
| 119 |
+
|
| 120 |
+
Every device connected to the Internet has a
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
"""
|
| 124 |
+
~~~
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
### INT4 Inference on CPU
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
Requirements
|
| 131 |
+
|
| 132 |
+
~~~bash
|
| 133 |
+
pip install auto-round
|
| 134 |
+
pip uninstall intel-extension-for-pytorch
|
| 135 |
+
pip install intel-extension-for-transformers
|
| 136 |
+
~~~
|
| 137 |
+
|
| 138 |
+
will update later
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
### Evaluate the model
|
| 144 |
+
pip3 install lm-eval==0.4.8
|
| 145 |
+
|
| 146 |
+
```bash
|
| 147 |
+
lm-eval --model hf --model_args pretrained=OPEA/DeepSeek-R1-int4-asym-AutoRound-awq --tasks lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,boolq,arc_easy,arc_challenge,mmlu --batch_size 16
|
| 148 |
+
```
|
| 149 |
+
| Metric | FP8 | INT4(BF16) |
|
| 150 |
+
| :------------------------ | :---------------------- | :--------------- |
|
| 151 |
+
| avg | 0.6954 | 0.6963 |
|
| 152 |
+
| mmlu | 0.8514 | 0.8485 |
|
| 153 |
+
| lambada_openai | 0.7902 | 0.7809 |
|
| 154 |
+
| hellaswag | 0.6935 | 0.6883 |
|
| 155 |
+
| winogrande | 0.7932 | 0.8011 |
|
| 156 |
+
| piqa | 0.8308 | 0.8292 |
|
| 157 |
+
| truthfulqa_mc1 | 0.4064 | 0.4051 |
|
| 158 |
+
| openbookqa | 0.3780 | 0.394 |
|
| 159 |
+
| boolq | 0.8856 | 0.8813 |
|
| 160 |
+
| arc_easy | 0.8598 | 0.8594 |
|
| 161 |
+
| arc_challenge | 0.6212 | 0.6271 |
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
### Generate the model
|
| 166 |
+
|
| 167 |
+
**1 add meta data to bf16 model** https://huggingface.co/opensourcerelease/DeepSeek-R1-bf16
|
| 168 |
+
|
| 169 |
+
~~~python
|
| 170 |
+
import safetensors
|
| 171 |
+
from safetensors.torch import save_file
|
| 172 |
+
|
| 173 |
+
for i in range(1, 164):
|
| 174 |
+
idx_str = "0" * (5-len(str(i))) + str(i)
|
| 175 |
+
safetensors_path = f"model-{idx_str}-of-000163.safetensors"
|
| 176 |
+
print(safetensors_path)
|
| 177 |
+
tensors = dict()
|
| 178 |
+
with safetensors.safe_open(safetensors_path, framework="pt") as f:
|
| 179 |
+
for key in f.keys():
|
| 180 |
+
tensors[key] = f.get_tensor(key)
|
| 181 |
+
save_file(tensors, safetensors_path, metadata={'format': 'pt'})
|
| 182 |
+
~~~
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
**2 remove torch.no_grad** in modeling_deepseek.py as we need some tuning in AutoRound.
|
| 187 |
+
|
| 188 |
+
~~~python
|
| 189 |
+
import torch
|
| 190 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 191 |
+
import transformers
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
# https://github.com/huggingface/transformers/pull/35493
|
| 195 |
+
def set_initialized_submodules(model, state_dict_keys):
|
| 196 |
+
"""
|
| 197 |
+
Sets the `_is_hf_initialized` flag in all submodules of a given model when all its weights are in the loaded state
|
| 198 |
+
dict.
|
| 199 |
+
"""
|
| 200 |
+
state_dict_keys = set(state_dict_keys)
|
| 201 |
+
not_initialized_submodules = {}
|
| 202 |
+
for module_name, module in model.named_modules():
|
| 203 |
+
if module_name == "":
|
| 204 |
+
# When checking if the root module is loaded there's no need to prepend module_name.
|
| 205 |
+
module_keys = set(module.state_dict())
|
| 206 |
+
else:
|
| 207 |
+
module_keys = {f"{module_name}.{k}" for k in module.state_dict()}
|
| 208 |
+
if module_keys.issubset(state_dict_keys):
|
| 209 |
+
module._is_hf_initialized = True
|
| 210 |
+
else:
|
| 211 |
+
not_initialized_submodules[module_name] = module
|
| 212 |
+
return not_initialized_submodules
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
transformers.modeling_utils.set_initialized_submodules = set_initialized_submodules
|
| 216 |
+
|
| 217 |
+
model_name = "opensourcerelease/DeepSeek-R1-bf16"
|
| 218 |
+
|
| 219 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 220 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, torch_dtype="auto")
|
| 221 |
+
|
| 222 |
+
block = model.model.layers
|
| 223 |
+
device_map = {}
|
| 224 |
+
|
| 225 |
+
for n, m in block.named_modules():
|
| 226 |
+
if isinstance(m, (torch.nn.Linear, transformers.modeling_utils.Conv1D)):
|
| 227 |
+
if "experts" in n and ("shared_experts" not in n) and int(n.split('.')[-2]) < 63:
|
| 228 |
+
device = "cuda:1"
|
| 229 |
+
elif "experts" in n and ("shared_experts" not in n) and int(n.split('.')[-2]) >= 63 and int(
|
| 230 |
+
n.split('.')[-2]) < 128:
|
| 231 |
+
device = "cuda:2"
|
| 232 |
+
elif "experts" in n and ("shared_experts" not in n) and int(n.split('.')[-2]) >= 128 and int(
|
| 233 |
+
n.split('.')[-2]) < 192:
|
| 234 |
+
device = "cuda:3"
|
| 235 |
+
elif "experts" in n and ("shared_experts" not in n) and int(
|
| 236 |
+
n.split('.')[-2]) >= 192:
|
| 237 |
+
device = "cuda:4"
|
| 238 |
+
else:
|
| 239 |
+
device = "cuda:0"
|
| 240 |
+
n = n[2:]
|
| 241 |
+
|
| 242 |
+
device_map.update({n: device})
|
| 243 |
+
|
| 244 |
+
from auto_round import AutoRound
|
| 245 |
+
|
| 246 |
+
autoround = AutoRound(model=model, tokenizer=tokenizer, device_map=device_map, nsamples=512,
|
| 247 |
+
batch_size=4, low_gpu_mem_usage=True, seqlen=2048, group_size=64, sym=False
|
| 248 |
+
)
|
| 249 |
+
autoround.quantize()
|
| 250 |
+
autoround.save_quantized(format="auto_awq", output_dir="tmp_autoround")
|
| 251 |
+
|
| 252 |
+
~~~
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
## Ethical Considerations and Limitations
|
| 259 |
+
|
| 260 |
+
The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
|
| 261 |
+
|
| 262 |
+
Therefore, before deploying any applications of the model, developers should perform safety testing.
|
| 263 |
+
|
| 264 |
+
## Caveats and Recommendations
|
| 265 |
+
|
| 266 |
+
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
|
| 267 |
+
|
| 268 |
+
Here are a couple of useful links to learn more about Intel's AI software:
|
| 269 |
+
|
| 270 |
+
- Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
|
| 271 |
+
|
| 272 |
+
## Disclaimer
|
| 273 |
+
|
| 274 |
+
The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
|
| 275 |
+
|
| 276 |
+
## Cite
|
| 277 |
+
|
| 278 |
+
@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }
|
| 279 |
+
|
| 280 |
+
[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)
|