> 技术文档 > 大模型部署指南(Ollama、SGLang、vLLM、Open-WebUI)_sglang docker

大模型部署指南(Ollama、SGLang、vLLM、Open-WebUI)_sglang docker


文章目录

  • 引言
  • 一、Ollama
  • 二、SGLang
  • 三、vLLM
  • 四、Open-WebUI
    • 方式一:pip
    • 方式二:Docker
  • 附录:
    • 1. Docker镜像源仓库设置
    • 2. 关于Docker无法调用GPU问题,需安装nvidia-container-toolkit

引言

  1. 项目下载

    git clone https://github.com/deepseek-ai/DeepSeek-V3.git
  2. 下载模型权重,可以在HuggingFace或者魔搭社区下载模型权重,推荐使用魔搭社区。

    pip install modelscope
  3. 下载

    mkdir ./deepseekmodelscope download --model deepseek-ai/DeepSeek-V3 --local_dir ./deepseek

一、Ollama

  1. Ollama下载并安装

    curl -fsSL https://ollama.com/install.sh | sh
  2. 通过脚本启动服务

    systemctl start ollama
  3. Ollama 从远程仓库下载大模型到本地

    ollama pull deepseek-r1:671b
  4. 运行模型

    ollama run deepseek-r1:671b

二、SGLang

  1. SGLang环境搭建

    conda create -n sglang python=3.12pip install --upgrade pippip install sgl-kernel --force-reinstall --no-depspip install \"sglang[all]>=0.4.3.post2\" --find-links https://flashinfer.ai/whl/cu124/torch2.5/flashinfer-python
  2. 调用模型

    python3 -m sglang.launch_server --model /home/dell3660/llm/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
  3. OpenAI风格API调用DeepSeek-V3模型

    import openaiclient = openai.Client(base_url=\"http://127.0.0.1:30000/v1\", api_key=\"EMPTY\")response = client.chat.completions.create(model=\"default\",messages=[{\"role\":\"system\", \"content\": \"You are a helpful AI assistant\"},{\"role\":\"user\", \"content\": \"List 3 countries and their capitals.\"},],temperature=0,max_tokens=64,)print(response)

三、vLLM

  1. vLLM环境搭建
    conda create -n vllm python=3.12conda activate vllmpip install vllm
  2. python代码调用
    from vllm import LLM# For generative models (task=generate) onlyllm = LLM(model=deepseek-ai/DeepSeek-V3, task=\"generate\") # Name or path of your modeloutput = llm.generate(\"Hello, my name is\")print(output)

四、Open-WebUI

方式一:pip

  1. 创建虚拟环境
    conda create -n open-webui python=3.12conda activate open-webuipip install open-webui
  2. 开启服务
    open-webui serve

方式二:Docker

  1. 拉取镜像
    docker pull ghcr.io/open-webui/open-webui:main
  2. 运行容器
    CPU版
    docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main

    GPU版

    docker run -d -p 3000:8080 --gpus all --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:cuda
  3. 浏览器访问
    打开您的浏览器,并访问http://localhost:3000。

附录:

1. Docker镜像源仓库设置

  1. 修改/etc/docker/daemon.json
    # 修改文件sudo vim /etc/docker/daemon.json{ \"registry-mirrors\": [ \"https://x9r52uz5.mirror.aliyuncs.com\", \"https://dockerhub.icu\", \"https://docker.chenby.cn\", \"https://docker.1panel.live\", \"https://docker.awsl9527.cn\", \"https://docker.anyhub.us.kg\", \"https://dhub.kubesre.xyz\" ]}
  2. 重启
    sudo systemctl daemon-reloadsudo systemctl restart docker

2. 关于Docker无法调用GPU问题,需安装nvidia-container-toolkit

  • 软件源配置(可对软件源进行替换https://mirrors.ustc.edu.cn)
    curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | sed \'s#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g\' | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list# 安装nvidia-container-toolkitsudo apt-get updatesudo apt-get install -y nvidia-container-toolkit# 配置 Docker 使用 NVIDIA 容器工具包sudo systemctl restart docker