以下是根据您提供的笔记整理而成的Markdown文档,内容涵盖了CUDA/cuDNN配置、Anaconda环境管理、Stable Diffusion及相关模型(如ChatGLM、Real-ESRGAN)的安装与部署,以及一些实用技巧。


Win11 + RTX3060 环境配置与AI项目部署笔记

1. CUDA 与 cuDNN 配置

1.1 下载与安装

1.2 环境变量

  • 系统环境变量中添加:

    • CUDA_PATH: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.5
    • %CUDA_PATH%\bin%CUDA_PATH%\libnvvp 添加到 Path 变量中。

2. Anaconda 配置

2.1 添加清华镜像源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --set show_channel_urls yes

2.2 修改默认环境与包位置

系统环境变量中添加:

  • CONDA_ENVS_PATH: E:\Anaconda\envs
  • CONDA_PKGS_DIRS: E:\Anaconda\pkgs

2.3 解决PowerShell无法加载conda

C:\ProgramData\anaconda3\Library\bin\conda.bat init powershell

3. Stable Diffusion WebUI 安装

3.1 创建Python环境

conda create -n stablediffusion python=3.10.6 -y
conda activate stablediffusion

3.2 安装PyTorch(GPU版)

# 使用CUDA 12.1版本
pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2+cu121 --index-url https://download.pytorch.org/whl/cu121

3.3 安装xformers

pip install xformers==0.0.23.post1 --index-url https://download.pytorch.org/whl/cu121

3.4 克隆项目并安装依赖

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui
pip install -r requirements.txt

3.5 修改启动脚本 webui-user.bat

set PYTHON="D:\Anaconda\envs\stablediffusion\python.exe"
set GIT=
set VENV_DIR="D:\Anaconda\envs\stablediffusion\"
set COMMANDLINE_ARGS=--xformers

3.6 启动

python launch.py --listen --enable-insecure-extension-access

3.7 模型放置路径

  • 主模型:models/Stable-diffusion/
  • VAE:models/VAE/
  • LoRA:models/lora/

4. ChatGLM2-6B 安装

4.1 创建环境

conda create -n chatglm2 python=3.10 -y
conda activate chatglm2

4.2 安装依赖

conda install ucrt==10.0.22621.0 cudatoolkit==11.8.0 cudnn==8.9.7.29 -y
pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2+cu121 --index-url https://download.pytorch.org/whl/cu121
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

4.3 解决numpy版本冲突

pip uninstall numpy -y
pip install numpy==1.26.4 -i https://pypi.tuna.tsinghua.edu.cn/simple

4.4 修改模型加载方式(根据显存调整)

# 6G显存
model = AutoModel.from_pretrained("model", trust_remote_code=True).half().quantize(4).cuda()
# 16G显存
model = AutoModel.from_pretrained("model", trust_remote_code=True).half().cuda()

4.5 启动Web界面

python web_demo.py

5. Real-ESRGAN 部署

5.1 克隆项目

git clone https://github.com/xinntao/Real-ESRGAN.git
cd Real-ESRGAN

5.2 创建环境与安装依赖

conda create -n realesrgan python=3.10 -y
conda activate realesrgan
conda install ucrt==10.0.22621.0 cudatoolkit==11.8.0 cudnn==8.9.7.29 -y
pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2+cu121 --index-url https://download.pytorch.org/whl/cu121
pip install basicsr==1.4.2 facexlib==0.3.0 gfpgan==1.3.8 opencv-python scipy tqdm pyyaml tb-nightly
pip install -r requirements.txt
python setup.py develop

5.3 修改模型加载路径

model_path='./gfpgan/weights/GFPGANv1.3.pth'

5.4 运行

python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs/0014.jpg --face_enhance

6. so-vits-svc 安装(声音转换)

6.1 克隆项目

git clone https://github.com/svc-develop-team/so-vits-svc.git
cd so-vits-svc

6.2 创建环境

conda create -n sovitssvc python=3.8.9 -y
conda activate sovitssvc

6.3 安装依赖

pip install -r requirements.txt

6.4 下载预训练模型

6.5 工具推荐


7. Ollama + Open WebUI 部署

7.1 创建环境

conda create -n ollama python=3.10.6 -y
conda activate ollama

7.2 安装CUDA依赖

conda install ucrt==10.0.22621.0 cudatoolkit==11.8.0 cudnn==9.1.1.17 -y

7.3 设置环境变量

conda env config vars set OLLAMA_HOST=0.0.0.0:11434 -n ollama
conda env config vars set OLLAMA_MODELS=E:\Anaconda\envs\ollamaai\models -n ollama

7.4 Docker运行

docker run -d -p 3000:8080 -p 11434:11434 --gpus=all -v D:/ProgramFiles/docker/data/ollama:/root/.ollama -v D:/ProgramFiles/docker/data/ollama/open-webui:/app/backend/data --name ollama ollama/ollama

8. 实用技巧与命令

8.1 查看CUDA是否可用

import torch
print(torch.cuda.is_available())

8.2 解决numpy版本过高问题

pip uninstall numpy -y
pip install numpy==1.26.4

8.3 解决fbgemm.dll报错

  • 下载 libomp140_x86_64.dll 放入 C:\Windows\System32

8.4 镜像加速

  • HuggingFace:https://hf-mirror.com/
  • GitHub:https://ghproxy.com/https://kkgithub.com/

8.5 修改环境变量

conda env config vars list
conda env config vars set my_test=123 -n env_name
conda env config vars unset my_test

9. 常用模型下载链接

模型下载地址
Stable Diffusion 1.5v1-5-pruned-emaonly.safetensors
Anything v4.0anything-v4.0-pruned-fp16.ckpt
GFPGAN模型GFPGANv1.3.pth
52G模型合集magnet:?xt=urn:btih:5bde442da86265b670a3e5ea3163afad2c6f8ecc&dn=novelaileak

10. 常见问题与解决

10.1 xformers版本不匹配

  • 确保PyTorch版本为 2.1.2+cu121
  • 安装 xformers==0.0.23.post1

10.2 gradio版本冲突

pip uninstall gradio
pip install gradio==3.41.2

10.3 显存不足

  • 添加启动参数:--lowvram --precision full --no-half

11. 其他资源


如果需要进一步整理或补充其他内容,请告诉我!

标签: none

添加新评论