{"id":364,"date":"2025-10-14T14:24:51","date_gmt":"2025-10-14T06:24:51","guid":{"rendered":"https:\/\/www.liaoxinghui.com\/?p=364"},"modified":"2025-10-14T14:24:52","modified_gmt":"2025-10-14T06:24:52","slug":"ubuntu%e4%bd%bf%e7%94%a8vllm%e9%83%a8%e7%bd%b2%e5%a4%a7%e6%a8%a1%e5%9e%8b%e5%8f%8a%e8%b0%83%e4%bc%98","status":"publish","type":"post","link":"https:\/\/www.liaoxinghui.com\/?p=364","title":{"rendered":"Ubuntu\u901a\u8fc7VLLM\u90e8\u7f72\u6a21\u578b"},"content":{"rendered":"<p class=\"wp-block-paragraph\">  \u5728\u4e0a\u4e00\u7bc7\u5e16\u5b50\u91cc\u8bf4\u4e86\u5982\u4f55\u5b89\u88c5\u663e\u5361\u9a71\u52a8<\/p>\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"mntrgtl56e\"><a href=\"https:\/\/www.liaoxinghui.com\/gpu%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85%e6%98%be%e5%8d%a1%e9%a9%b1%e5%8a%a8.html\">\u65b0GPU\u670d\u52a1\u5668\u5b89\u88c5NVDIA\u663e\u5361\u9a71\u52a8<\/a><\/blockquote>\n<iframe loading=\"lazy\" class=\"wp-embedded-content\" title=\"\u300a \u65b0GPU\u670d\u52a1\u5668\u5b89\u88c5NVDIA\u663e\u5361\u9a71\u52a8 \u300b\u2014\u65e0\u53cc\u7684\u4e2a\u4eba\u535a\u5ba2\" src=\"https:\/\/www.liaoxinghui.com\/gpu%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85%e6%98%be%e5%8d%a1%e9%a9%b1%e5%8a%a8.html\/embed#?secret=djvGwO1Xj9#?secret=mntrgtl56e\" width=\"600\" height=\"338\" frameborder=\"0\"><\/iframe>\n<\/div><\/figure>\n<p class=\"wp-block-paragraph\"> \u73b0\u5728\u6211\u4eec\u6765\u901a\u8fc7VLLM\u6765\u90e8\u7f72\u81ea\u5df1\u7684\u5927\u6a21\u578b\u628a<\/p>\n<p class=\"wp-block-paragraph\">\u9996\u5148\u662f\u5404\u79cd\u6a21\u578b\u7684\u83b7\u53d6\uff0c\u54ea\u79cd\u7c7b\u578b\u7684\u4efb\u52a1\u9002\u5408\u7684\u6a21\u578b\u90fd\u4e0d\u540c\uff0c\u8fd9\u91cc\u9700\u8981\u5927\u5bb6\u81ea\u5df1\u505a\u505a\u529f\u8bfe\u5566<\/p>\n<p class=\"wp-block-paragraph\">\u5927\u540d\u9f0e\u9f0e\u7684ollama\u5c31\u4e0d\u591a\u4ecb\u7ecd\u5566<\/p>\n<p class=\"wp-block-paragraph\"><a href=\"http:\/\/ollama.com\/library\" target=\"_blank\" rel=\"noopener\">https:\/\/ollama.com\/library<\/a><\/p>\n<p class=\"wp-block-paragraph\">\u963f\u91cc\u767e\u70bc<\/p>\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/bailian.console.aliyun.com\/?tab=model#\/model-market\" target=\"_blank\" rel=\"noopener\">https:\/\/bailian.console.aliyun.com\/?tab=model#\/model-market<\/a><\/p>\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/huggingface.co\/models\" target=\"_blank\" rel=\"noopener\">huggingface<\/a>\u61c2\u7684\u90fd\u61c2<\/p>\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/huggingface.co\/models\" target=\"_blank\" rel=\"noopener\">https:\/\/huggingface.co\/models<\/a><\/p>\n<p class=\"wp-block-paragraph\">\u9b54\u642d\u793e\u533a<\/p>\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/modelscope.cn\/home\" target=\"_blank\" rel=\"noopener\">https:\/\/modelscope.cn\/home<\/a><\/p>\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u5168\u90e8\u8fc7\u7a0b\u57fa\u4e8e <strong>Ubuntu 22.04 + RTX 3090 + Python \u73af\u5883<\/strong>\u3002<\/p>\n<\/blockquote>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2 class=\"wp-block-heading\"><strong>\u7b2c 1 \u6b65\uff1a\u51c6\u5907 Python \u73af\u5883<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">\u5efa\u8bae\u4f7f\u7528 <strong>\u865a\u62df\u73af\u5883<\/strong> \u6765\u907f\u514d\u6c61\u67d3\u7cfb\u7edf Python\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528conda\uff0c\u5177\u4f53\u770b\u4f60\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install -y python3-venv python3-pip\npython3 -m venv vllm_env\nsource vllm_env\/bin\/activate<\/pre>\n<p class=\"wp-block-paragraph\">\u786e\u8ba4 Python\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python --version\n# \u5efa\u8bae Python \u2265 3.10<\/pre>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2 class=\"wp-block-heading\"><strong>\u7b2c 2 \u6b65\uff1a\u5b89\u88c5 VLLM<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">\u76f4\u63a5\u5b89\u88c5\u6700\u65b0\u7248\uff08\u5305\u542b CUDA \u652f\u6301\uff09\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install --upgrade pip\npip install vllm<\/pre>\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u5efa\u8bae\u6362\u6e05\u534e\u6e90\uff1a<\/p>\n<\/blockquote>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple vllm<\/pre>\n<p class=\"wp-block-paragraph\">\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u68c0\u67e5\u7248\u672c\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python -m vllm.entrypoints.api_server --help<\/pre>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2 class=\"wp-block-heading\"><strong>\u7b2c 3 \u6b65\uff1a\u9009\u62e9\u5e76\u4e0b\u8f7d\u4e00\u4e2a\u6a21\u578b<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u4ee5\u5148\u4ece Hugging Face \u4e0a\u9009\u4e00\u4e2a\u5c0f\u6a21\u578b\u6d4b\u8bd5\uff0c\u6bd4\u5982\uff1a<\/p>\n<ul class=\"wp-block-list\">\n<li>&#8220;facebook\/opt-1.3b&#8221;\uff08\u5c0f\uff0c\u5bb9\u6613\u8dd1\uff09<\/li>\n\n<li>&#8220;meta-llama\/Llama-2-7b-chat-hf&#8221;\uff083090 \u4e5f\u80fd\u8dd1\uff09<\/li>\n\n<li>&#8220;Qwen\/Qwen2-7B-Instruct&#8221;\uff08\u56fd\u4ea7\u6a21\u578b\uff09<\/li>\n\n<li>&#8220;mistralai\/Mistral-7B-Instruct-v0.2&#8221;<\/li>\n<\/ul>\n<p class=\"wp-block-paragraph\">VLLM \u652f\u6301\u76f4\u63a5\u4ece Hugging Face \u81ea\u52a8\u4e0b\u8f7d\u3002<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2 class=\"wp-block-heading\"><strong>\u7b2c 4 \u6b65\uff1a\u542f\u52a8 VLLM \u670d\u52a1\uff08API \u6a21\u5f0f\uff09<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">\u6bd4\u5982\u6211\u4eec\u7528 <strong>Qwen2-7B-Instruct<\/strong>\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python -m vllm.entrypoints.api_server \\\n  --model Qwen\/Qwen2-7B-Instruct \\\n  --host 0.0.0.0 \\\n  --port 8000<\/pre>\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\u7c7b\u4f3c\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">INFO  vllm.engine: Initializing model: Qwen\/Qwen2-7B-Instruct\nINFO  vllm.api_server: Starting server at http:\/\/0.0.0.0:8000<\/pre>\n<p class=\"wp-block-paragraph\">\u8bf4\u660e\u542f\u52a8\u6210\u529f <\/p>\n<p class=\"wp-block-paragraph\">VLLM \u4f1a\u81ea\u52a8\u52a0\u8f7d\u6743\u91cd\uff08\u7b2c\u4e00\u6b21\u542f\u52a8\u4f1a\u4e0b\u8f7d\u6a21\u578b\u5230 ~\/.cache\/huggingface\uff09\u3002<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2 class=\"wp-block-heading\"><strong>\u7b2c 5 \u6b65\uff1a\u6d4b\u8bd5 API \u662f\u5426\u6b63\u5e38<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">\u6253\u5f00\u53e6\u4e00\u4e2a\u7ec8\u7aef\uff08\u6216\u7528 curl \u6d4b\u8bd5\uff09\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl http:\/\/localhost:8000\/generate \\\n  -H \"Content-Type: application\/json\" \\\n  -d '{\"prompt\": \"\u5199\u4e00\u9996\u5173\u4e8e\u79cb\u5929\u7684\u8bd7\", \"max_tokens\": 100}'<\/pre>\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\u7c7b\u4f3c\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\"text\": \"\u79cb\u98ce\u8d77\uff0c\u843d\u53f6\u9ec4\uff0c\u5c71\u6cb3\u8fdc\uff0c\u601d\u6545\u4e61\u3002\"}<\/pre>\n<p class=\"wp-block-paragraph\">\u8bf4\u660e\u63a8\u7406\u6210\u529f <\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2 class=\"wp-block-heading\"><strong>\u7b2c 6 \u6b65\uff1aPython \u5185\u90e8\u8c03\u7528\uff08\u53ef\u9009\uff09<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u60f3\u76f4\u63a5\u5728 Python \u4e2d\u4f7f\u7528\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from vllm import LLM, SamplingParams\n\nllm = LLM(model=\"Qwen\/Qwen2-7B-Instruct\")\nparams = SamplingParams(temperature=0.7, max_tokens=128)\noutputs = llm.generate([\"\u4f60\u597d\uff0c\u8bf7\u4ecb\u7ecd\u4e00\u4e0b\u4f60\u81ea\u5df1\u3002\"], params)\n\nfor o in outputs:\n    print(o.outputs[0].text)<\/pre>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2 class=\"wp-block-heading\"><strong>\u7b2c 7 \u6b65\uff08\u53ef\u9009\uff09\uff1a\u6027\u80fd\u4f18\u5316\u5efa\u8bae<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">3090 \u53ea\u6709 24G \u663e\u5b58\uff0c\u4e24\u5f20\u5361\u53ef\u4ee5\u5229\u7528\u4ee5\u4e0b\u65b9\u5f0f\uff1a<\/p>\n<ul class=\"wp-block-list\">\n<li>\u542f\u52a8\u591a\u5b9e\u4f8b VLLM\uff0c\u6bcf\u5f20\u5361\u5206\u914d\u4e0d\u540c\u7684\u6a21\u578b\uff1b<\/li>\n\n<li>\u6216\u7528\u53c2\u6570 &#8211;tensor-parallel-size 2 \u8de8\u5361\u5206\u5e03\u52a0\u8f7d\u6a21\u578b\uff1a<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python -m vllm.entrypoints.api_server \\\n  --model Qwen\/Qwen2-7B-Instruct \\\n  --tensor-parallel-size 2<\/pre>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2 class=\"wp-block-heading\"><strong>\u7b2c 8 \u6b65\uff1a\u7ba1\u7406\u4e0e\u76d1\u63a7<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">\u5b9e\u65f6\u67e5\u770b\u663e\u5361\u5360\u7528\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">watch -n 1 nvidia-smi<\/pre>\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u60f3\u540e\u53f0\u8fd0\u884c\u670d\u52a1\uff0c\u53ef\u7528\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nohup python -m vllm.entrypoints.api_server --model Qwen\/Qwen2-7B-Instruct --port 8000 &gt; vllm.log 2&gt;&amp;1 &amp;<\/pre>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2 class=\"wp-block-heading\"><strong>\u603b\u7ed3\u547d\u4ee4\u901f\u67e5\u8868<\/strong><\/h2>\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>\u4efb\u52a1<\/strong><\/th>\n<th><strong>\u547d\u4ee4<\/strong><\/th><\/tr><\/thead>\n<tbody><tr><td>\u521b\u5efa\u73af\u5883<\/td>\n<td>python3 -m venv vllm_env &amp;&amp; source vllm_env\/bin\/activate<\/td><\/tr>\n<tr><td>\u5b89\u88c5 VLLM<\/td>\n<td>pip install vllm<\/td><\/tr>\n<tr><td>\u542f\u52a8\u670d\u52a1<\/td>\n<td>python -m vllm.entrypoints.api_server &#8211;model Qwen\/Qwen2-7B-Instruct &#8211;port 8000<\/td><\/tr>\n<tr><td>\u6d4b\u8bd5\u63a5\u53e3<\/td>\n<td>curl -X POST http:\/\/localhost:8000\/generate -d &#8216;{&#8220;prompt&#8221;:&#8221;\u4f60\u597d&#8221;}&#8217;<\/td><\/tr>\n<tr><td>\u76d1\u63a7\u663e\u5361<\/td>\n<td>watch -n 1 nvidia-smi<\/td><\/tr><\/tbody><\/table><\/figure>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<p class=\"wp-block-paragraph\"><\/p>","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e0a\u4e00\u7bc7\u5e16\u5b50\u91cc\u8bf4\u4e86\u5982\u4f55\u5b89\u88c5\u663e\u5361\u9a71\u52a8 \u73b0\u5728\u6211\u4eec\u6765\u901a\u8fc7VLLM\u6765\u90e8\u7f72\u81ea\u5df1\u7684\u5927\u6a21\u578b\u628a \u9996\u5148\u662f\u5404\u79cd\u6a21\u578b\u7684\u83b7\u53d6\uff0c\u54ea\u79cd\u7c7b\u578b\u7684\u4efb\u52a1\u9002\u5408\u7684\u6a21\u578b\u90fd\u4e0d\u540c\uff0c\u8fd9\u91cc &hellip;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-364","post","type-post","status-publish","format-standard","hentry","category-10"],"views":321,"_links":{"self":[{"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=\/wp\/v2\/posts\/364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=364"}],"version-history":[{"count":1,"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=\/wp\/v2\/posts\/364\/revisions"}],"predecessor-version":[{"id":365,"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=\/wp\/v2\/posts\/364\/revisions\/365"}],"wp:attachment":[{"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}