{"id":1078,"date":"2025-12-08T20:46:51","date_gmt":"2025-12-08T12:46:51","guid":{"rendered":"https:\/\/gjweb.top\/?p=1078"},"modified":"2025-12-08T20:46:55","modified_gmt":"2025-12-08T12:46:55","slug":"vllm%e5%a4%a7%e6%a8%a1%e5%9e%8b%e9%83%a8%e7%bd%b2","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=1078","title":{"rendered":"vllm\u5927\u6a21\u578b\u90e8\u7f72"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">vllm \u548c ollma \u4f18\u7f3a\u70b9<\/h2>\n\n\n\n<p>VLLM \u548c Ollama \u662f\u4e24\u4e2a\u9488\u5bf9<strong>\u5927\u578b\u8bed\u8a00\u6a21\u578b (LLM) \u63a8\u7406\u548c\u90e8\u7f72<\/strong>\u7684\u6d41\u884c\u5de5\u5177\uff0c\u4f46\u5b83\u4eec\u5728<strong>\u8bbe\u8ba1\u76ee\u6807\u3001\u6838\u5fc3\u529f\u80fd\u548c\u9002\u7528\u573a\u666f<\/strong>\u4e0a\u5b58\u5728\u663e\u8457\u533a\u522b\u3002<\/p>\n\n\n\n<p>\u4e3b\u8981\u5bf9\u6bd4\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>\u7279\u6027<\/strong><\/th><th><strong>VLLM (Virtual Large Language Model)<\/strong><\/th><th><strong>Ollama<\/strong><\/th><\/tr><\/thead><tbody><tr><td><strong>\u6838\u5fc3\u5b9a\u4f4d<\/strong><\/td><td><strong>\u9ad8\u6027\u80fd\u3001\u9ad8\u541e\u5410\u91cf\u7684 LLM \u63a8\u7406\u548c\u670d\u52a1\u5f15\u64ce\u3002<\/strong><\/td><td><strong>\u672c\u5730\u3001\u4fbf\u6377\u5730\u8fd0\u884c LLM \u7684\u5de5\u5177\u548c\u6846\u67b6\u3002<\/strong><\/td><\/tr><tr><td><strong>\u4e3b\u8981\u76ee\u6807<\/strong><\/td><td><strong>\u6700\u5927\u5316 GPU \u5229\u7528\u7387\u548c\u63a8\u7406\u541e\u5410\u91cf\uff0c\u964d\u4f4e\u670d\u52a1\u5ef6\u8fdf\u3002<\/strong> \u9002\u7528\u4e8e\u5927\u89c4\u6a21\u3001\u9ad8\u5e76\u53d1\u7684\u751f\u4ea7\u73af\u5883\u3002<\/td><td><strong>\u7b80\u5316\u672c\u5730 LLM \u7684\u4e0b\u8f7d\u3001\u5b89\u88c5\u548c\u8fd0\u884c\u8fc7\u7a0b\u3002<\/strong> \u9002\u7528\u4e8e\u4e2a\u4eba\u7528\u6237\u3001\u5f00\u53d1\u8005\u3001\u672c\u5730\u5b9e\u9a8c\u3002<\/td><\/tr><tr><td><strong>\u6838\u5fc3\u6280\u672f<\/strong><\/td><td>\u91c7\u7528\u521b\u65b0\u6280\u672f\uff0c\u5982 <strong>PagedAttention<\/strong>\uff08\u9ad8\u6548\u5185\u5b58\u7ba1\u7406\uff09\u548c<strong>\u8fde\u7eed\u6279\u5904\u7406 (Continuous Batching)<\/strong>\uff0c\u4ee5\u4f18\u5316 LLM \u63a8\u7406\u901f\u5ea6\u548c\u6548\u7387\u3002<\/td><td>\u62bd\u8c61\u5316\u590d\u6742\u7684\u4f9d\u8d56\u9879\u548c\u914d\u7f6e\uff0c\u63d0\u4f9b\u7b80\u5355\u7684<strong>\u547d\u4ee4\u884c\u63a5\u53e3<\/strong>\u548c<strong>REST API<\/strong>\uff0c\u7528\u4e8e\u62c9\u53d6\u3001\u8fd0\u884c\u548c\u7ba1\u7406\u6a21\u578b\u3002<\/td><\/tr><tr><td><strong>\u6027\u80fd<\/strong><\/td><td><strong>\u6781\u9ad8\u3002<\/strong> \u5728\u541e\u5410\u91cf\u548c\u5ef6\u8fdf\u65b9\u9762\u901a\u5e38\u4f18\u4e8e\u8bb8\u591a\u5176\u4ed6\u63a8\u7406\u6846\u67b6\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u957f\u5e8f\u5217\u548c\u9ad8\u5e76\u53d1\u8bf7\u6c42\u65f6\u3002<\/td><td><strong>\u4e2d\u7b49\u5230\u826f\u597d\u3002<\/strong> \u4e13\u6ce8\u4e8e\u6613\u7528\u6027\uff0c\u6027\u80fd\u4f18\u5316\u4e0d\u5982 VLLM \u6fc0\u8fdb\uff0c\u4f46\u5bf9\u4e8e\u5355\u7528\u6237\u6216\u672c\u5730\u4f7f\u7528\u6765\u8bf4\u8db3\u591f\u5feb\u3002<\/td><\/tr><tr><td><strong>\u6613\u7528\u6027<\/strong><\/td><td>\u9700\u8981\u4e00\u5b9a\u7684\u73af\u5883\u914d\u7f6e\u548c\u5bf9\u9ad8\u6027\u80fd\u8ba1\u7b97\u7684\u7406\u89e3\uff0c\u901a\u5e38\u7528\u4e8e<strong>\u4e13\u4e1a\u90e8\u7f72<\/strong>\u3002<\/td><td><strong>\u975e\u5e38\u7b80\u5355\u6613\u7528\u3002<\/strong> \u51e0\u6761\u547d\u4ee4\u5c31\u53ef\u4ee5\u5728\u672c\u5730\u542f\u52a8\u4e00\u4e2a LLM\u3002<\/td><\/tr><tr><td><strong>\u6a21\u578b\u683c\u5f0f<\/strong><\/td><td><strong>\u652f\u6301 Hugging Face \u683c\u5f0f<\/strong>\u7684\u5927\u591a\u6570\u6d41\u884c\u6a21\u578b\u3002<\/td><td>\u4e3b\u8981\u652f\u6301 <strong>GGUF \u683c\u5f0f<\/strong>\u7684\u6a21\u578b\uff08\u4e00\u79cd\u9488\u5bf9 CPU\/GPU \u6df7\u5408\u4f18\u5316\u7684\u683c\u5f0f\uff09\uff0c\u4e5f\u652f\u6301\u4ece\u5176\u4ed6\u683c\u5f0f\u5bfc\u5165\u3002<\/td><\/tr><tr><td><strong>\u90e8\u7f72\u73af\u5883<\/strong><\/td><td>\u901a\u5e38\u90e8\u7f72\u5728\u5177\u5907<strong>\u9ad8\u6027\u80fd GPU<\/strong> \u7684\u670d\u52a1\u5668\u6216\u4e91\u73af\u5883\u4e0a\u3002<\/td><td>\u9002\u7528\u4e8e\u4e2a\u4eba\u7535\u8111\uff08<strong>macOS, Windows, Linux<\/strong>\uff09\u548c\u672c\u5730\u73af\u5883\uff0c\u5bf9\u786c\u4ef6\u8981\u6c42\u76f8\u5bf9\u8f83\u4f4e\uff08\u4f46\u4ecd\u4f9d\u8d56 GPU\/CPU \u6027\u80fd\uff09\u3002<\/td><\/tr><tr><td><strong>API<\/strong><\/td><td>\u63d0\u4f9b <strong>OpenAI \u517c\u5bb9\u7684 API \u670d\u52a1\u5668<\/strong>\uff0c\u65b9\u4fbf\u96c6\u6210\u3002<\/td><td>\u63d0\u4f9b\u4e00\u4e2a\u7b80\u5355\u7684 <strong>REST API<\/strong>\uff0c\u4e5f\u65b9\u4fbf\u4e0e\u5404\u79cd\u5e94\u7528\u96c6\u6210\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>VLLM\u53ea\u80fd\u7528\u4e8e GPU \u670d\u52a1\u5668\uff0c\u4e14\u5fc5\u987b\u662f linux \u7cfb\u7edf\u4e0b\u8fd0\u884c\uff0c\u53ef\u5c06\u5e76\u53d1\u548c\u63a8\u7406\u541e\u5410\u91cf\u53d1\u6325\u5230\u6700\u5927<\/strong><\/p>\n\n\n\n<p><strong>ollam \u66f4\u9002\u5408\u7528\u4e8e\u4e2a\u4eba\u7535\u8111\u642d\u5efa\u81ea\u5df1\u7684\u77e5\u8bc6\u5e93\uff0c\u5b89\u88c5\u65b9\u6cd5\u66f4\u52a0\u7b80\u5355\u6613\u7528\uff0c\u4f46\u541e\u5410\u91cf\u548c\u5e76\u53d1\u6570\u6027\u80fd\u6709\u74f6\u9888<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b89\u88c5\u524d\u63d0<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>linux \u7cfb\u7edf\uff0cunbutu\uff08\u63a8\u8350\uff09<\/li>\n\n\n\n<li>conda \u3001python>=3.10 \u4ee5\u4e0a<\/li>\n\n\n\n<li>\u9700\u8981 GPU \u786c\u4ef6\u652f\u6301 NVIDIA \u663e\u5361<\/li>\n\n\n\n<li>CUDA<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b89\u88c5\u8fc7\u7a0b<\/h2>\n\n\n\n<p>\u521b\u5efa conda \u6c99\u76d2\uff0c\u6fc0\u6d3b vllm_env<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">conda create -n vllm_env python=3.10 -y<br>conda activate vllm_env<\/pre>\n\n\n\n<p>\u4e0b\u8f7d vllm<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pip install vllm<\/pre>\n\n\n\n<p>\u9700\u8981\u7b49\u5f85\u5f88\u957f\u4e00\u6bb5\u65f6\u95f4\u7684\u5b89\u88c5\u8fc7\u7a0b<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u90e8\u7f72deepseek1.5 \uff084060 8G\u663e\u5361\u6d4b\u8bd5\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">python -m vllm.entrypoints.openai.api_server \\<br> &nbsp; &nbsp;--model deepseek-ai\/DeepSeek-R1-Distill-Qwen-1.5B \\<br> &nbsp; &nbsp;--trust-remote-code \\<br> &nbsp; &nbsp;--gpu-memory-utilization 0.85 \\<br> &nbsp; &nbsp;--tensor-parallel-size 1 \\<br> &nbsp; &nbsp;--dtype bfloat16 \\<br> &nbsp; &nbsp;--max-model-len 2048 \\<br> &nbsp; &nbsp;--port 8000<\/pre>\n\n\n\n<p><strong>vLLM \u671f\u671b\u663e\u5b58\u7684\u8ba1\u7b97\u5173\u7cfb<\/strong>:<\/p>\n\n\n\n<p>$$\\text{vLLM \u671f\u671b\u663e\u5b58} \\approx (\\text{\u6a21\u578b\u6743\u91cd}) + (\\text{KV \u7f13\u5b58})$$<\/p>\n\n\n\n<p>\u5f53 $6.92 \\text{ GiB} &lt; \\text{vLLM \u671f\u671b\u663e\u5b58}$ \u65f6\uff0c\u5c31\u4f1a\u62a5\u9519\u3002\u964d\u4f4e <code>--max-model-len<\/code> \u6216 <code>--gpu-memory-utilization<\/code> \u90fd\u80fd\u51cf\u5c0f<strong>\u671f\u671b\u663e\u5b58<\/strong>\uff0c\u5e2e\u52a9\u670d\u52a1\u987a\u5229\u542f\u52a8\u3002<\/p>\n\n\n\n<p><strong>\u8fd0\u884c\u6210\u529f<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/raw.githubusercontent.com\/gongjianOnline\/ImgHosting\/main\/img\/8570106613b34313f8e2a8e4a95d2499.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/raw.githubusercontent.com\/gongjianOnline\/ImgHosting\/main\/img\/8570106613b34313f8e2a8e4a95d2499.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<p>\u8fd0\u884c\u7aef\u53e3\u53f7 <code>localhost:8000<\/code> \u670d\u52a1\u542f\u52a8\u6210\u529f\uff0cSwagger\u63a5\u53e3\u6587\u6863 <code>localhost:8000\/docs<\/code><\/p>\n\n\n\n<p>postMan \u6d4b\u8bd5\u5bf9\u8bdd<\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/raw.githubusercontent.com\/gongjianOnline\/ImgHosting\/main\/img\/a4390608ed6e6db1093f099783b20fb8.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/raw.githubusercontent.com\/gongjianOnline\/ImgHosting\/main\/img\/a4390608ed6e6db1093f099783b20fb8.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<p>postMan\u5f00\u542f\u6d41\u5f0f\u5bf9\u8bdd<\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/raw.githubusercontent.com\/gongjianOnline\/ImgHosting\/main\/img\/162071e2-1d65-4848-b1a9-96d9c243d2c1.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/raw.githubusercontent.com\/gongjianOnline\/ImgHosting\/main\/img\/162071e2-1d65-4848-b1a9-96d9c243d2c1.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u5e38\u89c1\u9519\u8bef<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/raw.githubusercontent.com\/gongjianOnline\/ImgHosting\/main\/img\/074a239c8ae34341dc2574f0097d6d61.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/raw.githubusercontent.com\/gongjianOnline\/ImgHosting\/main\/img\/074a239c8ae34341dc2574f0097d6d61.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<p>\u663e\u5b58\u7a7a\u95f4\u4e0d\u8db3\uff0c\u53ef\u964d\u4f4e\u76f8\u5173\u53c2\u6570<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> --gpu-memory-utilization 0.85 \\ &nbsp;# \u9ed8\u8ba4\u53c2\u6570 9<br>--max-model-len 2048 \\ # \u9ed8\u8ba4\u53c2\u6570 4096<\/pre>\n\n\n\n<p><code>--max-model-len<\/code> \u6307\u5b9a\u4e86 vLLM \u670d\u52a1\u80fd\u591f\u5904\u7406\u7684<strong>\u6700\u5927\u5e8f\u5217\u957f\u5ea6 (Maximum Sequence Length)<\/strong>\u3002\u8fd9\u4e2a\u957f\u5ea6\u5305\u62ec\u4e86\uff1a<\/p>\n\n\n\n<p>\u6700\u5927\u5e8f\u5217\u957f\u5ea6 = \u8f93\u5165\u63d0\u793a\u8bcd\u957f\u5ea6 + \u6700\u5927\u751f\u6210\u957f\u5ea6<\/p>\n\n\n\n<p><code>--gpu-memory-utilization<\/code> \u7684\u4f5c\u7528<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u53c2\u6570\u7684\u672c\u8d28\u662f\u4e00\u4e2a<strong>\u5b89\u5168\u9600 (Safety Valve)<\/strong>\uff0c\u5b83\u544a\u8bc9 vLLM\uff1a<strong>\u201c\u5728\u4f60\u7684\u542f\u52a8\u548c\u8fd0\u884c\u8fc7\u7a0b\u4e2d\uff0c\u6700\u591a\u53ea\u80fd\u4f7f\u7528 GPU \u603b\u663e\u5b58\u7684 X \u767e\u5206\u6bd4\u3002\u201d<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>vllm \u548c ollma \u4f18\u7f3a\u70b9 VLLM \u548c Ollama \u662f\u4e24\u4e2a\u9488\u5bf9\u5927\u578b\u8bed\u8a00\u6a21\u578b (LLM) \u63a8\u7406\u548c\u90e8\u7f72\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"class_list":["post-1078","post","type-post","status-publish","format-standard","hentry","category-llm"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/1078","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1078"}],"version-history":[{"count":1,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/1078\/revisions"}],"predecessor-version":[{"id":1079,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/1078\/revisions\/1079"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}