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的浮…...
如何调整CAN位宽容忍度?
CAN位宽容忍度是指在控制器局域网络(CAN, Controller Area Network)中允许时钟同步的误差范围。这是CAN网络正常通信时的关键因素之一,因为CAN协议依赖位同步来确保多个节点在总线上正确解码数据。CAN位宽容忍度确保节点之间由于时钟偏差或抖…...
Versal - 基础6(Linux 开发 AIE-ML + 自动化脚本解析)
目录 1. 简介 2. 步骤解析 2.1 概览 2.1.1 步骤依赖关系 2.1.2 总目录结构 2.2 Vitis XPFM 2.2.1 Dir 2.2.2 Makefile 2.2.3 vitis_pfm.py 2.3 Kernels 2.3.1 Dir 2.3.2 Makefile 2.3.3 config 文件 2.4 AIE_app 2.4.1 Dir 2.4.2 Makefile 2.4.3 aie 要点 2.…...
乐享数科:供应链金融—三个不同阶段的融资模式
供应链金融是与产业链紧密结合的融资模式,它主要体现在订单采购、存货保管、销售回款这三个不同的业务阶段,并针对这些阶段提供了相应的金融服务。以下是这三个阶段中主要的融资模式及其特点: 供应链金融融资模式主要分为以下几种࿱…...
vmware虚拟机Ubuntu Desktop系统怎么和我的电脑相互复制文件、内容
1、先安装vmware workstation 17 player,然后再安装Ubuntu Desktop虚拟机,然后再安装vmware tools,具体可以参考如下视频: VMware虚拟机与主机实现文件共享,其实一点也不难_哔哩哔哩_bilibili 2、本人亲自试过了&…...
【React】React 基础(2)
JSX 是什么 JSX是一种 JavaScript 的语法扩展(extension), 也在很多地方称之为 JavaScript XML, 因为看起就是一段XML语法。它用于描述我们的Ul界面,并且其完成可以和 JavaScript 融合在一起使用; 为什么 React 选择使用 jsx? React 认为渲…...
DeepSeek接入Siri(已升级支持苹果手表)完整版硅基流动DeepSeek-R1部署
DeepSeek接入Siri(已升级支持苹果手表)完整版硅基流动DeepSeek-R1部署 **DeepSeek** 是一款专注于深度学习和人工智能的工具或平台,通常与人工智能、机器学习、自动化分析等领域有关。它的主要功能可能包括:深度学习模型搜索&…...
ASP.NET MVC AJAX 文件上传
如何使用 MVC 5 和 AJAX(.NET Framework)上传文件。 使用AJAX和ASP.NET MVC 上传文件 再简单不过了。对于最纯粹的人来说,这不需要使用jQuery。此代码实际上允许上传多个文件。 注意:以下代码示例支持 ASP.NET MVC 5。如果使用 .…...
npm使用了代理,但是代理软件已经关闭导致创建失败
如果在关闭前打开了vscode,此时vscode中的终端没有刷新,就会出现这个问题,最开始会一直转圈圈,直到超时,然后出现该报错 ❯ npm create vuelatest npm error code ECONNREFUSED npm error syscall connect npm error …...
Spring Boot定时任务原理
Spring Boot定时任务原理 在现代应用中,定时任务的调度是实现周期性操作的关键机制。Spring Boot 提供了强大的定时任务支持,通过注解驱动的方式,开发者可以轻松地为方法添加定时任务功能。本文将深入探讨 Spring Boot 中定时任务的实现原理…...
公文派2025:免费社区版重大安装更新!
大家好,感谢对「公文派」的支持。 距离上一次更新已经过去了将近一年的时间,今天我们带来了全新的免费2025社区版,该版本也是目前最新的版本,无需授权即可使用所有的功能。 我们先来看下本版本的更新及特色功能 聚合多个AI功能…...
Ubuntu24.04LTS的下载安装超细图文教程(VMware虚拟机及正常安装)
😸个人主页👉:神兽汤姆猫 📖系列专栏:开发语言环境配置 、 Java学习 、Java面试 、Markdown等 学习上的每一次进步,均来自于平时的努力与坚持。 💕如果此篇文章对您有帮助的话,请点…...
ES6相关操作
一.JavaScript的基础语法 1.Demo1.html <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>JavaScrip…...
【运维】源码编译安装cmake
背景: 已经在本地源码编译安装gcc/g,现在源码安装cmake 下载源码 下载地址:CMake - Upgrade Your Software Build System 安装步骤: ./bootstrap --prefix/usr/local/cmake make make install 错误处理 1、提示找不到libmpc.…...
代码随想录_回溯
代码随想录_回溯 回溯 77.组合 77. 组合 给定两个整数 n 和 k,返回范围 [1, n] 中所有可能的 k 个数的组合。 你可以按 任何顺序 返回答案。 思路: 回溯 优化: 剪枝 注意代码中i,就是for循环里选择的起始位置。 for (int i startIndex; i <…...
tauri2实现监听记住窗口大小变化,重启回复之前的窗口大小
要想实现记住窗口大小的功能,整体逻辑就是要监听窗口大小变化,将窗口大小保存下来,重启之后,读取保存的大小,然后恢复。这里可以使用rust层实现,也可以在前端实现。我这里就纯rust层实现了。 监听窗口变化…...
番茄工作法html实现
对比了deepseek-r1-online和本地部署的14b的版本,输出的输出的html页面。 在线满血版的功能比较强大,可以一次完成所有要求。14b版本的功能有一些欠缺,但是基本功能也是写了出来了。 input write a html named Pomodoro-clock which “hel…...
C++:dfs,bfs各两则
1.木棒 167. 木棒 - AcWing题库 乔治拿来一组等长的木棒,将它们随机地砍断,使得每一节木棍的长度都不超过 5050 个长度单位。 然后他又想把这些木棍恢复到为裁截前的状态,但忘记了初始时有多少木棒以及木棒的初始长度。 请你设计一个程序…...
【ORB-SLAM3】鲁棒核函数的阈值设置
问题背景 阈值 δ \delta δ 是 Huber 鲁棒核函数的重要参数。首先给出结论,在ORB-SLAM系列中,该阈值选取的原则为: 单目情况下,根据95%置信水平下两自由度卡方检验的临界值, δ \delta δ 设置为 5.991 \sqrt{5.9…...
四种常见图形库GLUT,SDL,SFML和GLFW简介
GLUT、SDL、SFML 和 GLFW 是四种常用的库,用于管理窗口、输入和上下文创建,通常与 OpenGL 结合使用以实现图形渲染。以下是它们的详细介绍、常用应用场合和具体案例。 1. GLUT(OpenGL Utility Toolkit) 简介 GLUT 是一个用于创建…...
C++类和对象进阶:初始化列表和static成员深度详解
C类和对象:初始化列表和static成员深度详解 1. 前言2. 构造函数初始化成员变量的方式2.1 构造函数体内赋值2.2 初始化列表2.2.1 初始化列表的注意事项 2.3 初始化列表的初始化顺序 3. 类的静态成员3.1 引入3.2 静态成员变量3.3 静态成员函数3.4 静态成员的注意事项3…...
[C#]C# winform部署yolov12目标检测的onnx模型
yolov12官方框架:github.com/sunsmarterjie/yolov12 【测试环境】 vs2019 netframework4.7.2 opencvsharp4.8.0 onnxruntime1.16.3 【效果展示】 【调用代码】 using System; using System.Collections.Generic; using System.ComponentModel; using System.…...
阿里云k8s服务部署操作一指禅
文章目录 DockerFile镜像操作阿里云k8s服务部署 DockerFile # 使用 JDK 17 官方镜像 # linux架构:FROM --platformlinux/amd64 openjdk:17-jdk-slim # arm架构:openjdk:17-jdk-slim FROM --platformlinux/amd64 openjdk:17-jdk-slim# 设置工作目录 WORK…...
Transformer LLaMA
一、Transformer Transformer:一种基于自注意力机制的神经网络结构,通过并行计算和多层特征抽取,有效解决了长序列依赖问题,实现了在自然语言处理等领域的突破。 Transformer 架构摆脱了RNNs,完全依靠 Attention的优…...
球队训练信息管理系统设计与实现(代码+数据库+LW)
摘 要 传统办法管理信息首先需要花费的时间比较多,其次数据出错率比较高,而且对错误的数据进行更改也比较困难,最后,检索数据费事费力。因此,在计算机上安装球队训练信息管理系统软件来发挥其高效地信息处理的作用&a…...
【存储中间件API】MySQL、Redis、MongoDB、ES常见api操作及性能比较
常见中间件api操作及性能比较 ☝️ MySQL crud操作✌️ maven依赖✌️ 配置✌️ 定义实体类✌️ 常用api ☝️ Redis crud操作✌️ maven依赖✌️ 配置✌️ 常用api ☝️ MongoDB crud操作✌️ maven依赖✌️ 配置文件✌️ 定义实体类✌️ MongoDB常用api ☝️ ES crud操作 ⭐️…...
UE_C++ —— Gameplay Classes
目录 一,Adding Classes 二,Class Headers Class Declaration Class Specifiers Metadata Specifiers 三,Class Implementation Class Constructor 引擎中每个游戏类都由一个类头文件(.h)和一个类源文件&#x…...
windows上vscode cmake工程搭建
安装vscode插件: 1.按装fastc(主要是安装MinGW\mingw64比较方便) 2.安装C,cmake,cmake tools插件 3.准备工作完成之后,按F1,选择cmake:Quick Start就可以创建一个cmake工程。 4.设置Cmake: G…...
软件测试:1、单元测试
1. 单元测试的基本概念 单元(Unit):软件系统的基本组成单位,可以是函数、模块、方法或类。 单元测试(Unit Testing):对软件单元进行的测试,验证代码的正确性、规范性、安全性和性能…...
如果后台的Long类型的数据返回是null,那么Android客户端的数据bean的kotlin的Long类型的字段接受到数据后是null空指针吗?
如果后台的Long类型的数据返回是null,那么Android客户端的数据bean的kotlin的Long类型的字段接受到数据后是null空指针吗? DeepSeek R1 思考 35 秒 思考过程 好的,用户的问题是关于在Android客户端使用Kotlin处理后台返回的Long类型数据为n…...
Vue3 打造 Windows 桌面个性高效组件工具
软件介绍 Widgets 这款基于 Vue3 构建的开源 Windows 桌面小部件工具超实用。 其多样化组件库涵盖超 20 种,从倒计时、打工进度等实用工具,到抖音热榜等实时资讯组件应有尽有,各组件独立运行,满足多场景需求。 高度自定义布局支持…...
学习笔记-沁恒第四讲-米醋
一, 语音模块:数据包发送 刷卡模块:数据包接收 AS608:数据包发送接收 二,第三讲文件夹改成第四讲,工程也改成第四讲 三,目前在内存里面。保存新值,掉电会丢失 u8 password[6]{1,…...
epoll_event的概念和使用案例
epoll_event 是 Linux 下 epoll I/O 多路复用机制的核心数据结构,用于描述文件描述符(File Descriptor, FD)上发生的事件及其关联的用户数据。通过 epoll,可以高效地监控多个文件描述符的状态变化(如可读、可写、错误等…...
容器和虚拟机选择对比
1. 概述 如果主要需求是学习和测试 Ubuntu 下的命令行工具或服务型应用,推荐使用 Docker Docker 更轻量、更高效,适合快速搭建和销毁环境。 启用 WSL 2,Docker Desktop 是一个非常好的选择。 如果需要完整的桌面环境或进行复杂的系统级开…...
C++17中std::chrono::duration和std::chrono::time_point的舍入函数
文章目录 1. std::chrono::duration的舍入函数1.1 floor1.2 ceil1.3 round 2. std::chrono::time_point的舍入函数2.1 示例 3. 舍入函数的应用场景3.1 时间测量3.2 数据记录3.3 时间同步 4. 总结 在C17中, std::chrono库提供了一组强大的时间处理工具,包…...
基于SpringBoot的线上汽车租赁系统的设计与实现(源码+SQL脚本+LW+部署讲解等)
专注于大学生项目实战开发,讲解,毕业答疑辅导,欢迎高校老师/同行前辈交流合作✌。 技术范围:SpringBoot、Vue、SSM、HLMT、小程序、Jsp、PHP、Nodejs、Python、爬虫、数据可视化、安卓app、大数据、物联网、机器学习等设计与开发。 主要内容:…...
基于Dancing Links的精确覆盖算法(解决NP难问题)和量子计算机模拟中的Shor算法(涉及数论与量子叠加态模拟)
一、Dancing Links算法实现数独求解(NP难问题) 算法方案 数独可转化为精确覆盖问题,使用Knuth提出的DLX算法实现高效求解。该算法通过双向十字循环链表实现快速回溯,时间复杂度可达O(n^k)(k为常数) #include <iostream> #include <vector> #include <c…...
体育品牌排行榜前十名:MLB·棒球1号位
MLB是一个融合了棒球文化与街头时尚元素的潮流运动品牌。以下是对该品牌的详细介绍: 一、品牌背景 • 全称:MLB全称是Major League Baseball,即美国职业棒球大联盟。不过,作为品牌的MLB并非由美国职业棒球大联盟直接运营&#x…...
Java网络编程封装
系列文章目录 Java知识点 文章目录 系列文章目录👉前言👉一、封装的目标👉二、套接字层封装👉壁纸分享👉总结 👉前言 Java 网络编程封装原理主要围绕着将底层的网络通信细节隐藏起来,提供简洁…...
数字内容体验标杆案例解析
内容概要 在数字化转型浪潮中,数字内容体验正成为企业构建核心竞争力的关键抓手。本文通过拆解金融、零售、文旅等领域的标杆案例,系统分析沉浸式设计与智能交互系统的技术融合路径,揭示头部企业如何通过XR技术、实时数据可视化及场景化内容…...
区块链相关方法-PEST分析
一、定义:一种用于分析企业外部宏观环境的工具。PEST 这四个字母分别代表政治(Political)、经济(Economic)、社会(Social)和技术(Technological)。这种分析方法帮助企业或组织了解宏…...
Dify安装教程:Linux系统本地化安装部署Dify详细教程
1. 本地部署 Dify 应用开发平台 环境:Ubuntu(24.10) docker-ce docker compose 安装 克隆 Dify 源代码至本地环境: git clone https://github.com/langgenius/dify.git 启动 Dify: cd dify/docker cp .env.example...
git使用-克隆远程项目、分支管理
文章目录 克隆远程项目到本地1. 远程找到需要克隆的项目,复制ssh地址2. idea开启git版本控制(如果已经开了,忽略此步骤)3. clone远端项目4. 克隆完成 分支管理1. 新建分支2. 切换分支3. 合并分支4. 储存变化 克隆远程项目到本地 …...
QT 引入Quazip和Zlib源码工程到项目中,无需编译成库,跨平台,压缩进度
前言 最近在做项目时遇到一个需求,需要将升级的文件压缩成zip,再进行传输; 通过网络调研,有许多方式可以实现,例如QT私有模块的ZipReader、QZipWriter;或者第三方库zlib或者libzip或者quazip等࿱…...
SQLMesh 系列教程8- 详解 seed 模型
在数据分析和建模过程中,外部模型(External Models)在 SQLMesh 中扮演着重要角色。外部模型允许用户引用外部数据源或现有数据库表,从而实现灵活的数据整合和分析。本文将介绍外部模型的定义、生成方法(包括使用 CLI 和…...
oracle apex post接口
日常记录 使用到了apex_json方式接收 、、、1 首先,接口通过body传递过来,成功接收到, 数据格式为 JSON_OBJECT_T l_json : JSON_OBJECT_T.parse(:body); 这里我用参数接收到 然后 里面是包含了 "data" 我用 继续接收到这个 l…...
复制所绑定元素文本的vue自定义指令
最近写了一个复制所绑定元素文本的vue自定义指令,给大家分享一下。 import { ElMessage } from element-plus// data-* 属性名 const dataCopyBtnTextAttribute data-copy-btn-text // 复制按钮的class,结合项目实际进行设置 const copyBtnClass icon…...
若依-@Excel新增注解numberFormat
Excel注解中原本的scale会四舍五入小数,导致进度丢失 想要的效果 显示的时候保留两个小数真正的数值是保留之前的数值 还原过程 若以中有一個專門的工具类,用来处理excel的 找到EXCEL导出方法exportExcel()找到writeSheet,写表格的方法找到填充数据的方法…...
内容中台重构智能服务:人工智能技术驱动精准决策
内容概要 现代企业数字化转型进程中,内容中台与人工智能技术的深度融合正在重构智能服务的基础架构。通过整合自然语言处理、知识图谱构建与深度学习算法三大技术模块,该架构实现了从数据采集到决策输出的全链路智能化。在数据层,系统可对接…...
网络安全:DeepSeek已经在自动的挖掘漏洞
大家好,我是AI拉呱,一个专注于人工智领域与网络安全方面的博主,现任资深算法研究员一职,兼职硕士研究生导师;热爱机器学习和深度学习算法应用,深耕大语言模型微调、量化、私域部署。曾获多次获得AI竞赛大奖,拥有多项发明专利和学术论文。对于AI算法有自己独特见解和经验…...