1. 软件下载安装
Miniconda
Miniconda下载地址
选择对应的版本下载,此处下载如下版本
Python 3.10
conda 25.1.1
安装完成后,配置环境变量,打开cmd命令窗口验证
Python
Python的版本为 3.10
PyTorch
PyTorch下载地址
后面通过命令下载
2. 环境配置
2.1 系统环境变量配置
我的电脑–属性–高级系统设置–系统属性(高级)–环境变量
2.1.1 配置NVSMI_HOME
新建环境变量,点击确定
编辑Path,点击新建
增加NVSMI_HOME配置后,点击确定
2.1.2 配置miniconda
安装miniconda时若勾选添加到环境变量,则忽略该步骤
编辑环境变量,点击新建,添加miniconda的路径,最后点击确定
2.2 查看cuda版本
方式一:打开cmd窗口,查看cuda版本
C:\Users\Administrator>nvidia-smi
方式二: 打开NVIDIA控制面板
3. 创建虚拟环境及安装依赖
操作步骤
# python版本为3.10
conda create -n deepseek python=3.10
conda activate deepseek
# 安装deepseek-sdk
pip install deepseek-sdk
# 安装torch 对应cuda12.8版本
pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128
# transformers
pip install transformers>=4.33 accelerate sentencepiece
pip install protobuf
# 检查
conda list
D:\AI>conda create -n deepseek python=3.10
Channels:
- defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 25.1.1
latest version: 25.3.0
Please update conda by running
$ conda update -n base -c defaults conda
## Package Plan ##
environment location: D:\AI\soft\miniconda\envs\deepseek
added / updated specs:
- python=3.10
The following packages will be downloaded:
package | build
---------------------------|-----------------
ca-certificates-2025.2.25 | haa95532_0 130 KB
openssl-3.0.16 | h3f729d1_0 7.8 MB
xz-5.6.4 | h4754444_1 280 KB
------------------------------------------------------------
Total: 8.2 MB
The following NEW packages will be INSTALLED:
bzip2 pkgs/main/win-64::bzip2-1.0.8-h2bbff1b_6
ca-certificates pkgs/main/win-64::ca-certificates-2025.2.25-haa95532_0
libffi pkgs/main/win-64::libffi-3.4.4-hd77b12b_1
openssl pkgs/main/win-64::openssl-3.0.16-h3f729d1_0
pip pkgs/main/win-64::pip-25.0-py310haa95532_0
python pkgs/main/win-64::python-3.10.16-h4607a30_1
setuptools pkgs/main/win-64::setuptools-75.8.0-py310haa95532_0
sqlite pkgs/main/win-64::sqlite-3.45.3-h2bbff1b_0
tk pkgs/main/win-64::tk-8.6.14-h0416ee5_0
tzdata pkgs/main/noarch::tzdata-2025a-h04d1e81_0
vc pkgs/main/win-64::vc-14.42-haa95532_4
vs2015_runtime pkgs/main/win-64::vs2015_runtime-14.42.34433-he0abc0d_4
wheel pkgs/main/win-64::wheel-0.45.1-py310haa95532_0
xz pkgs/main/win-64::xz-5.6.4-h4754444_1
zlib pkgs/main/win-64::zlib-1.2.13-h8cc25b3_1
Proceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate deepseek
#
# To deactivate an active environment, use
#
# $ conda deactivate
D:\AI>conda activate deepseek
(deepseek) D:\AI>
(deepseek) D:\AI>pip install deepseek-sdk
Collecting deepseek-sdk
Downloading deepseek_sdk-0.1.0-py3-none-any.whl.metadata (1.4 kB)
Collecting openai>=1.0.0 (from deepseek-sdk)
Downloading openai-1.68.2-py3-none-any.whl.metadata (25 kB)
Collecting anyio<5,>=3.5.0 (from openai>=1.0.0->deepseek-sdk)
Downloading anyio-4.9.0-py3-none-any.whl.metadata (4.7 kB)
Collecting distro<2,>=1.7.0 (from openai>=1.0.0->deepseek-sdk)
Downloading distro-1.9.0-py3-none-any.whl.metadata (6.8 kB)
Collecting httpx<1,>=0.23.0 (from openai>=1.0.0->deepseek-sdk)
Downloading httpx-0.28.1-py3-none-any.whl.metadata (7.1 kB)
Collecting jiter<1,>=0.4.0 (from openai>=1.0.0->deepseek-sdk)
Downloading jiter-0.9.0-cp310-cp310-win_amd64.whl.metadata (5.3 kB)
Collecting pydantic<3,>=1.9.0 (from openai>=1.0.0->deepseek-sdk)
Downloading pydantic-2.10.6-py3-none-any.whl.metadata (30 kB)
Collecting sniffio (from openai>=1.0.0->deepseek-sdk)
Downloading sniffio-1.3.1-py3-none-any.whl.metadata (3.9 kB)
Collecting tqdm>4 (from openai>=1.0.0->deepseek-sdk)
Downloading tqdm-4.67.1-py3-none-any.whl.metadata (57 kB)
Collecting typing-extensions<5,>=4.11 (from openai>=1.0.0->deepseek-sdk)
Downloading typing_extensions-4.12.2-py3-none-any.whl.metadata (3.0 kB)
Collecting exceptiongroup>=1.0.2 (from anyio<5,>=3.5.0->openai>=1.0.0->deepseek-sdk)
Downloading exceptiongroup-1.2.2-py3-none-any.whl.metadata (6.6 kB)
Collecting idna>=2.8 (from anyio<5,>=3.5.0->openai>=1.0.0->deepseek-sdk)
Downloading idna-3.10-py3-none-any.whl.metadata (10 kB)
Collecting certifi (from httpx<1,>=0.23.0->openai>=1.0.0->deepseek-sdk)
Downloading certifi-2025.1.31-py3-none-any.whl.metadata (2.5 kB)
Collecting httpcore==1.* (from httpx<1,>=0.23.0->openai>=1.0.0->deepseek-sdk)
Downloading httpcore-1.0.7-py3-none-any.whl.metadata (21 kB)
Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx<1,>=0.23.0->openai>=1.0.0->deepseek-sdk)
Downloading h11-0.14.0-py3-none-any.whl.metadata (8.2 kB)
Collecting annotated-types>=0.6.0 (from pydantic<3,>=1.9.0->openai>=1.0.0->deepseek-sdk)
Downloading annotated_types-0.7.0-py3-none-any.whl.metadata (15 kB)
Collecting pydantic-core==2.27.2 (from pydantic<3,>=1.9.0->openai>=1.0.0->deepseek-sdk)
Downloading pydantic_core-2.27.2-cp310-cp310-win_amd64.whl.metadata (6.7 kB)
Collecting colorama (from tqdm>4->openai>=1.0.0->deepseek-sdk)
Downloading colorama-0.4.6-py2.py3-none-any.whl.metadata (17 kB)
Downloading deepseek_sdk-0.1.0-py3-none-any.whl (2.4 kB)
Downloading openai-1.68.2-py3-none-any.whl (606 kB)
---------------------------------------- 606.1/606.1 kB 99.1 kB/s eta 0:00:00
Downloading anyio-4.9.0-py3-none-any.whl (100 kB)
Downloading distro-1.9.0-py3-none-any.whl (20 kB)
Downloading httpx-0.28.1-py3-none-any.whl (73 kB)
Downloading httpcore-1.0.7-py3-none-any.whl (78 kB)
Downloading jiter-0.9.0-cp310-cp310-win_amd64.whl (208 kB)
Downloading pydantic-2.10.6-py3-none-any.whl (431 kB)
Downloading pydantic_core-2.27.2-cp310-cp310-win_amd64.whl (2.0 MB)
---------------------------------------- 2.0/2.0 MB 79.5 kB/s eta 0:00:00
Downloading sniffio-1.3.1-py3-none-any.whl (10 kB)
Downloading tqdm-4.67.1-py3-none-any.whl (78 kB)
Downloading typing_extensions-4.12.2-py3-none-any.whl (37 kB)
Downloading annotated_types-0.7.0-py3-none-any.whl (13 kB)
Downloading exceptiongroup-1.2.2-py3-none-any.whl (16 kB)
Downloading idna-3.10-py3-none-any.whl (70 kB)
Downloading certifi-2025.1.31-py3-none-any.whl (166 kB)
Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Downloading h11-0.14.0-py3-none-any.whl (58 kB)
Installing collected packages: typing-extensions, sniffio, jiter, idna, h11, exceptiongroup, distro, colorama, certifi, annotated-types, tqdm, pydantic-core, httpcore, anyio, pydantic, httpx, openai, deepseek-sdk
Successfully installed annotated-types-0.7.0 anyio-4.9.0 certifi-2025.1.31 colorama-0.4.6 deepseek-sdk-0.1.0 distro-1.9.0 exceptiongroup-1.2.2 h11-0.14.0 httpcore-1.0.7 httpx-0.28.1 idna-3.10 jiter-0.9.0 openai-1.68.2 pydantic-2.10.6 pydantic-core-2.27.2 sniffio-1.3.1 tqdm-4.67.1 typing-extensions-4.12.2
(deepseek) D:\AI\soft>pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128
Looking in indexes: https://download.pytorch.org/whl/nightly/cu128
Collecting torch
Downloading https://download.pytorch.org/whl/nightly/cu128/torch-2.8.0.dev20250321%2Bcu128-cp310-cp310-win_amd64.whl.metadata (29 kB)
Collecting torchvision
Downloading https://download.pytorch.org/whl/nightly/cu128/torchvision-0.22.0.dev20250321%2Bcu128-cp310-cp310-win_amd64.whl.metadata (6.3 kB)
Collecting torchaudio
Downloading https://download.pytorch.org/whl/nightly/cu128/torchaudio-2.6.0.dev20250321%2Bcu128-cp310-cp310-win_amd64.whl.metadata (6.8 kB)
Collecting filelock (from torch)
Downloading https://download.pytorch.org/whl/nightly/filelock-3.16.1-py3-none-any.whl (16 kB)
Requirement already satisfied: typing-extensions>=4.10.0 in d:\ai\soft\miniconda\envs\deepseek\lib\site-packages (from torch) (4.12.2)
Collecting sympy>=1.13.3 (from torch)
Downloading https://download.pytorch.org/whl/nightly/sympy-1.13.3-py3-none-any.whl (6.2 MB)
---------------------------------------- 6.2/6.2 MB 3.7 MB/s eta 0:00:00
Collecting networkx (from torch)
Downloading https://download.pytorch.org/whl/nightly/networkx-3.4.2-py3-none-any.whl (1.7 MB)
---------------------------------------- 1.7/1.7 MB 3.2 MB/s eta 0:00:00
Collecting jinja2 (from torch)
Downloading https://download.pytorch.org/whl/nightly/jinja2-3.1.4-py3-none-any.whl (133 kB)
Collecting fsspec (from torch)
Downloading https://download.pytorch.org/whl/nightly/fsspec-2024.10.0-py3-none-any.whl (179 kB)
Collecting numpy (from torchvision)
Downloading https://download.pytorch.org/whl/nightly/numpy-2.1.2-cp310-cp310-win_amd64.whl (12.9 MB)
---------------------------------------- 12.9/12.9 MB 3.5 MB/s eta 0:00:00
Collecting torch
Downloading https://download.pytorch.org/whl/nightly/cu128/torch-2.8.0.dev20250320%2Bcu128-cp310-cp310-win_amd64.whl.metadata (29 kB)
Collecting pillow!=8.3.*,>=5.3.0 (from torchvision)
Downloading https://download.pytorch.org/whl/nightly/pillow-11.0.0-cp310-cp310-win_amd64.whl (2.6 MB)
---------------------------------------- 2.6/2.6 MB 4.2 MB/s eta 0:00:00
Collecting mpmath<1.4,>=1.1.0 (from sympy>=1.13.3->torch)
Downloading https://download.pytorch.org/whl/nightly/mpmath-1.3.0-py3-none-any.whl (536 kB)
---------------------------------------- 536.2/536.2 kB 4.4 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0 (from jinja2->torch)
Downloading https://download.pytorch.org/whl/nightly/MarkupSafe-2.1.5-cp310-cp310-win_amd64.whl (17 kB)
Downloading https://download.pytorch.org/whl/nightly/cu128/torchvision-0.22.0.dev20250321%2Bcu128-cp310-cp310-win_amd64.whl (7.6 MB)
---------------------------------------- 7.6/7.6 MB 4.2 MB/s eta 0:00:00
Downloading https://download.pytorch.org/whl/nightly/cu128/torch-2.8.0.dev20250320%2Bcu128-cp310-cp310-win_amd64.whl (3327.8 MB)
---------------------------------------- 3.3/3.3 GB 2.7 MB/s eta 0:00:00
Downloading https://download.pytorch.org/whl/nightly/cu128/torchaudio-2.6.0.dev20250321%2Bcu128-cp310-cp310-win_amd64.whl (4.7 MB)
---------------------------------------- 4.7/4.7 MB 4.9 MB/s eta 0:00:00
Installing collected packages: mpmath, sympy, pillow, numpy, networkx, MarkupSafe, fsspec, filelock, jinja2, torch, torchvision, torchaudio
Successfully installed MarkupSafe-2.1.5 filelock-3.16.1 fsspec-2024.10.0 jinja2-3.1.4 mpmath-1.3.0 networkx-3.4.2 numpy-2.1.2 pillow-11.0.0 sympy-1.13.3 torch-2.8.0.dev20250320+cu128 torchaudio-2.6.0.dev20250321+cu128 torchvision-0.22.0.dev20250321+cu128
(deepseek) D:\AI\>
4. 模型下载
DeepSeek模型下载地址
此处下载DeepSeek-R1-Distill-Qwen-7B版本
本地创建文件夹,将下载的文件全部复制到文件夹下
5. 测试
创建测试目录,在目录下创建脚本文件test.py,脚本内容如
#使用transformer加载模型
from transformers import AutoTokenizer, AutoModelForCausalLM
#加载本地模型路径
model_path = "D:\AI\models"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(
model_path,
device_map="balanced_low_0",
torch_dtype='float16'
)
prompt = "请给一个deepseek的搭建步骤"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(
**inputs,
max_new_tokens=128,
do_sample=True,
temperature=0.7
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
执行测试脚本
# 激活deepseek环境
conda activate deepseek
cd D:\AI\scripts
# 执行脚本
python test.py
# 测试完成后退出
#conda deactivate
长时间等待的结果
CPU、内存和GPU
6. 其他模型
6.1 下载deepseek-llm-7b-chat模型
# 1.安装modelscope
(deepseek) D:\AI>pip install modelscope
# 2.下载模型文件
(deepseek) D:\AI>modelscope download --model deepseek-ai/deepseek-llm-7b-chat
(deepseek) D:\AI\scripts>pip install modelscope
Collecting modelscope
Downloading modelscope-1.24.0-py3-none-any.whl.metadata (39 kB)
Requirement already satisfied: requests>=2.25 in d:\ai\soft\miniconda\envs\deepseek\lib\site-packages (from modelscope) (2.32.3)
Requirement already satisfied: tqdm>=4.64.0 in d:\ai\soft\miniconda\envs\deepseek\lib\site-packages (from modelscope) (4.67.1)
Requirement already satisfied: urllib3>=1.26 in d:\ai\soft\miniconda\envs\deepseek\lib\site-packages (from modelscope) (2.3.0)
Requirement already satisfied: charset-normalizer<4,>=2 in d:\ai\soft\miniconda\envs\deepseek\lib\site-packages (from requests>=2.25->modelscope) (3.4.1)
Requirement already satisfied: idna<4,>=2.5 in d:\ai\soft\miniconda\envs\deepseek\lib\site-packages (from requests>=2.25->modelscope) (3.10)
Requirement already satisfied: certifi>=2017.4.17 in d:\ai\soft\miniconda\envs\deepseek\lib\site-packages (from requests>=2.25->modelscope) (2025.1.31)
Requirement already satisfied: colorama in d:\ai\soft\miniconda\envs\deepseek\lib\site-packages (from tqdm>=4.64.0->modelscope) (0.4.6)
Downloading modelscope-1.24.0-py3-none-any.whl (5.9 MB)
---------------------------------------- 5.9/5.9 MB 42.8 kB/s eta 0:00:00
Installing collected packages: modelscope
Successfully installed modelscope-1.24.0
(deepseek) D:\AI\scripts>
(deepseek) D:\AI\scripts>modelscope download --model deepseek-ai/deepseek-llm-7b-chat
Downloading Model from https://www.modelscope.cn to directory: C:\Users\Administrator\.cache\modelscope\hub\models\deepseek-ai\deepseek-llm-7b-chat
Downloading [README.md]: 100%|███████████████████████████████████████████████████████████████████████████| 3.16k/3.16k [00:00<00:00, 8.49kB/s]
Downloading [configuration.json]: 100%|██████████████████████████████████████████████████████████████████████| 73.0/73.0 [00:00<00:00, 176B/s]
Downloading [generation_config.json]: 100%|████████████████████████████████████████████████████████████████████| 181/181 [00:00<00:00, 387B/s]
Downloading [pytorch_model.bin.index.json]: 100%|████████████████████████████████████████████████████████| 21.9k/21.9k [00:00<00:00, 49.1kB/s]
Downloading [config.json]: 100%|█████████████████████████████████████████████████████████████████████████████| 594/594 [00:00<00:00, 1.26kB/s]
Downloading [tokenizer_config.json]: 100%|███████████████████████████████████████████████████████████████| 1.25k/1.25k [00:00<00:00, 2.21kB/s]
Downloading [tokenizer.json]: 100%|██████████████████████████████████████████████████████████████████████| 4.40M/4.40M [00:03<00:00, 1.33MB/s]
Processing 9 items: 78%|███████████████████████████████████████████████████████████████▊ | 7.00/9.00 [00:03<00:01, 1.61it/s]
Downloading [tokenizer_config.json]: 0%| | 0.00/1.25k [00:00<?, ?B/s]
Downloading [pytorch_model-00001-of-00002.bin]: 0%| | 6.00M/9.28G [00:03<1:08:33, 2.42MB/s]
Downloading [pytorch_model-00001-of-00002.bin]: 1%|▌ | 110M/9.28G [00:42<55:11, 2.98MB/s]
Downloading [pytorch_model-00002-of-00002.bin]: 0%| | 4.00M/3.59G [00:03<52:32, 1.22MB/s]
Downloading [pytorch_model-00002-of-00002.bin]: 2%|█▏ | 88.0M/3.59G [00:42<42:44, 1.47MB/s]
Downloading [tokenizer.json]: 100%|██████████████████████████████████████████████████████████████████████| 4.40M/4.40M [00:03<00:00, 1.49MB/s]
6.2 修改脚本中模型的路径
下载完成后,默认在C:\Users\Administrator.cache\modelscope\hub\models\deepseek-ai目录下,将deepseek-llm-7b-chat文件夹复制到自定义的文件夹model下。
修改test.py脚本
#使用transformer加载模型
from transformers import AutoTokenizer, AutoModelForCausalLM
#加载本地模型路径
model_path = "D:\AI\model\deepseek-llm-7b-chat"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(
model_path,
device_map="balanced_low_0",
torch_dtype='float16'
)
prompt = "请给一个deepseek的搭建步骤"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(
**inputs,
max_new_tokens=1000,
do_sample=True,
temperature=0.8
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
执行脚本
# 激活deepseek环境
conda activate deepseek
cd D:\AI\scripts
# 执行脚本
python test.py