DeepSeek模型量化
技术背景
大语言模型(Large Language Model,LLM),可以通过量化(Quantization)操作来节约内存/显存的使用,并且降低了通讯开销,进而达到加速模型推理的效果。常见的就是把Float16的浮点数,转换成低精度的整数,例如Int4整数。最极限的情况下,可以把参数转化成二值Bool变量,也就是只有0和1,但是这种大幅度的量化有可能导致模型的推理效果不佳。常用的是,在70B以下的模型用Q8,70B以上可以用Q4。具体的原理,包括对称量化和非对称量化等,这里就不作介绍了,主要看看工程上怎么实现,主要使用了llama.cpp
来完成量化。
安装llama.cpp
这里我们在Ubuntu上使用本地编译构建的方法进行安装,首先从github上面clone下来:
$ git clone https://github.com/ggerganov/llama.cpp.git
正克隆到 'llama.cpp'...
remote: Enumerating objects: 43657, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 43657 (delta 3), reused 5 (delta 1), pack-reused 43642 (from 3)
接收对象中: 100% (43657/43657), 88.26 MiB | 8.30 MiB/s, 完成.
处理 delta 中: 100% (31409/31409), 完成.
最好创建一个虚拟环境,以避免各种软件依赖的问题,推荐Python3.10:
# 创建虚拟环境
$ conda create -n llama python=3.10
# 激活虚拟环境
$ conda activate llama
进入下载好的llama.cpp路径,安装所有的依赖项:
$ cd llama.cpp/
$ python3 -m pip install -e .
创建一个编译目录,执行编译指令:
$ mkdir build
$ cd build/
$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /usr/bin/git (found version "2.25.1")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Warning: ccache not found - consider installing it for faster compilation or disable this warning with GGML_CCACHE=OFF
-- CMAKE_SYSTEM_PROCESSOR: x86_64
-- Including CPU backend
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- x86 detected
-- Adding CPU backend variant ggml-cpu: -march=native
-- Configuring done
-- Generating done
-- Build files have been written to: /datb/DeepSeek/llama/llama.cpp/build
$ cmake --build . --config Release
Scanning dependencies of target ggml-base
[ 0%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml.c.o
[ 1%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml-alloc.c.o
[100%] Linking CXX executable ../../bin/llama-vdot
[100%] Built target llama-vdot
到这里,就成功构建了cpu版本的llama.cpp,可以直接使用了。如果需要安装gpu加速的版本,可以参考下面这一小节,如果嫌麻烦建议直接跳过。
llama.cpp之CUDA加速
安装GPU版本llama.cpp需要先安装一些依赖:
$ sudo apt install curl libcurl4-openssl-dev
跟cpu版本不同的地方,主要在于cmake的编译指令(如果已经编译了cpu的版本,最好先清空build
路径下的文件):
$ cmake .. -DCMAKE_CUDA_COMPILER=/usr/bin/nvcc -DGGML_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DLLAMA_CURL=ON -DCMAKE_CUDA_STANDARD=17
这里加的一个FLAG:-DCMAKE_CUDA_STANDARD=17
可以解决Llama.cpp仓库里面的Issue,如果不加这个Flag,有可能出现下面这种报错:
Make Error in ggml/src/ggml-cuda/CMakeLists.txt:Target "ggml-cuda" requires the language dialect "CUDA17" (with compilerextensions), but CMake does not know the compile flags to use to enable it.
如果顺利的话,执行下面这个指令,成功编译通过的话就是成功了:
$ cmake --build . --config Release
但是如果像我这样有报错信息,那就得单独处理以下。
/datb/DeepSeek/llama/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h:6:10: fatal error: cuda_bf16.h: 没有那个文件或目录#include <cuda_bf16.h>^~~~~~~~~~~~~
compilation terminated.
这个报错是说找不到头文件,于是在环境里面find / -name cuda_bf16.h
了一下,发现其实是有这个头文件的:
/home/dechin/anaconda3/envs/llama/lib/python3.10/site-packages/nvidia/cuda_runtime/include/cuda_bf16.h
/home/dechin/anaconda3/envs/llama/lib/python3.10/site-packages/triton/backends/nvidia/include/cuda_bf16.h
处理方式是把这个路径加到CPATH
里面:
$ export CPATH=$CPATH:/home/dechin/anaconda3/envs/llama/lib/python3.10/site-packages/nvidia/cuda_runtime/include/
如果是出现这个报错:
/home/dechin/anaconda3/envs/llama/lib/python3.10/site-packages/nvidia/cuda_runtime/include/cuda_fp16.h:4100:10: fatal error: nv/target: 没有那个文件或目录#include <nv/target>^~~~~~~~~~~
compilation terminated.
那就是找不到target目录的路径,如果本地有target路径的话,也可以直接配置到CPATH
里面:
$ export CPATH=/home/dechin/anaconda3/pkgs/cupy-core-13.3.0-py310h5da974a_2/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/:$CPATH
如果是下面这些报错:
/datb/DeepSeek/llama/llama.cpp/ggml/src/ggml-cuda/common.cuh(138): error: identifier "cublasGetStatusString" is undefined/datb/DeepSeek/llama/llama.cpp/ggml/src/ggml-cuda/common.cuh(417): error: A __device__ variable cannot be marked constexpr/datb/DeepSeek/llama/llama.cpp/ggml/src/ggml-cuda/common.cuh(745): error: identifier "CUBLAS_TF32_TENSOR_OP_MATH" is undefined3 errors detected in the compilation of "/tmp/tmpxft_000a126f_00000000-9_acc.compute_75.cpp1.ii".
make[2]: *** [ggml/src/ggml-cuda/CMakeFiles/ggml-cuda.dir/build.make:82:ggml/src/ggml-cuda/CMakeFiles/ggml-cuda.dir/acc.cu.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:1964:ggml/src/ggml-cuda/CMakeFiles/ggml-cuda.dir/all] 错误 2
make: *** [Makefile:160:all] 错误 2
那么很有可能是cuda-toolkit
的版本问题,尝试安装cuda-12:
$ conda install nvidia::cuda-toolkit
如果使用conda安装过程有这种问题:
Collecting package metadata (current_repodata.json): failed# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<Traceback (most recent call last):File "/home/dechin/anaconda3/lib/python3.8/site-packages/conda/gateways/repodata/__init__.py", line 132, in conda_http_errorsyieldFile "/home/dechin/anaconda3/lib/python3.8/site-packages/conda/gateways/repodata/__init__.py", line 101, in repodataresponse.raise_for_status()File "/home/dechin/anaconda3/lib/python3.8/site-packages/requests/models.py", line 1024, in raise_for_statusraise HTTPError(http_error_msg, response=self)requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://conda.anaconda.org/defaults/linux-64/current_repodata.json
那应该是conda源的问题,可以删掉旧的channels,使用默认channels或者找一个国内可以用的镜像源进行配置:
$ conda config --remove-key channels
$ conda config --remove-key default_channels
$ conda config --append channels conda-forge
重新安装以后,nvcc的路径发生了变化,要注意修改下编译时的DCMAKE_CUDA_COMPILER
参数配置:
$ cmake .. -DCMAKE_CUDA_COMPILER=/home/dechin/anaconda3/envs/llama/bin/nvcc -DGGML_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DLLAMA_CURL=ON -DCMAKE_CUDA_STANDARD=17
如果出现如下报错:
-- Unable to find cuda_runtime.h in "/home/dechin/anaconda3/envs/llama/include" for CUDAToolkit_INCLUDE_DIR.
-- Could NOT find CUDAToolkit (missing: CUDAToolkit_INCLUDE_DIR)
CMake Error at ggml/src/ggml-cuda/CMakeLists.txt:151 (message):CUDA Toolkit not found-- Configuring incomplete, errors occurred!
See also "/datb/DeepSeek/llama/llama.cpp/build/CMakeFiles/CMakeOutput.log".
See also "/datb/DeepSeek/llama/llama.cpp/build/CMakeFiles/CMakeError.log".
这是找不到CUDAToolkit_INCLUDE_DIR
的路径配置,只要在cmake的指令里面加上一个include路径即可:
$ cmake .. -DCMAKE_CUDA_COMPILER=/home/dechin/anaconda3/envs/llama/bin/nvcc -DGGML_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DLLAMA_CURL=ON -DCMAKE_CUDA_STANDARD=17 -DCUDAToolkit_INCLUDE_DIR=/home/dechin/anaconda3/envs/llama/targets/x86_64-linux/include/ -DCURL_LIBRARY=/usr/lib/x86_64-linux-gnu/
如果经过以上的一串处理,依然有报错信息,那我建议还是用个Docker吧,或者直接用CPU版本执行quantize,模型调用使用Ollama,这样方便一些。
下载Hugging Face模型
由于很多已经完成量化的GGUF模型文件,无法被二次量化,所以建议直接从Hugging Face下载safetensors模型文件。然后用llama.cpp里面的一个Python脚本将hf模型转为gguf模型,然后再使用llama.cpp进行模型quantize。
关于模型下载这部分,因为Hugging Face的访问有时候也会受限,所以这里首推的还是国内的ModelScope平台。从ModelScope平台下载模型,可以装一个这种Python形式的modelscope:
$ python3 -m pip install modelscope
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: modelscope in /home/dechin/anaconda3/lib/python3.8/site-packages (1.22.3)
Requirement already satisfied: requests>=2.25 in /home/dechin/.local/lib/python3.8/site-packages (from modelscope) (2.25.1)
Requirement already satisfied: urllib3>=1.26 in /home/dechin/.local/lib/python3.8/site-packages (from modelscope) (1.26.5)
Requirement already satisfied: tqdm>=4.64.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from modelscope) (4.67.1)
Requirement already satisfied: certifi>=2017.4.17 in /home/dechin/.local/lib/python3.8/site-packages (from requests>=2.25->modelscope) (2021.5.30)
Requirement already satisfied: chardet<5,>=3.0.2 in /home/dechin/.local/lib/python3.8/site-packages (from requests>=2.25->modelscope) (4.0.0)
Requirement already satisfied: idna<3,>=2.5 in /home/dechin/.local/lib/python3.8/site-packages (from requests>=2.25->modelscope) (2.10)
然后使用modelcope下载模型:
$ modelscope download --model deepseek-ai/DeepSeek-R1-Distill-Qwen-32B
如果出现报错(如果没有报错就不用理会,等待模型下载完成即可):
safetensors integrity check failed, expected sha256 signature is xxx
可以尝试另一种安装方式:
$ sudo apt install git-lfs
下载模型:
$ git clone https://www.modelscope.cn/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B.git
正克隆到 'DeepSeek-R1-Distill-Qwen-32B'...
remote: Enumerating objects: 52, done.
remote: Counting objects: 100% (52/52), done.
remote: Compressing objects: 100% (37/37), done.
remote: Total 52 (delta 17), reused 42 (delta 13), pack-reused 0
展开对象中: 100% (52/52), 2.27 MiB | 2.62 MiB/s, 完成.
过滤内容: 100% (8/8), 5.02 GiB | 912.00 KiB/s, 完成.
Encountered 8 file(s) that may not have been copied correctly on Windows:model-00005-of-000008.safetensorsmodel-00004-of-000008.safetensorsmodel-00008-of-000008.safetensorsmodel-00002-of-000008.safetensorsmodel-00007-of-000008.safetensorsmodel-00003-of-000008.safetensorsmodel-00006-of-000008.safetensorsmodel-00001-of-000008.safetensorsSee: `git lfs help smudge` for more details.
这个过程会消耗很多时间,请耐心等待模型下载完成为止。下载完成后查看路径:
$ cd DeepSeek-R1-Distill-Qwen-32B/
$ ll
总用量 63999072
drwxrwxr-x 4 dechin dechin 4096 2月 12 19:22 ./
drwxrwxr-x 3 dechin dechin 4096 2月 12 17:46 ../
-rw-rw-r-- 1 dechin dechin 664 2月 12 17:46 config.json
-rw-rw-r-- 1 dechin dechin 73 2月 12 17:46 configuration.json
drwxrwxr-x 2 dechin dechin 4096 2月 12 17:46 figures/
-rw-rw-r-- 1 dechin dechin 181 2月 12 17:46 generation_config.json
drwxrwxr-x 9 dechin dechin 4096 2月 12 19:22 .git/
-rw-rw-r-- 1 dechin dechin 1519 2月 12 17:46 .gitattributes
-rw-rw-r-- 1 dechin dechin 1064 2月 12 17:46 LICENSE
-rw-rw-r-- 1 dechin dechin 8792578462 2月 12 19:22 model-00001-of-000008.safetensors
-rw-rw-r-- 1 dechin dechin 8776906899 2月 12 19:03 model-00002-of-000008.safetensors
-rw-rw-r-- 1 dechin dechin 8776906927 2月 12 19:18 model-00003-of-000008.safetensors
-rw-rw-r-- 1 dechin dechin 8776906927 2月 12 18:56 model-00004-of-000008.safetensors
-rw-rw-r-- 1 dechin dechin 8776906927 2月 12 18:38 model-00005-of-000008.safetensors
-rw-rw-r-- 1 dechin dechin 8776906927 2月 12 19:19 model-00006-of-000008.safetensors
-rw-rw-r-- 1 dechin dechin 8776906927 2月 12 19:15 model-00007-of-000008.safetensors
-rw-rw-r-- 1 dechin dechin 4073821536 2月 12 19:02 model-00008-of-000008.safetensors
-rw-rw-r-- 1 dechin dechin 64018 2月 12 17:46 model.safetensors.index.json
-rw-rw-r-- 1 dechin dechin 18985 2月 12 17:46 README.md
-rw-rw-r-- 1 dechin dechin 3071 2月 12 17:46 tokenizer_config.json
-rw-rw-r-- 1 dechin dechin 7031660 2月 12 17:46 tokenizer.json
这就是下载成功了。
HF模型转GGUF模型
找到编译好的llama/llama.cpp/
下的python脚本文件,可以先看下其用法:
$ python3 convert_hf_to_gguf.py --help
usage: convert_hf_to_gguf.py [-h] [--vocab-only] [--outfile OUTFILE] [--outtype {f32,f16,bf16,q8_0,tq1_0,tq2_0,auto}] [--bigendian] [--use-temp-file] [--no-lazy][--model-name MODEL_NAME] [--verbose] [--split-max-tensors SPLIT_MAX_TENSORS] [--split-max-size SPLIT_MAX_SIZE] [--dry-run][--no-tensor-first-split] [--metadata METADATA] [--print-supported-models][model]Convert a huggingface model to a GGML compatible filepositional arguments:model directory containing model fileoptions:-h, --help show this help message and exit--vocab-only extract only the vocab--outfile OUTFILE path to write to; default: based on input. {ftype} will be replaced by the outtype.--outtype {f32,f16,bf16,q8_0,tq1_0,tq2_0,auto}output format - use f32 for float32, f16 for float16, bf16 for bfloat16, q8_0 for Q8_0, tq1_0 or tq2_0 for ternary, and auto for the highest-fidelity 16-bit float type depending on the first loaded tensor type--bigendian model is executed on big endian machine--use-temp-file use the tempfile library while processing (helpful when running out of memory, process killed)--no-lazy use more RAM by computing all outputs before writing (use in case lazy evaluation is broken)--model-name MODEL_NAMEname of the model--verbose increase output verbosity--split-max-tensors SPLIT_MAX_TENSORSmax tensors in each split--split-max-size SPLIT_MAX_SIZEmax size per split N(M|G)--dry-run only print out a split plan and exit, without writing any new files--no-tensor-first-splitdo not add tensors to the first split (disabled by default)--metadata METADATA Specify the path for an authorship metadata override file--print-supported-modelsPrint the supported models
然后执行构建GGUF:
$ python3 convert_hf_to_gguf.py /datb/DeepSeek/models/DeepSeek-R1-Distill-Qwen-32B --outfile /datb/DeepSeek/models/DeepSeek-R1-Distill-Qwen-32B.gguf
INFO:hf-to-gguf:Set model quantization version
INFO:gguf.gguf_writer:Writing the following files:
INFO:gguf.gguf_writer:/datb/DeepSeek/models/DeepSeek-R1-Distill-Qwen-32B.gguf: n_tensors = 771, total_size = 65.5G
Writing: 100%|██████████████████████████████████████████████████████████████| 65.5G/65.5G [19:42<00:00, 55.4Mbyte/s]
INFO:hf-to-gguf:Model successfully exported to /datb/DeepSeek/models/DeepSeek-R1-Distill-Qwen-32B.gguf
完成转化后,会在指定的路径下生成一个gguf文件,也就是all-in-one的模型文件。默认是fp32的精度,可以用于执行下一步的量化操作。
GGUF模型量化
在编译好的llama.cpp
的build/bin/
路径下,可以找到量化的可执行文件:
$ ./llama-quantize --help
usage: ./llama-quantize [--help] [--allow-requantize] [--leave-output-tensor] [--pure] [--imatrix] [--include-weights] [--exclude-weights] [--output-tensor-type] [--token-embedding-type] [--override-kv] model-f32.gguf [model-quant.gguf] type [nthreads]--allow-requantize: Allows requantizing tensors that have already been quantized. Warning: This can severely reduce quality compared to quantizing from 16bit or 32bit--leave-output-tensor: Will leave output.weight un(re)quantized. Increases model size but may also increase quality, especially when requantizing--pure: Disable k-quant mixtures and quantize all tensors to the same type--imatrix file_name: use data in file_name as importance matrix for quant optimizations--include-weights tensor_name: use importance matrix for this/these tensor(s)--exclude-weights tensor_name: use importance matrix for this/these tensor(s)--output-tensor-type ggml_type: use this ggml_type for the output.weight tensor--token-embedding-type ggml_type: use this ggml_type for the token embeddings tensor--keep-split: will generate quantized model in the same shards as input--override-kv KEY=TYPE:VALUEAdvanced option to override model metadata by key in the quantized model. May be specified multiple times.
Note: --include-weights and --exclude-weights cannot be used togetherAllowed quantization types:2 or Q4_0 : 4.34G, +0.4685 ppl @ Llama-3-8B3 or Q4_1 : 4.78G, +0.4511 ppl @ Llama-3-8B8 or Q5_0 : 5.21G, +0.1316 ppl @ Llama-3-8B9 or Q5_1 : 5.65G, +0.1062 ppl @ Llama-3-8B19 or IQ2_XXS : 2.06 bpw quantization20 or IQ2_XS : 2.31 bpw quantization28 or IQ2_S : 2.5 bpw quantization29 or IQ2_M : 2.7 bpw quantization24 or IQ1_S : 1.56 bpw quantization31 or IQ1_M : 1.75 bpw quantization36 or TQ1_0 : 1.69 bpw ternarization37 or TQ2_0 : 2.06 bpw ternarization10 or Q2_K : 2.96G, +3.5199 ppl @ Llama-3-8B21 or Q2_K_S : 2.96G, +3.1836 ppl @ Llama-3-8B23 or IQ3_XXS : 3.06 bpw quantization26 or IQ3_S : 3.44 bpw quantization27 or IQ3_M : 3.66 bpw quantization mix12 or Q3_K : alias for Q3_K_M22 or IQ3_XS : 3.3 bpw quantization11 or Q3_K_S : 3.41G, +1.6321 ppl @ Llama-3-8B12 or Q3_K_M : 3.74G, +0.6569 ppl @ Llama-3-8B13 or Q3_K_L : 4.03G, +0.5562 ppl @ Llama-3-8B25 or IQ4_NL : 4.50 bpw non-linear quantization30 or IQ4_XS : 4.25 bpw non-linear quantization15 or Q4_K : alias for Q4_K_M14 or Q4_K_S : 4.37G, +0.2689 ppl @ Llama-3-8B15 or Q4_K_M : 4.58G, +0.1754 ppl @ Llama-3-8B17 or Q5_K : alias for Q5_K_M16 or Q5_K_S : 5.21G, +0.1049 ppl @ Llama-3-8B17 or Q5_K_M : 5.33G, +0.0569 ppl @ Llama-3-8B18 or Q6_K : 6.14G, +0.0217 ppl @ Llama-3-8B7 or Q8_0 : 7.96G, +0.0026 ppl @ Llama-3-8B1 or F16 : 14.00G, +0.0020 ppl @ Mistral-7B32 or BF16 : 14.00G, -0.0050 ppl @ Mistral-7B0 or F32 : 26.00G @ 7BCOPY : only copy tensors, no quantizing
这里可以看到完整的可以执行量化操作的精度。例如我们可以量化一个q4_0
精度的32B模型:
$ ./llama-quantize /datb/DeepSeek/models/DeepSeek-R1-Distill-Qwen-32B.gguf /datb/DeepSeek/models/DeepSeek-R1-Distill-Qwen-32B-Q4_0.gguf q4_0
输出结果对比(这里的Q8_0是直接从模型仓库里面下载的别人量化出来的Q8_0模型):
-rw-rw-r-- 1 dechin dechin 65535969184 2月 13 09:33 DeepSeek-R1-Distill-Qwen-32B.gguf
-rw-rw-r-- 1 dechin dechin 18640230304 2月 13 09:51 DeepSeek-R1-Distill-Qwen-32B-Q4_0.gguf
-rw-rw-r-- 1 dechin dechin 34820884384 2月 9 01:44 DeepSeek-R1-Distill-Qwen-32B-Q8_0.gguf
从F32到Q8再到Q4,可以看到有一个很明显的内存占用的下降。我们可以根据自己本地的计算机资源来决定要做多少精度的量化操作。
量化完成后,导入模型成功以后,可以用ollama list
查看到所有的本地模型:
$ ollama list
NAME ID SIZE MODIFIED
deepseek-r1:32b-q2k 8d2a0c19f6e0 12 GB 5 seconds ago
deepseek-r1:32b-q40 13c7c287f615 18 GB 3 minutes ago
deepseek-r1:32b 91f2de3dd7fd 34 GB 42 hours ago
nomic-embed-text-v1.5:latest 5b3683392ccb 274 MB 43 hours ago
deepseek-r1:14b ea35dfe18182 9.0 GB 7 days ago
这里q2k也是本地量化的Q2_K
的模型。只是从Q4_0
到Q2_k
已经没有太大的参数内存缩减了,所以很多人量化一般就到Q4_0
这个级别,可以兼具性能与精确性。
其他报错处理
如果运行llama-quantize
这个可执行文件出现这种报错:
./xxx/llama-quantize: error while loading shared libraries: libllama.so: cannot open shared object file: No such file or directory
动态链接库路径LD_LIBRARY_PATH
没有设置,也可以选择直接进入到bin/
路径下运行该可执行文件。
总结概要
这篇文章主要介绍了llama.cpp这一大模型工具的使用。因为已经使用Ollama来run大模型,因此仅介绍了llama.cpp在HF模型转GGUF模型中的应用,及其在大模型量化中的使用。大模型的参数量化技术,使得我们可以在本地有限预算的硬件条件下,也能够运行DeepSeek的蒸馏模型。
文章转载自:Dechin的博客
原文链接:DeepSeek模型量化 - DECHIN - 博客园
体验地址:引迈 - JNPF快速开发平台_低代码开发平台_零代码开发平台_流程设计器_表单引擎_工作流引擎_软件架构
相关文章:
DeepSeek模型量化
技术背景 大语言模型(Large Language Model,LLM),可以通过量化(Quantization)操作来节约内存/显存的使用,并且降低了通讯开销,进而达到加速模型推理的效果。常见的就是把Float16的浮…...
【练习】【回溯:组合:不同集合】力扣 17. 电话号码的字母组合
题目 电话号码的字母组合 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。答案可以按 任意顺序 返回。 给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。 示例 1: 输入:digits “2…...

分布式文件系统HDFS
一、HDFS简介 HDFS( Hadoop Distributed File System ),意为:Hadoop分布式文件系统。是Apache Hadoop核心组件之一,作为大数据生态圈最底层的分布式存储服务而存在。分布式文件系统解决大数据如何存储问题。分布式意味…...

从WebRTC到EasyRTC:嵌入式适配的视频通话SDK实现低延迟、高稳定性音视频通信
WebRTC最初是为浏览器之间的实时通信设计的,其资源需求和复杂性可能对嵌入式设备的性能提出较高要求,因此在嵌入式系统中应用时面临一些挑战: 1)资源消耗较高 CPU和内存占用:WebRTC是一个功能强大的实时通信框架&…...

WordPress自定义排序插件:Simple Custom Post Order完全指南(SEO优化版)
在WordPress建站中,文章、分类目录或页面的默认排序方式往往无法满足个性化需求。WordPress自定义排序插件:Simple Custom Post Order插件,你可以轻松实现拖拽式自定义排序,无需修改代码即可优化内容展示逻辑。本文将详细介绍这款…...
docker安装ros2 并在windows中显示docker内ubuntu系统窗口并且vscode编程
这里包括docker desktop安装ros2 humble hawkshill , 安装xserver(用来在windows中显示ubuntu中窗口), vscode安装插件连接docker并配置python的一系列方法 1.安装xserver 为了能方便的在windows中显示ubuntu内的窗口,比如rqt窗口 参考文章:https://www.cnblogs.com/larva-zhh…...
【QT中的一些高级数据结构,持续更新中...】
QT中有一些很精妙、便捷的设计,在了解这些数据的同时,我们可以学到如何更好的设计代码。本贴持续更新中,欢迎关注和收藏 一 QScopedPointer主要特点:示例代码 二 Q_DISABLE_COPY 一 QScopedPointer QScopedPointer 是 Qt 中的一种…...
简单工厂模式 (Simple Factory Pattern) 在Spring Boot 中的应用
简单工厂模式(Simple Factory Pattern)虽然不属于 GoF 23 种经典设计模式,但在实际开发中非常常用,尤其是在 Spring Boot 项目中。它提供了一种简单的方式来创建对象,将对象的创建逻辑集中到一个工厂类中。 一、简单工…...

《95015网络安全应急响应分析报告(2024)》
2025年2月,95015服务平台发布了最新一期的《95015网络安全应急响应分析报告(2024)》。报告分别从整体形势、受害者特征、攻击者特征等方面,对2024年95015平台接报的739起网络安全应急响应事件展开分析,并给出了7个年度…...
TensorFlow v2.16 Overview
TensorFlow v2.16 Overview 一、模块 Modules二、类 Classes三、函数 Functions TensorFlow v2.16.1 Overview 一、模块 Modules 模块是TensorFlow中组织代码的一种方式,将相关的功能和类封装在一起,方便用户使用和管理。每个模块都提供了特定领域的公共…...
Udp发送和接收数据(python和QT)
服务端代码 (python) import socketdef udp_server(host0.0.0.0, port12345):# 创建一个UDP套接字sock socket.socket(socket.AF_INET, socket.SOCK_DGRAM)# 绑定服务器的IP地址和端口号sock.bind((host, port))print(f"UDP服务器已启动,监听端口 {port}...&…...
element-plus 根据条件显示多选框
代码如下: <el-table :data"pager.lists" selection-change"handleSelectionChange" row-key"id" :tree-props"{ checkStrictly: true }" :cell-class-name"cellClass"> <el-table-column type"s…...

Ubuntu 22.04 Install deepseek
前言 deepseekAI助手。它具有聊天机器人功能,可以与用户进行自然语言交互,回答问题、提供建议和帮助解决问题。DeepSeek 的特点包括: 强大的语言理解能力:能够理解和生成自然语言,与用户进行流畅的对话。多领域知识&…...

DeepSeek赋能智慧文旅:新一代解决方案,重构文旅发展的底层逻辑
DeepSeek作为一款前沿的人工智能大模型,凭借其强大的多模态理解、知识推理和内容生成能力,正在重构文旅产业的发展逻辑,推动行业从传统的经验驱动向数据驱动、从人力密集型向智能协同型转变。 一、智能服务重构:打造全域感知的智…...

小程序的分包
1.分包的概念以及基本用法 2.在小程序项目里面添加自己的分包 3.给分包加上别名 4.查看分包体积大小 5.分包的打包原则 6.分包的引用原则 7.独立分包 8.分包的预下载...
RTSP场景下RTP协议详解及音视频打包全流程
RTSP场景下RTP协议详解及音视频打包全流程 一、RTSP与RTP的关系 RTSP:负责媒体会话控制(DESCRIBE、SETUP、PLAY、PAUSE),通过SDP协商传输参数(端口、编码格式、封装模式)。RTP:实际传输音视频数…...

使用API有效率地管理Dynadot域名,为域名部署DNS安全拓展(DNSSEC)
关于Dynadot Dynadot是通过ICANN认证的域名注册商,自2002年成立以来,服务于全球108个国家和地区的客户,为数以万计的客户提供简洁,优惠,安全的域名注册以及管理服务。 Dynadot平台操作教程索引(包括域名邮…...

如何基于transformers库通过训练Qwen/DeepSeek模型的传统分类能力实现文本分类任务
文章目录 模型与环境准备文档分析源码解读模型训练及推理方式进阶:CPU与显存的切换进阶:多卡数据并行训练🔑 DDP 训练过程核心步骤🚫 DDP 不适用于模型并行⚖️ DDP vs. Model Parallelism⚙️ 解决大模型训练的推荐方法🎉进入大模型应用与实战专栏 | 🚀查看更多专栏…...

开源一款I2C电机驱动扩展板-FreakStudio多米诺系列
总线直流电机扩展板 原文链接: FreakStudio的博客 摘要 设计了一个I2C电机驱动板,通过I2C接口控制多个电机的转速和方向,支持刹车和减速功能。可连接16个扩展板,具有PWM输出、过流过热保护和可更换电机驱动芯片。支持按键控制…...
FFmpeg+WebSocket+JsMpeg实时视频流实现方案
之前写的使用FFmpeg Nginx HLS流媒体播放方案,适合对实时性要求不高的需求,存在延迟,FFmpeg需要将视频流存储到本地文件,而本次方案FFmpeg不需要将视频流存储到本地文件,而是直接将转换后的视频流(如MJPE…...

Vue3 + Element Plus + TypeScript中el-transfer穿梭框组件使用详解及示例
使用详解 Element Plus 的 el-transfer 组件是一个强大的穿梭框组件,常用于在两个集合之间进行数据转移,如权限分配、数据选择等场景。下面我将详细介绍其用法并提供一个完整示例。 核心特性与用法 基本属性 v-model:绑定右侧列表的值&…...

DAY 47
三、通道注意力 3.1 通道注意力的定义 # 新增:通道注意力模块(SE模块) class ChannelAttention(nn.Module):"""通道注意力模块(Squeeze-and-Excitation)"""def __init__(self, in_channels, reduction_rat…...
oracle与MySQL数据库之间数据同步的技术要点
Oracle与MySQL数据库之间的数据同步是一个涉及多个技术要点的复杂任务。由于Oracle和MySQL的架构差异,它们的数据同步要求既要保持数据的准确性和一致性,又要处理好性能问题。以下是一些主要的技术要点: 数据结构差异 数据类型差异ÿ…...

嵌入式学习笔记DAY33(网络编程——TCP)
一、网络架构 C/S (client/server 客户端/服务器):由客户端和服务器端两个部分组成。客户端通常是用户使用的应用程序,负责提供用户界面和交互逻辑 ,接收用户输入,向服务器发送请求,并展示服务…...
【Nginx】使用 Nginx+Lua 实现基于 IP 的访问频率限制
使用 NginxLua 实现基于 IP 的访问频率限制 在高并发场景下,限制某个 IP 的访问频率是非常重要的,可以有效防止恶意攻击或错误配置导致的服务宕机。以下是一个详细的实现方案,使用 Nginx 和 Lua 脚本结合 Redis 来实现基于 IP 的访问频率限制…...
日常一水C
多态 言简意赅:就是一个对象面对同一事件时做出的不同反应 而之前的继承中说过,当子类和父类的函数名相同时,会隐藏父类的同名函数转而调用子类的同名函数,如果要调用父类的同名函数,那么就需要对父类进行引用&#…...
vue3 daterange正则踩坑
<el-form-item label"空置时间" prop"vacantTime"> <el-date-picker v-model"form.vacantTime" type"daterange" start-placeholder"开始日期" end-placeholder"结束日期" clearable :editable"fal…...

云安全与网络安全:核心区别与协同作用解析
在数字化转型的浪潮中,云安全与网络安全作为信息安全的两大支柱,常被混淆但本质不同。本文将从概念、责任分工、技术手段、威胁类型等维度深入解析两者的差异,并探讨它们的协同作用。 一、核心区别 定义与范围 网络安全:聚焦于保…...

【若依】框架项目部署笔记
参考【SpringBoot】【Vue】项目部署_no main manifest attribute, in springboot-0.0.1-sn-CSDN博客 多一个redis安装 准备工作: 压缩包下载:http://download.redis.io/releases 1. 上传压缩包,并进入压缩包所在目录,解压到目标…...

内窥镜检查中基于提示的息肉分割|文献速递-深度学习医疗AI最新文献
Title 题目 Prompt-based polyp segmentation during endoscopy 内窥镜检查中基于提示的息肉分割 01 文献速递介绍 以下是对这段英文内容的中文翻译: ### 胃肠道癌症的发病率呈上升趋势,且有年轻化倾向(Bray等人,2018&#x…...