
self-llm 如何用 vLLM 部署 Step-3.5-Flash 并基于 Docker 镜像准备运行环境【免费下载链接】self-llm《开源大模型食用指南》针对中国宝宝量身打造的基于Linux环境快速微调全参数/Lora、部署国内外开源大模型LLM/多模态大模型MLLM教程项目地址: https://gitcode.com/GitHub_Trending/se/self-llmStep-3.5-Flash 是阶跃星辰推出的稀疏混合专家Sparse MoE模型1960 亿参数、激活约 110 亿。要把它跑成可调用的推理服务需要先准备好 vLLM 运行环境再用vllm serve把模型暴露为兼容 OpenAI 的 API 服务。本文按 self-llm 仓库中的 01-Step-3.5-Flash-vLLM部署教程.md 完成这条路径准备运行环境可直接使用 AutoDL 平台提供的 Docker 镜像也可用 pip 手动安装依赖→ 用 modelscope 下载模型 → 用 Transformers 验证模型 → 启动 vLLM 服务 → 用 requests 和 OpenAI SDK 调用接口确认部署成功。文档给出的基础环境是 ubuntu 22.04、python 3.12、cuda 12.4、pytorch 2.5.1并默认学习者已配置好 PyTorch (CUDA) 环境如未配置需先自行安装。环境准备两种搭建方式二选一方式一使用 AutoDL 的 Docker 镜像可选分支文档在“环境准备”一节说明考虑到部分同学配置环境可能会遇到一些问题项目在 AutoDL 平台准备了 Step-3.5-Flash 的环境镜像点击文档中给出的链接并直接创建 AutoDL 实例即可链接位于 01-Step-3.5-Flash-vLLM部署教程.md 的“环境准备”小节。走这条路径时文档中手动安装依赖的步骤可以直接跳过后续下载模型、启动服务的步骤与方式二完全一致。方式二手动安装依赖在已配置好 PyTorch (CUDA) 的环境中执行python -m pip install --upgrade pip pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple pip install modelscope pip install vllm --pre --extra-index-url https://wheels.vllm.ai/nightly注意pip config set global.index-url ...会把本机 pip 的默认索引源改为清华镜像影响此后所有pip install这是文档为加速国内下载给出的配置。两条安装命令中modelscope用于后续下载模型vllm使用--pre加 nightly 额外源安装预发布版本。用 modelscope 下载 Step-3.5-Flash 模型使用 modelscope 的snapshot_download函数下载模型第一个参数为模型名称参数cache_dir为模型的下载路径。新建model_download.py文件# model_download.py from modelscope import snapshot_download model_dir snapshot_download(stepfun-ai/Step-3.5-Flash, cache_dir/root/autodl-tmp, revisionmaster) print(f模型下载完成保存路径为{model_dir})python model_download.py需要等待一段时间直到下载完成。文档特别提示cache_dir要修改为你的模型下载路径。示例中的/root/autodl-tmp是 AutoDL 数据盘路径在其他机器上应换成自己可写的绝对路径。脚本结束时会打印“模型下载完成保存路径为{model_dir}”记下这个路径后续启动服务时会用到。用 Transformers 预先验证模型文档建议在正式用 vLLM 部署之前先用 Transformers 验证模型能否正常推理。新建transformers_inference.py文件其中MODEL_PATH注释已标明要修改为你的本地路径# transformers_inference.py from transformers import AutoModelForCausalLM, AutoTokenizer # 模型路径修改为你的本地路径 MODEL_PATH /root/autodl-tmp/stepfun-ai/Step-3.5-Flash # 1) 加载 tokenizer tokenizer AutoTokenizer.from_pretrained( MODEL_PATH, local_files_onlyTrue, trust_remote_codeTrue, ) # 2) 加载模型 model AutoModelForCausalLM.from_pretrained( MODEL_PATH, trust_remote_codeTrue, device_mapauto, local_files_onlyTrue, ) # 3) 构造对话消息 messages [{role: user, content: Explain the significance of the number 42.}] # 4) 应用 chat 模板 inputs tokenizer.apply_chat_template( messages, tokenizeTrue, add_generation_promptTrue, return_dictTrue, return_tensorspt, ).to(model.device) # 5) 生成文本 generated_ids model.generate( **inputs, max_new_tokens128, do_sampleTrue, temperature0.7, top_p0.9, ) # 6) 解码输出 gen_ids generated_ids[0][inputs.input_ids.shape[1]:] output_text tokenizer.decode(gen_ids, skip_special_tokensTrue) print(output_text)python transformers_inference.py文档给出的输出示例示例结果实际输出取决于模型采样Hmm, the user is asking about the significance of the number 42...终端能针对该问题打印出模型的回复文本说明下载下来的模型文件可以正常加载推理可以继续下一步 vLLM 部署。启动 vLLM 推理服务文档建议使用 vLLM 的最新 nightly 版本以获得最佳性能并在“vLLM 服务部署”一节给出了安装命令与“环境准备”一节的pip install vllm --pre ...二选一执行即可# 通过 pip 安装nightly 版本 pip install -U vllm --pre \ --index-url https://pypi.org/simple \ --extra-index-url https://wheels.vllm.ai/nightlyFP8 模型启动vllm serve /root/autodl-tmp/stepfun-ai/Step-3.5-Flash \ --served-model-name step3p5-flash \ --tensor-parallel-size 8 \ --disable-cascade-attn \ --reasoning-parser step3p5 \ --enable-auto-tool-choice \ --tool-call-parser step3p5 \ --trust-remote-code \ --quantization fp8BF16 模型启动BF16 启动命令在 FP8 基础上额外启用了专家并行与推测解码配置vllm serve /root/autodl-tmp/stepfun-ai/Step-3.5-Flash \ --served-model-name step3p5-flash \ --tensor-parallel-size 8 \ --enable-expert-parallel \ --disable-cascade-attn \ --reasoning-parser step3p5 \ --enable-auto-tool-choice \ --tool-call-parser step3p5 \ --hf-overrides {num_nextn_predict_layers: 1} \ --speculative_config {method: step3p5_mtp, num_speculative_tokens: 1} \ --trust-remote-code两条命令中的模型路径同样是 AutoDL 数据盘示例路径需替换为你的实际模型目录。参数说明文档对各参数的说明如下参数文档说明--served-model-name对外暴露的模型名称客户端调用时需使用此名称--tensor-parallel-size张量并行大小通常设置为 GPU 数量--enable-expert-parallel启用专家并行适用于 MoE 模型--disable-cascade-attn禁用级联注意力机制--reasoning-parser推理内容解析器用于解析模型的思考过程--enable-auto-tool-choice启用自动工具选择--tool-call-parser工具调用解析器--trust-remote-code允许加载自定义代码必需--quantization量化方式如 fp8--hf-overrides覆盖 HuggingFace 配置参数--speculative_config推测解码配置判断启动成功启动后日志中会先出现 vLLM 版本号、模型路径、解析到的模型架构等加载信息服务启动成功后将监听http://0.0.0.0:8000/v1日志中列出全部可用路由并等待请求文档提示由于模型较大首次加载过程时间较长可能在半个小时以上。参考显存占用文档附有启动后的参考显存截图 01-03.jpg 与 01-04.jpg可对照自己的环境。文档原文说明vLLM 尚未完全支持 MTP3官方正在开发 Pull Request 集成此功能预计将显著提升解码性能。启动命令中的--reasoning-parser step3p5等参数已按文档保留用于解析模型的思考过程。用 API 调用验证部署成功使用 requests 调用新建test_requests.py文件model字段需与启动时的--served-model-name一致# test_requests.py import requests url http://0.0.0.0:8000/v1/chat/completions headers {Content-Type: application/json} data { messages: [ {role: user, content: Explain the significance of the number 42.} ], model: step3p5-flash } response requests.post(url, headersheaders, jsondata) if response.status_code 200: result response.json() print(Response:, result[choices][0][message][content]) else: print(Error:, response.status_code, response.text)python test_requests.pyHTTP 状态码为 200 时脚本打印Response:及模型回复内容说明服务可用。文档给出的响应示例部分截取{ id: chatcmpl-9f51bb9294e6712a, object: chat.completion, created: 1770390777, model: step3p5-flash, choices: [ { index: 0, message: { role: assistant, content: The number **42** is most famously known as the **\Answer to the Ultimate Question of Life, the Universe, and Everything\** in Douglas Adams beloved sci-fi series *The Hitchhikers Guide to the Galaxy*. Its significance is both a hilarious absurdist joke and a cultural phenomenon..., reasoning_content: Hmm, the user is asking about the significance of the number 42. This is a classic pop culture reference, so theyre likely expecting an explanation tied to Douglas Adams *The Hitchhikers Guide to the Galaxy*... }, finish_reason: stop } ], usage: { prompt_tokens: 21, total_tokens: 982, completion_tokens: 961 } }注意响应中包含reasoning_content字段展示了模型的思考过程。使用 OpenAI SDK 调用Chat Completions新建test_chat.py文件# test_chat.py from openai import OpenAI client OpenAI( api_keyEMPTY, base_urlhttp://127.0.0.1:8000/v1, ) response client.chat.completions.create( modelstep3p5-flash, messages[ {role: user, content: Explain the significance of the number 42.} ] ) print(Response:, response.choices[0].message.content) print(\nReasoning:, response.choices[0].message.reasoning_content)python test_chat.py文档的输出示例示例结果Response: The number **42** is most famously known as the **Answer to the Ultimate Question of Life, the Universe, and Everything** in Douglas Adams beloved sci-fi series *The Hitchhikers Guide to the Galaxy*... Reasoning: Hmm, the user is asking about the significance of the number 42. This is a classic pop culture reference, so theyre likely expecting an explanation tied to Douglas Adams *The Hitchhikers Guide to the Galaxy*...在以上所有请求处理过程中API 后端都会打印相对应的日志和统计信息可据此观察服务运行状态。可选Completions 接口文档还提供了一个 Completions 接口示例新建test_completion.py# test_completion.py from openai import OpenAI client OpenAI( api_keyEMPTY, base_urlhttp://127.0.0.1:8000/v1, ) response client.completions.create( modelstep3p5-flash, prompt简要介绍一下 Step-3.5-Flash 模型。, max_tokens500, top_p0.95, temperature0.2, ) response_text response.choices[0].text print(response_text)边界说明与后续入口启动命令中已包含--enable-auto-tool-choice与--tool-call-parser step3p5服务支持工具调用文档附有天气查询的工具调用示例test_tool_calling.py其中 WeatherAPI 的api_key需替换为你自己的 key可回到 01-Step-3.5-Flash-vLLM部署教程.md 的“工具调用”小节查看完整代码。如果后续想改用 SGLang 框架部署同一模型仓库提供了 02-Step-3.5-Flash-SGLang.md环境要求与 vLLM 路线不同按该文档单独操作。【免费下载链接】self-llm《开源大模型食用指南》针对中国宝宝量身打造的基于Linux环境快速微调全参数/Lora、部署国内外开源大模型LLM/多模态大模型MLLM教程项目地址: https://gitcode.com/GitHub_Trending/se/self-llm创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考