<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>GPU VRAM on KnightLi Blog</title>
        <link>https://knightli.com/en/tags/gpu-vram/</link>
        <description>Recent content in GPU VRAM on KnightLi Blog</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en</language>
        <lastBuildDate>Sat, 11 Jul 2026 10:30:00 +0800</lastBuildDate><atom:link href="https://knightli.com/en/tags/gpu-vram/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>How to calculate the cost of running Agent on a consumer-grade graphics card: electricity bill, depreciation and cost per task</title>
        <link>https://knightli.com/en/2026/07/11/consumer-gpu-agent-cost-electricity-depreciation-guide/</link>
        <pubDate>Sat, 11 Jul 2026 10:30:00 +0800</pubDate>
        
        <guid>https://knightli.com/en/2026/07/11/consumer-gpu-agent-cost-electricity-depreciation-guide/</guid>
        <description>&lt;p&gt;If you want to know whether a consumer-grade graphics card is worth running a local agent, you can&amp;rsquo;t just look at &amp;ldquo;how much the graphics card cost&amp;rdquo;, nor can you just compare the unit price per million tokens of the API. Agents will repeatedly call models, tools, and browsers; long contexts, failed retries, and idle standby will all change the actual cost.&lt;/p&gt;
&lt;p&gt;The most practical way is to split the cost into four items: electricity, hardware depreciation, supporting equipment and manual maintenance, and then calculate it according to &amp;ldquo;each successful task&amp;rdquo; and &amp;ldquo;per million output tokens&amp;rdquo; at the same time.&lt;/p&gt;
&lt;h2 id=&#34;first-determine-which-costs-you-want-to-calculate&#34;&gt;First determine which costs you want to calculate
&lt;/h2&gt;&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;caliber&lt;/th&gt;
          &lt;th&gt;Questions suitable to be answered&lt;/th&gt;
          &lt;th&gt;Items that are easily missed&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;incremental cost&lt;/td&gt;
          &lt;td&gt;I already have a game console. How much does it cost to run Agent in my spare time?&lt;/td&gt;
          &lt;td&gt;The graphics card is already there, is it included in the depreciation?&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;full cost&lt;/td&gt;
          &lt;td&gt;Is it cost-effective to purchase a machine specifically for local agents?&lt;/td&gt;
          &lt;td&gt;Host, memory, SSD, cooling and depreciation&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Cost per task&lt;/td&gt;
          &lt;td&gt;How much does it cost to automate a document and a code task?&lt;/td&gt;
          &lt;td&gt;Failure, retry, and manual review&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;throughput cost&lt;/td&gt;
          &lt;td&gt;What is the cost per million tokens to build a self-built inference service?&lt;/td&gt;
          &lt;td&gt;Enter token, KV cache and idle time&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;If the graphics card was originally used for gaming or other work, it would be more honest to calculate the incremental cost first; only when the entire machine is purchased for Agent, the depreciation of the entire machine is fully included.&lt;/p&gt;
&lt;h2 id=&#34;total-monthly-cost-formula&#34;&gt;Total monthly cost formula
&lt;/h2&gt;&lt;p&gt;Let’s use monthly caliber first, the data is easiest to obtain:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;5
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;6
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;月度总成本 = 电费 + 硬件月折旧 + 配套服务费 + 人工维护成本
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;电费 = 实测整机平均功耗(kW) × 实际运行小时数 × 电价(元/kWh)
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;硬件月折旧 = (购入总价 - 预估残值) ÷ 使用月数
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;单次成功任务成本 = 月度总成本 ÷ 月成功任务数
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;每百万输出 token 成本 = 月度总成本 ÷ 月输出 token 数 × 1,000,000
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;The &amp;ldquo;average power consumption of the entire machine&amp;rdquo; should come from a socket power meter or UPS as much as possible, rather than just looking at the graphics card&amp;rsquo;s nominal TBP. The Agent also runs with CPU, memory, SSD, fans, and monitors; using only GPU power consumption will underestimate the electricity bill. Conversely, periods when the machine is on standby but not processing tasks should not be mixed into pure inference costs and is best recorded separately.&lt;/p&gt;
&lt;h2 id=&#34;an-example-of-replaceable-parameters&#34;&gt;An example of replaceable parameters
&lt;/h2&gt;&lt;p&gt;Assume that a machine has a measured average power consumption of 280W under the actual Agent workload, runs 6 hours a day, and 30 days a month; the local electricity price is calculated as 0.8 yuan/kWh. The hardware purchased specifically for this purpose is amortized over 7,000 yuan, 36 months, and the residual value is ignored.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;电费 = 0.28 × 6 × 30 × 0.8 = 40.32 元/月
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;硬件折旧 = 7,000 ÷ 36 = 194.44 元/月
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;月度基础成本 = 234.76 元/月
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;If 600 accepted tasks are completed this month, the basic cost will be approximately 0.39 yuan/task. The &amp;ldquo;completion&amp;rdquo; here cannot only be counted as model return; it should be based on business results such as successful script execution, work order closing, and manual inspection passing.&lt;/p&gt;
&lt;p&gt;This is just an example calculation, not a universal price. It only makes sense to replace power consumption, usage time, electricity price, purchase amount and task volume with your own data.&lt;/p&gt;
&lt;h2 id=&#34;why-is-agent-more-difficult-to-estimate-than-regular-chat&#34;&gt;Why is Agent more difficult to estimate than regular chat?
&lt;/h2&gt;&lt;p&gt;Chat models are often billed by token, and the cost of Agent is also affected by the execution path:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A task may include planning, retrieval, calling tools, reading results, and multiple rounds of corrections.&lt;/li&gt;
&lt;li&gt;The longer the context, the more KV cache is occupied; when there is insufficient video memory, it will slow down, unload the CPU/RAM, and even trigger retries.&lt;/li&gt;
&lt;li&gt;Browser automation, code testing, and file processing can stretch task times even if the GPU is not constantly fully loaded.&lt;/li&gt;
&lt;li&gt;Multi-Agent parallelization will increase throughput, but may also increase memory contention, queuing, and failure rates.&lt;/li&gt;
&lt;li&gt;In order to reduce the first token delay, resident model will increase idle power consumption.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Therefore, do not use the tokens/s of a short question and answer to represent the Agent cost. Select at least a set of real tasks, run them continuously for a week, and record input/output tokens, success rate, number of retries, wall clock time, and overall machine power consumption.&lt;/p&gt;
&lt;h2 id=&#34;two-units-that-must-be-seen-at-the-same-time&#34;&gt;Two units that must be seen at the same time
&lt;/h2&gt;&lt;h3 id=&#34;every-successful-task&#34;&gt;every successful task
&lt;/h3&gt;&lt;p&gt;This is closest to business decisions. It is suitable for comparing fixed processes such as &amp;ldquo;local agent automatically processes PR&amp;rdquo;, &amp;ldquo;batch data collection&amp;rdquo;, &amp;ldquo;customer service draft generation&amp;rdquo;, etc.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;每个成功任务成本 = (本周期全部成本) ÷ 成功且验收通过的任务数
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Failed tasks cannot be deleted from the numerator. The power, inference time, and manual troubleshooting they consume are the true operating costs of local systems.&lt;/p&gt;
&lt;h3 id=&#34;per-million-tokens&#34;&gt;per million tokens
&lt;/h3&gt;&lt;p&gt;This is suitable for comparing on-premises inference services and cloud APIs, but distinguishing between inputs and outputs. The input of many agents includes long tool logs and historical context, and the input tokens are much more than the output tokens; if divided by the output tokens only, the number will be high. A more reliable approach is to record input, output and total tokens at the same time, and maintain the same statistical caliber.&lt;/p&gt;
&lt;h2 id=&#34;how-to-collect-your-own-data&#34;&gt;How to collect your own data
&lt;/h2&gt;&lt;p&gt;There is no need to build a complex monitoring system from the beginning. First create a table and record the following fields for each run:&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Field&lt;/th&gt;
          &lt;th&gt;Recording method&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;start and end time&lt;/td&gt;
          &lt;td&gt;Agent log or task queue&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Whole machine power consumption&lt;/td&gt;
          &lt;td&gt;Smart outlet, power meter or UPS&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;input/output token&lt;/td&gt;
          &lt;td&gt;Inference service logs or client statistics&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Success, failure, retry&lt;/td&gt;
          &lt;td&gt;Task status and error log&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Manual review time&lt;/td&gt;
          &lt;td&gt;Work order, PR or random inspection record&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Model and quantified version&lt;/td&gt;
          &lt;td&gt;Avoid mixing different models in the same set of data&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Start with 20 to 50 representative tasks as a baseline. Then, tasks with short contexts, long contexts, many tool calls, and many retries are tested separately to see the impact of memory and model selection on costs. Video memory planning can be judged in conjunction with &lt;a class=&#34;link&#34; href=&#34;https://knightli.com/en/2026/07/11/rtx-3060-qwen3-best-quantization-guide/&#34; &gt;Local Model Quantification and Video Memory Selection&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;how-to-calculate-depreciation-so-as-not-to-mislead-yourself&#34;&gt;How to calculate depreciation so as not to mislead yourself
&lt;/h2&gt;&lt;p&gt;There is no one answer to depreciation, but the assumptions must be written down first.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Existing graphics card: You can only calculate the electricity bill and additional maintenance as incremental costs; you can also set an opportunity cost for the graphics card as a more conservative full cost.&lt;/li&gt;
&lt;li&gt;New equipment purchased: Graphics card, host, memory, SSD, and radiator should be included together; don’t just spread the price of the graphics card.&lt;/li&gt;
&lt;li&gt;Lifespan: 24, 36 or 48 months will work, the key is comparing on-premises vs. cloud using the same assumptions.&lt;/li&gt;
&lt;li&gt;Residual value: When the equipment is expected to be resold, the estimated residual value can be deducted from the purchase price; if it is uncertain, set it to 0, and the conclusion is more conservative.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;NAS or small hosts usually consume less power, but memory, cooling, and expansion capabilities also limit models and concurrency. If you consider this route, you can first read &lt;a class=&#34;link&#34; href=&#34;https://knightli.com/en/2026/07/11/nas-ollama-performance-cpu-memory-gpu-guide/&#34; &gt;Performance Judgment of NAS Deployment Ollama&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;when-comparing-to-cloud-apis-dont-just-compare-unit-price&#34;&gt;When comparing to cloud APIs, don’t just compare unit price
&lt;/h2&gt;&lt;p&gt;The cloud side can also be converted into cost per task:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;云端每任务成本 = 模型 API 费用 + 工具/API 费用 + 必要的存储与网络费用 + 人工复核成本
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Local is usually better suited for these situations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;There is a stable and predictable workload every day, and machine utilization is high.&lt;/li&gt;
&lt;li&gt;Data cannot or is not expected to be sent to external services.&lt;/li&gt;
&lt;li&gt;Already have a working GPU, the incremental cost is mainly electricity.&lt;/li&gt;
&lt;li&gt;Self-maintainable models, drivers, service and crash recovery are acceptable.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The cloud is often better suited for these situations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The load is sporadic and the machine will be idle most of the time.&lt;/li&gt;
&lt;li&gt;Tasks require large models, very long contexts, or peak concurrency that far exceed local video memory.&lt;/li&gt;
&lt;li&gt;The team is unwilling to take on the driver, model upgrades, monitoring and troubleshooting.&lt;/li&gt;
&lt;li&gt;The task results are of high value, and the strongest model or multi-modal capabilities are required first.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Local deployment is not just a choice between two options. Stable, privacy-sensitive steps are placed locally; complex, low-frequency steps or steps that require stronger models are called to the cloud, which is often easier to control the total cost.&lt;/p&gt;
&lt;h2 id=&#34;a-practical-decision-line&#34;&gt;A practical decision line
&lt;/h2&gt;&lt;p&gt;Record the local monthly fixed cost as &lt;code&gt;F&lt;/code&gt;, the variable power and maintenance costs per task as &lt;code&gt;v&lt;/code&gt;, and the cloud per-task cost as &lt;code&gt;c&lt;/code&gt;. When &lt;code&gt;c &amp;gt; v&lt;/code&gt;, the approximate amount of tasks required to achieve local breakeven is:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;每月盈亏平衡任务数 = F ÷ (c - v)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;If &lt;code&gt;c&lt;/code&gt; is less than or close to &lt;code&gt;v&lt;/code&gt;, local will not be significantly cheaper due to scale; privacy, latency, controllability, and offline capabilities should be considered more at this time. This formula is only a financial filter and still requires failure rates and manual review time.&lt;/p&gt;
&lt;h2 id=&#34;common-misunderstandings&#34;&gt;Common misunderstandings
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Only look at the power consumption of the graphics card&lt;/strong&gt;: The power, standby and cooling of the entire machine also need to be paid.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Think of nominal tokens/s as throughput&lt;/strong&gt;: Real agents will be slowed down by context, tools, network, and test steps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ignore failed tasks&lt;/strong&gt;: The process that is retried most frequently is often a cost black hole.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Only model charges are calculated&lt;/strong&gt;: Browser, search, vector library, storage and human review charges may also apply.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mixing data from different models&lt;/strong&gt;: The quantization version, context length, and concurrency are different, and the results cannot be compared horizontally.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;summarize&#34;&gt;Summarize
&lt;/h2&gt;&lt;p&gt;The cost of running Agent on a consumer-grade graphics card should not just be answered by &amp;ldquo;a few kilowatt-hours of electricity per hour.&amp;rdquo; First use the measured power consumption of the entire machine to calculate the electricity cost, then add the hardware cost according to your own depreciation assumptions, and finally use the number of successful tasks and the amount of tokens to amortize it. After continuously recording a period of real workload, you can clearly judge whether to continue running locally, expand the video memory, or hand over some steps to the cloud API.&lt;/p&gt;
</description>
        </item>
        <item>
        <title>Whether the Ollama performance of NAS deployment is insufficient: how to judge the CPU, memory and graphics card</title>
        <link>https://knightli.com/en/2026/07/11/nas-ollama-performance-cpu-memory-gpu-guide/</link>
        <pubDate>Sat, 11 Jul 2026 09:40:43 +0800</pubDate>
        
        <guid>https://knightli.com/en/2026/07/11/nas-ollama-performance-cpu-memory-gpu-guide/</guid>
        <description>&lt;p&gt;NAS can deploy Ollama, but &amp;ldquo;can be installed&amp;rdquo; and &amp;ldquo;quick enough to use&amp;rdquo; are two different things.&lt;/p&gt;
&lt;p&gt;If the goal is to make occasional summaries, file Q&amp;amp;A, home automation and low-frequency API calls, x86 NAS can use CPU to run small models; if you want to have continuous conversations like chat software, run 7B/8B code models, or make multiple service calls, the key becomes video memory, memory and heat dissipation, not how many TB the hard drive has.&lt;/p&gt;
&lt;p&gt;Let’s give the conclusion first:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;**NAS without available GPU is suitable for small models and low-frequency tasks; only NVIDIA GPUs correctly recognized by Ollama are more suitable for using 7B/8B models as daily services. **&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;first-confirm-which-category-your-nas-belongs-to&#34;&gt;First confirm which category your NAS belongs to
&lt;/h2&gt;&lt;p&gt;Don’t just look at “AI chip”, “NPU” or “4K transcoding” on the product promotion page. Whether Ollama can accelerate depends on whether the system, driver, container permissions and hardware are recognized in the actual running environment.&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;NAS status&lt;/th&gt;
          &lt;th&gt;suitability&lt;/th&gt;
          &lt;th&gt;More realistic uses&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;ARM CPU, 8GB RAM, no available GPU&lt;/td&gt;
          &lt;td&gt;limited&lt;/td&gt;
          &lt;td&gt;Minimal model, simple classification, offline tasks&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;x86 CPU, 8GB RAM, no available GPU&lt;/td&gt;
          &lt;td&gt;Barely usable&lt;/td&gt;
          &lt;td&gt;1B–3B Quantitative model, low-frequency text processing&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;x86 CPU, 16GB–32GB memory, no available GPU&lt;/td&gt;
          &lt;td&gt;testable&lt;/td&gt;
          &lt;td&gt;3B–7B Low quantization model, but generally slower response&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;x86 NAS + 8GB NVIDIA video memory&lt;/td&gt;
          &lt;td&gt;Available every day&lt;/td&gt;
          &lt;td&gt;7B/8B quantitative chat, lightweight code assistance, single-user API&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;x86 NAS + 12GB or above NVIDIA video memory&lt;/td&gt;
          &lt;td&gt;more suitable&lt;/td&gt;
          &lt;td&gt;The 8B model is more comfortable, and some 14B quantitative models can be chosen based on context.&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The table is a starting point for deployment judgment, not a performance promise. CPU model, memory channels, model format, context length, number of concurrencies, NAS system limitations, and thermal dissipation will vary actual results.&lt;/p&gt;
&lt;h2 id=&#34;lets-first-look-at-storage-and-reasoning-separately&#34;&gt;Let’s first look at “storage” and “reasoning” separately.
&lt;/h2&gt;&lt;p&gt;The large hard disk of NAS mainly solves the problem of model file storage: you can save many GGUF, Ollama model layers and document libraries. The inference speed is mainly determined by the following items:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CPU core performance and memory bandwidth;&lt;/li&gt;
&lt;li&gt;Whether the system memory is sufficient to install the model and runtime;&lt;/li&gt;
&lt;li&gt;Whether the GPU is available and whether the video memory can accommodate the model and context;&lt;/li&gt;
&lt;li&gt;Whether PCIe lanes, drivers and containers are transparently transmitted correctly;&lt;/li&gt;
&lt;li&gt;Context length, model quantization, concurrency and output length.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So the answer to &amp;ldquo;Can a NAS run a 32B model if it has a 40TB hard drive?&amp;rdquo; is usually: files can certainly be placed, but they may not be able to be inferred at an acceptable speed.&lt;/p&gt;
&lt;h2 id=&#34;cpu-only-nas-when-is-it-worth-deploying&#34;&gt;CPU-only NAS: When is it worth deploying?
&lt;/h2&gt;&lt;p&gt;It is possible to run Ollama without a GPU. The official Docker image supports pure CPU boot:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;docker run -d &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  -v ollama:/root/.ollama &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  -p 11434:11434 &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --name ollama &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  ollama/ollama
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;CPU-only suitable for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Nightly batch summarization, document classification, tag extraction;&lt;/li&gt;
&lt;li&gt;low-frequency text tasks in home automation;&lt;/li&gt;
&lt;li&gt;Validate API calls, RAG pipelines, and permissions logic;&lt;/li&gt;
&lt;li&gt;Personal tools that are insensitive to initial token latency and generation speed.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Not very suitable for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Multi-person chat service;&lt;/li&gt;
&lt;li&gt;Long time code Agent;&lt;/li&gt;
&lt;li&gt;Large models are generated continuously;&lt;/li&gt;
&lt;li&gt;Real-time voice assistant or high-frequency web Q&amp;amp;A.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The correct strategy for CPU-only is to use a small model first, a short context, and limit concurrency. Don&amp;rsquo;t download the largest model first and then expect to get a cloud-like experience by &amp;ldquo;relying on the NAS and calculating slowly&amp;rdquo;.&lt;/p&gt;
&lt;h2 id=&#34;how-much-memory-should-be-reserved-at-least&#34;&gt;How much memory should be reserved at least?
&lt;/h2&gt;&lt;p&gt;System memory is not only used for model weights, but also for the NAS itself, file cache, Docker, download tasks, photo index, containers and KV Cache.&lt;/p&gt;
&lt;p&gt;A practical principle: **Don&amp;rsquo;t let Ollama eat up the NAS memory until it starts swapping a lot. ** Once swap intervenes frequently, the response time will significantly deteriorate and file sharing and other services will also be affected.&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Memory&lt;/th&gt;
          &lt;th&gt;suggestion&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;8GB&lt;/td&gt;
          &lt;td&gt;Only small models and lightweight testing are recommended; be more conservative when the NAS is running multiple services.&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;16 GB&lt;/td&gt;
          &lt;td&gt;Can be used as a starting point for CPU-only local assistants, prioritizing small models or low-quantized versions&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;32GB&lt;/td&gt;
          &lt;td&gt;More suitable for the coexistence of 7B-level low-quantity models, RAG and multiple lightweight containers&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;64GB+&lt;/td&gt;
          &lt;td&gt;Good for CPU/hybrid offloading of larger models and long documents, but does not equate to fast enough generation&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Model file size is only a lower limit. Model loading, context, and runtime will continue to take up memory, so don&amp;rsquo;t rely on &amp;ldquo;file 8GB, machine 8GB&amp;rdquo; to judge whether it can run.&lt;/p&gt;
&lt;h2 id=&#34;the-biggest-difference-in-experience-is-seen-with-nvidia-gpus&#34;&gt;The biggest difference in experience is seen with NVIDIA GPUs
&lt;/h2&gt;&lt;p&gt;If the NAS is x86 Linux and has a supported NVIDIA graphics card, Ollama can use GPU acceleration. Ollama officially lists the support range of NVIDIA compute capability 5.0+ and driver 531+, among which the RTX 30 series is also included in the support list.&lt;/p&gt;
&lt;p&gt;The Docker solution requires the host to first configure the NVIDIA Container Toolkit, and then use the GPU parameters to start the container:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;5
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;6
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;docker run -d &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --gpus&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;all &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  -v ollama:/root/.ollama &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  -p 11434:11434 &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --name ollama &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  ollama/ollama
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;After the container is started, verify the GPU transparent transmission itself instead of directly downloading the large model:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;docker run --gpus all ubuntu nvidia-smi
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;When this command does not display the graphics card properly, the Ollama container cannot use the GPU. At this time, you should first check whether the driver, Container Toolkit, Docker runtime, and NAS system support PCIe GPU transparent transmission.&lt;/p&gt;
&lt;h2 id=&#34;can-the-core-graphics-npu-and-transcoding-capabilities-of-nas-be-used-directly&#34;&gt;Can the core graphics, NPU and transcoding capabilities of NAS be used directly?
&lt;/h2&gt;&lt;p&gt;This cannot be assumed by default.&lt;/p&gt;
&lt;p&gt;The core graphics of many NAS are mainly used for video decoding, transcoding or graphics output; the NPU advertised by some devices may only be open to the manufacturer&amp;rsquo;s own applications. Whether they can be used by Ollama depends on the backend, operating system, driver and device permissions supported by Ollama.&lt;/p&gt;
&lt;p&gt;Actual evidence should be seen before deployment:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Whether the host can see the GPU device;&lt;/li&gt;
&lt;li&gt;Whether &lt;code&gt;nvidia-smi&lt;/code&gt; or the corresponding manufacturer’s detection tool can be run in the container;&lt;/li&gt;
&lt;li&gt;Do Ollama logs clearly show GPU usage;&lt;/li&gt;
&lt;li&gt;Under the same prompt, is the speed difference between GPU and CPU reasonable?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When you don&amp;rsquo;t see this evidence, plan according to CPU-only expectations. Don&amp;rsquo;t purchase a model based on discrete graphics performance just because the device has a &amp;ldquo;transcoding engine&amp;rdquo;.&lt;/p&gt;
&lt;h2 id=&#34;how-to-choose-a-model-so-as-not-to-bring-down-the-nas&#34;&gt;How to choose a model so as not to bring down the NAS
&lt;/h2&gt;&lt;p&gt;The core of NAS deployment is not to pursue the largest model, but to let common tasks be stably completed first.&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;scene&lt;/th&gt;
          &lt;th&gt;Model selection ideas&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;Family document summary, classification, simple questions and answers&lt;/td&gt;
          &lt;td&gt;Try 1B–4B models first&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Chinese chat, lightweight scripting, single-user API&lt;/td&gt;
          &lt;td&gt;You can try the 7B/8B quantization model when you have 8GB of video memory.&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Long code, complex Agent&lt;/td&gt;
          &lt;td&gt;Prioritize larger memory hosts or clouds. It is not recommended to rely solely on ordinary NAS CPUs.&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Embedding/RAG&lt;/td&gt;
          &lt;td&gt;Embedding models are usually lighter and suitable for NAS; generated models are called on demand&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Called by multiple people at the same time&lt;/td&gt;
          &lt;td&gt;Do queue and concurrency limits first, don’t let all requests directly load large models in parallel&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Once the model is too large, the common symptoms of NAS are not immediate failure, but long loading, slow first token generation, low generation speed, and continuous increase in system memory, which ultimately affects the stability of file services and containers.&lt;/p&gt;
&lt;h2 id=&#34;recommended-deployment-structure&#34;&gt;Recommended deployment structure
&lt;/h2&gt;&lt;p&gt;For most families or small teams, it is recommended to use NAS as a &amp;ldquo;data and light reasoning node&amp;rdquo;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;5
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;6
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;7
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;8
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;NAS
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;├─ Ollama：小模型、Embedding、低频 API
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;├─ 文档与向量库：私有文件、备份、RAG 数据
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;├─ 反向代理：局域网访问控制
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└─ 监控：CPU、内存、GPU、容器日志
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;高显存主机或云端
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└─ 大模型、长上下文、复杂 Agent、高并发推理
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;This division of labor is more stable than forcing all inference into the NAS: sensitive files remain local, and heavy tasks are routed to more appropriate devices.&lt;/p&gt;
&lt;h2 id=&#34;five-minute-test-before-deployment&#34;&gt;Five-minute test before deployment
&lt;/h2&gt;&lt;p&gt;Don&amp;rsquo;t download dozens of GB models first. First judge according to this process:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Confirm NAS architecture, Docker support, and remaining memory.&lt;/li&gt;
&lt;li&gt;Start the Ollama container and confirm that &lt;code&gt;http://NAS地址:11434&lt;/code&gt; is accessible.&lt;/li&gt;
&lt;li&gt;Pull up a small model and ask 5 to 10 fixed questions in a row.&lt;/li&gt;
&lt;li&gt;Observe CPU, memory, swap, disk IO and GPU usage.&lt;/li&gt;
&lt;li&gt;Then switch to a model that is close to real requirements, and gradually increase context and concurrency.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can use the following command to view container resources:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;docker stats ollama
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;If you have an NVIDIA GPU, observe at the same time:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;nvidia-smi
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;As long as file sharing, photo serving, or backup tasks are noticeably slower when running a model, the current model or concurrency is not suitable for NAS, and the model size should be reduced or the inference should be moved to other machines.&lt;/p&gt;
&lt;h2 id=&#34;dont-ignore-network-and-security&#34;&gt;Don’t ignore network and security
&lt;/h2&gt;&lt;p&gt;Ollama&amp;rsquo;s default local service port is &lt;code&gt;11434&lt;/code&gt;. If you want other devices on the LAN to call it, first implement access control at the NAS firewall or reverse proxy layer, and do not directly expose the unauthenticated inference port to the public network.&lt;/p&gt;
&lt;p&gt;Especially when there are family photos, backups, documents and private files in the NAS, the model service, file service and management backend should use different permission boundaries. For calls that can be completed on the LAN, there is no need to open the public network port.&lt;/p&gt;
&lt;h2 id=&#34;summarize&#34;&gt;Summarize
&lt;/h2&gt;&lt;p&gt;Whether Ollama is sufficient for NAS deployment can be judged as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;5
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;6
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;7
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;8
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;只做摘要、分类、Embedding
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;-&amp;gt; CPU-only NAS 可以尝试
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;想要 7B/8B 模型的日常交互体验
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;-&amp;gt; 需要可用 GPU，优先看显存
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;想做长上下文、复杂 Agent 或多人并发
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;-&amp;gt; 更适合高显存主机或云端推理
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;First use a small model to verify resources and stability, and then decide whether to add a graphics card, expand memory, or split inference nodes. NAS is great for hosting private data and lightweight model services, but it is not a natural large model server.&lt;/p&gt;
&lt;p&gt;refer to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://docs.ollama.com/gpu&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;Ollama Hardware Support&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://docs.ollama.com/docker&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;Ollama Docker Deployment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://docs.ollama.com/troubleshooting&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;Ollama GPU Troubleshooting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://knightli.com/en/2026/07/11/ollama-multiple-model-switching-keep-alive-modelfile-guide/&#34; &gt;Ollama multi-model switching tutorial&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        </item>
        <item>
        <title>What to do if vLLM KV Cache has insufficient memory: video memory, context and concurrency troubleshooting</title>
        <link>https://knightli.com/en/2026/07/11/vllm-kv-cache-memory-not-enough-troubleshooting/</link>
        <pubDate>Sat, 11 Jul 2026 09:36:02 +0800</pubDate>
        
        <guid>https://knightli.com/en/2026/07/11/vllm-kv-cache-memory-not-enough-troubleshooting/</guid>
        <description>&lt;p&gt;When the following error occurs when vLLM is started, it is usually not because the model weight download is broken:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;The model&amp;#39;s max seq len ... KV cache is needed, which is larger than the available KV cache memory
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;It means that after the model weights and runtime overhead take up the video memory, the remaining space is not enough to prepare the KV Cache for the maximum context length you set. The most direct processing sequence is: **Reduce &lt;code&gt;--max-model-len&lt;/code&gt; first, then check concurrency, and finally consider improving memory utilization, quantifying KV Cache, or expanding capacity. **&lt;/p&gt;
&lt;p&gt;Don&amp;rsquo;t pull &lt;code&gt;--gpu-memory-utilization&lt;/code&gt; to 1 right off the bat. That may allow vLLM to pass initialization, but be more prone to OOM when real requests, CUDA graph, or other processes compete for video memory.&lt;/p&gt;
&lt;h2 id=&#34;first-understand-why-kv-cache-fills-up-the-video-memory&#34;&gt;First understand: why KV Cache fills up the video memory
&lt;/h2&gt;&lt;p&gt;The model weight determines &amp;ldquo;whether the model can be loaded&amp;rdquo;, and the KV Cache determines &amp;ldquo;how many tokens the model can remember at the same time and how many requests it serves.&amp;rdquo; Every time a token is generated or read, the attention layer needs to save the corresponding Key/Value state.&lt;/p&gt;
&lt;p&gt;Therefore, KV Cache usage will increase with the following items:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;max_model_len&lt;/code&gt;: The longer the maximum context allowed, the greater the cache requirements.&lt;/li&gt;
&lt;li&gt;Number of concurrent requests: Each concurrent request will occupy its own context space.&lt;/li&gt;
&lt;li&gt;Model structure: number of layers, number of KV heads, hidden size and data type all affect cache size.&lt;/li&gt;
&lt;li&gt;Cache precision: The default usually follows the model data type; low-precision caches such as FP8 can save space, but have compatibility and quality boundaries.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The most overlooked thing is concurrency. Even if each request is only given 8K context, the total demand on KV Cache will still grow rapidly when multiple requests are running simultaneously.&lt;/p&gt;
&lt;h2 id=&#34;first-determine-what-kind-of-problem-it-is-from-the-logs&#34;&gt;First determine what kind of problem it is from the logs
&lt;/h2&gt;&lt;p&gt;Startup logs usually give three key pieces of information:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The maximum sequence length specified by the model or configured by you.&lt;/li&gt;
&lt;li&gt;How many GiB does KV Cache require.&lt;/li&gt;
&lt;li&gt;The actual space currently available for the KV Cache, and the maximum feasible length estimated by vLLM.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If the log says &amp;ldquo;Maximum length 32768 requires 10GiB KV Cache, but currently only 4GiB&amp;rdquo;, don&amp;rsquo;t worry about whether the model supports 32K first. Model &lt;strong&gt;Support&lt;/strong&gt; does not mean that your card can serve 32K requests under the current configuration.&lt;/p&gt;
&lt;p&gt;Start by taking note of the estimated maximum length provided by the log, and set your first test at around 60% to 80% of it, and then work your way up.&lt;/p&gt;
&lt;h2 id=&#34;first-priority-lower---max-model-len&#34;&gt;First priority: lower &lt;code&gt;--max-model-len&lt;/code&gt;
&lt;/h2&gt;&lt;p&gt;This is the adjustment with the highest success rate and the most predictable impact. For example, the model natively supports 32K, and your actual business only handles ordinary conversations, short codes and small documents, you can start with 8K:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;vllm serve Qwen/Qwen3-8B &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --max-model-len &lt;span class=&#34;m&#34;&gt;8192&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;If it&amp;rsquo;s still not enough, try again:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;vllm serve Qwen/Qwen3-8B &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --max-model-len &lt;span class=&#34;m&#34;&gt;4096&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Do not write the model card&amp;rsquo;s nominal 128K, 256K or longer context directly into the service parameters. For single-card deployments, the actual available length depends on weight, video memory, concurrency, and cache accuracy.&lt;/p&gt;
&lt;p&gt;A practical starting point:&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Video memory and usage&lt;/th&gt;
          &lt;th&gt;Context length to try first&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;12GB–16GB single-card, Class 8B model&lt;/td&gt;
          &lt;td&gt;4096 or 8192&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;24GB single card, 7B–14B models&lt;/td&gt;
          &lt;td&gt;8192 or 16384&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;24GB single card, 30B level quantized model&lt;/td&gt;
          &lt;td&gt;Start with 4096&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Long Document/RAG/Multi-User Service&lt;/td&gt;
          &lt;td&gt;Make decisions based on log estimates and stress testing, don’t just follow the table&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;These values ​​are a starting point for troubleshooting, not memory commitments. KV Cache size can vary significantly between models.&lt;/p&gt;
&lt;h2 id=&#34;second-priority-limit-concurrency-and-batch-processing&#34;&gt;Second priority: Limit concurrency and batch processing
&lt;/h2&gt;&lt;p&gt;Just because the service can be started does not mean it will be stable under high concurrency conditions. First, control concurrency to a small value:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;vllm serve Qwen/Qwen3-8B &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --max-model-len &lt;span class=&#34;m&#34;&gt;8192&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --max-num-seqs &lt;span class=&#34;m&#34;&gt;4&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;code&gt;--max-num-seqs&lt;/code&gt; limits the number of sequences that can be processed in one iteration. A larger number may result in higher throughput, but also greater KV Cache and scheduling pressure.&lt;/p&gt;
&lt;p&gt;If requests often contain long prompts, you should also pay attention to &lt;code&gt;--max-num-batched-tokens&lt;/code&gt;. It determines the maximum number of tokens that can be processed at one time; if it is too high, the prefill phase may occupy more resources instantly. Be conservative when troubleshooting, and then gradually expand after confirming stability.&lt;/p&gt;
&lt;p&gt;It is recommended to perform stress testing in this order:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Single request, 4K context, confirmed service stability.&lt;/li&gt;
&lt;li&gt;Single request, 8K context, observe first token latency and video memory.&lt;/li&gt;
&lt;li&gt;Two concurrent requests confirm that there will be no OOM.&lt;/li&gt;
&lt;li&gt;Then gradually increase &lt;code&gt;max_num_seqs&lt;/code&gt; or the number of batch tokens.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Do not adjust context, concurrency, batch and model quantization at the same time, otherwise it will be difficult to locate which parameter is causing the video memory to be exhausted.&lt;/p&gt;
&lt;h2 id=&#34;third-priority-properly-set---gpu-memory-utilization&#34;&gt;Third priority: Properly set &lt;code&gt;--gpu-memory-utilization&lt;/code&gt;
&lt;/h2&gt;&lt;p&gt;&lt;code&gt;--gpu-memory-utilization&lt;/code&gt; specifies the proportion of GPU memory that can be used by the current vLLM instance, with a value between 0 and 1. vLLM will plan the weight, runtime and KV Cache based on this part of the space.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;vllm serve Qwen/Qwen3-8B &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --gpu-memory-utilization 0.90 &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --max-model-len &lt;span class=&#34;m&#34;&gt;8192&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --max-num-seqs &lt;span class=&#34;m&#34;&gt;4&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;When the error message clearly says &amp;ldquo;Too few available KV Cache&amp;rdquo; and there are no other processes on the GPU, you can improve it in small steps, such as trying from &lt;code&gt;0.90&lt;/code&gt; to &lt;code&gt;0.92&lt;/code&gt; or &lt;code&gt;0.94&lt;/code&gt;. Add just a little at a time and test with real requests.&lt;/p&gt;
&lt;p&gt;It is not recommended to deadlift high in the following situations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Also running on the same card is a desktop program, another inference service, or a training task.&lt;/li&gt;
&lt;li&gt;Available video memory will fluctuate after startup.&lt;/li&gt;
&lt;li&gt;Spikes are prone to occur when using CUDA graphs, vision models, or high-concurrency prefills.&lt;/li&gt;
&lt;li&gt;You&amp;rsquo;ve encountered a CUDA OOM on the fly, not just a failed initialization check.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If multiple instances share the same GPU, you should have an explicit budget for each instance rather than setting them all to 0.9.&lt;/p&gt;
&lt;h2 id=&#34;fp8-kv-cache-confirm-the-model-and-version-before-saving-graphics-memory&#34;&gt;FP8 KV Cache: Confirm the model and version before saving graphics memory
&lt;/h2&gt;&lt;p&gt;vLLM supports changing the cache data type via &lt;code&gt;--kv-cache-dtype&lt;/code&gt;. CUDA 11.8+ environments are available with FP8 related options, such as:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;vllm serve Qwen/Qwen3-8B &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --kv-cache-dtype fp8 &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --max-model-len &lt;span class=&#34;m&#34;&gt;16384&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;FP8 KV Cache can significantly reduce cache usage, but don’t think of it as a completely free switch:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First confirm that the current vLLM, CUDA and hardware support this data type.&lt;/li&gt;
&lt;li&gt;Whether the model checkpoint provides an appropriate KV scale will affect the results; its absence needs to be evaluated with caution.&lt;/li&gt;
&lt;li&gt;Long contexts, complex reasoning, tool calls, and structured output should all be tested against the default cache accuracy.&lt;/li&gt;
&lt;li&gt;If you just want to fit an unsuitable large model into the graphics card, it is usually more stable to lower the context first or change to a more suitable model.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Therefore, the more recommended order is: first use the default precision to run 4K/8K stably, and then test whether FP8 can really allow the business to obtain the required context or concurrency.&lt;/p&gt;
&lt;h2 id=&#34;know-priorities-when-manually-specifying-kv-cache-size&#34;&gt;Know priorities when manually specifying KV Cache size
&lt;/h2&gt;&lt;p&gt;Newer vLLMs provide &lt;code&gt;kv_cache_memory_bytes&lt;/code&gt; to specify the KV Cache size precisely in bytes per GPU. It is suitable for scenarios where multiple services share a card and require a fixed graphics memory budget.&lt;/p&gt;
&lt;p&gt;Note: Explicitly setting the number of cache bytes will override the automatic inference of the cache size via &lt;code&gt;gpu_memory_utilization&lt;/code&gt;. Don&amp;rsquo;t think of both as additive gains; first decide whether to use a &amp;ldquo;proportional budget&amp;rdquo; or a &amp;ldquo;fixed cache budget&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Fixed budget is suitable for servers with clear operation and maintenance constraints. It is more intuitive to use &lt;code&gt;--gpu-memory-utilization&lt;/code&gt; and &lt;code&gt;--max-model-len&lt;/code&gt; for single-machine troubleshooting.&lt;/p&gt;
&lt;h2 id=&#34;what-can-cpu-offload-solve-and-what-cant-it-solve&#34;&gt;What can CPU offload solve and what can’t it solve?
&lt;/h2&gt;&lt;p&gt;The new version of vLLM supports offloading part of the KV Cache to the CPU, or combining it with back-end processing cache layers such as LMCache. This can scale capacity when the GPU cache is insufficient, but at the cost of PCIe/memory transfers and latency.&lt;/p&gt;
&lt;p&gt;It is more suitable for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Occasionally very long context requests;&lt;/li&gt;
&lt;li&gt;The business can accept higher initial token delay;&lt;/li&gt;
&lt;li&gt;There is sufficient system memory and real stress testing has been done;&lt;/li&gt;
&lt;li&gt;Want to make a degradation path for long prompts instead of pursuing the highest throughput.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is not suitable to cover up the problem of &amp;ldquo;the model weight cannot be put down&amp;rdquo;, nor can it replace the management of concurrency and context upper limits. If all requests are swapped out and in frequently, throughput will often drop significantly.&lt;/p&gt;
&lt;h2 id=&#34;a-replicable-troubleshooting-template&#34;&gt;A replicable troubleshooting template
&lt;/h2&gt;&lt;p&gt;Start with a conservative configuration:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;vllm serve Qwen/Qwen3-8B &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --gpu-memory-utilization 0.90 &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --max-model-len &lt;span class=&#34;m&#34;&gt;4096&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  --max-num-seqs &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;After confirming that the order request can be processed stably, adjust in the following order:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;4096 上下文稳定
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;-&amp;gt; 8192 上下文稳定
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;-&amp;gt; max_num_seqs 从 2 调到 4
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;-&amp;gt; 调整 max_num_batched_tokens
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;-&amp;gt; 再测试 FP8 KV Cache 或 CPU offload
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Four pieces of data are recorded in each round: number of available KV Cache tokens, first token delay, generated tokens/s, and peak video memory. This way you can tell whether an optimization is improving throughput or simply deferring OOMs to higher concurrency.&lt;/p&gt;
&lt;h2 id=&#34;common-misunderstandings&#34;&gt;Common misunderstandings
&lt;/h2&gt;&lt;h3 id=&#34;misunderstanding-1-the-model-supports-long-context-so-the-service-must-be-fully-enabled&#34;&gt;Misunderstanding 1: The model supports long context, so the service must be fully enabled
&lt;/h3&gt;&lt;p&gt;The upper limit of model capabilities and the upper limit of serviceability of your graphics card are two different things. The server&amp;rsquo;s &lt;code&gt;max_model_len&lt;/code&gt; should be set according to the hardware and business upper limit.&lt;/p&gt;
&lt;h3 id=&#34;misunderstanding-2-set-gpu_memory_utilization-to-1-to-solve-the-problem&#34;&gt;Misunderstanding 2: Set &lt;code&gt;gpu_memory_utilization&lt;/code&gt; to 1 to solve the problem
&lt;/h3&gt;&lt;p&gt;This reduces the safety margin and does not reduce the need for the KV Cache itself. Runtime spikes are more likely to trigger CUDA OOM.&lt;/p&gt;
&lt;h3 id=&#34;misunderstanding-3-only-reduce-weight-quantization-regardless-of-concurrency&#34;&gt;Misunderstanding 3: Only reduce weight quantization, regardless of concurrency
&lt;/h3&gt;&lt;p&gt;Weight quantization can free up video memory, but concurrency and context will still cause the KV Cache to expand rapidly. Service configurations must limit both length and number of requests.&lt;/p&gt;
&lt;h3 id=&#34;myth-4-cpu-offloading-is-definitely-better-than-rejecting-long-requests&#34;&gt;Myth 4: CPU offloading is definitely better than rejecting long requests
&lt;/h3&gt;&lt;p&gt;If latency is sensitive, frequent offloading may be worse than explicitly routing long requests to nodes with larger memory. First define the delay and cost boundaries of the business.&lt;/p&gt;
&lt;h2 id=&#34;summarize&#34;&gt;Summarize
&lt;/h2&gt;&lt;p&gt;vLLM KV Cache has insufficient memory. The most reliable processing priority is:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;降低 max_model_len
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;-&amp;gt; 限制 max_num_seqs 与 batch
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;-&amp;gt; 小步调整 gpu_memory_utilization
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;-&amp;gt; 验证 FP8 KV Cache
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;-&amp;gt; 最后考虑固定缓存预算或 CPU offload
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Let a short context and low concurrency configuration work stably first, and then gradually expand it according to business data. As long as the model weight, KV Cache, concurrency and real context length are looked at separately, most &amp;ldquo;out of memory&amp;rdquo; problems can be located faster.&lt;/p&gt;
&lt;p&gt;refer to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://docs.vllm.ai/en/stable/api/vllm/config/cache/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;vLLM Cache Config&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://docs.vllm.ai/en/stable/api/vllm/v1/core/kv_cache_utils/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;vLLM KV Cache calculation and error reporting logic&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://docs.vllm.ai/en/stable/configuration/engine_args/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;vLLM Engine Arguments&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://knightli.com/en/2026/06/25/lmcache-vllm-kv-cache-guide/&#34; &gt;LMCache Practical Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        </item>
        <item>
        <title>How to configure Ollama multi-model switching: resident, video memory and Modelfile tutorials</title>
        <link>https://knightli.com/en/2026/07/11/ollama-multiple-model-switching-keep-alive-modelfile-guide/</link>
        <pubDate>Sat, 11 Jul 2026 09:32:06 +0800</pubDate>
        
        <guid>https://knightli.com/en/2026/07/11/ollama-multiple-model-switching-keep-alive-modelfile-guide/</guid>
        <description>&lt;p&gt;After Ollama has installed several models, the first question many people have is: How to quickly switch between chat, code, translation and Embedding models? The second question is often more practical: Why does the previous one disappear from the video memory just after switching to another model?&lt;/p&gt;
&lt;p&gt;Let me start with the conclusion: Ollama does not need to serve each model separately. Use &lt;code&gt;ollama run &amp;lt;模型名&amp;gt;&lt;/code&gt; for daily switching; use &lt;code&gt;ollama ps&lt;/code&gt; to see which models are currently in memory; use &lt;code&gt;ollama stop &amp;lt;模型名&amp;gt;&lt;/code&gt; to release unnecessary models. Whether multiple models can be resident at the same time depends on whether they can fit into the available video memory or memory, rather than how many models are downloaded to the local disk.&lt;/p&gt;
&lt;h2 id=&#34;most-commonly-used-switching-commands&#34;&gt;Most commonly used switching commands
&lt;/h2&gt;&lt;p&gt;First list the models that have been downloaded by this machine:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama ls
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Start a chat or code model:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama run qwen3:8b
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;When you need to change to another model, run another name directly:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama run qwen3:4b
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Or switch to the Embedding model for testing:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama run embeddinggemma &lt;span class=&#34;s2&#34;&gt;&amp;#34;测试一段文本&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Model files remain local and will not be re-downloaded when switching. The weights need to be put into video memory or system memory when loading the model for the first time. If the model is still retained in memory, it will be faster to call it again.&lt;/p&gt;
&lt;h2 id=&#34;ollama-ps-first-see-who-occupies-the-video-memory&#34;&gt;&lt;code&gt;ollama ps&lt;/code&gt;: First see who occupies the video memory
&lt;/h2&gt;&lt;p&gt;When the switching is not smooth, first execute:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama ps
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;It lists models that are running or still resident in memory. The most interesting things to look at here are the model name, footprint, processor location, and expiration time.&lt;/p&gt;
&lt;p&gt;If you only have a medium-sized graphics card, and you launch two large models one after another, Ollama may uninstall the first model to make room for the second one. This is normal resource scheduling, not that the model is lost. The model is still on disk and will be reloaded on the next call.&lt;/p&gt;
&lt;p&gt;If you don’t want to wait for it to expire naturally, you can stop it proactively:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama stop qwen3:8b
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Then use &lt;code&gt;ollama ps&lt;/code&gt; to confirm that the video memory has been released.&lt;/p&gt;
&lt;h2 id=&#34;default-dwell-time-5-minutes&#34;&gt;Default dwell time: 5 minutes
&lt;/h2&gt;&lt;p&gt;Ollama defaults to retaining a model for approximately 5 minutes after it was last used. This design is suitable for continuous questions: the first loading is slightly slower, and subsequent requests do not need to repeatedly move the same model back to the video memory.&lt;/p&gt;
&lt;p&gt;If you use multiple models in turn on a machine with small video memory, 5 minutes may actually cause the feeling of &amp;ldquo;just finished running one, and the video memory has not been returned yet&amp;rdquo;. There are three control methods at this time.&lt;/p&gt;
&lt;h3 id=&#34;method-1-uninstall-immediately-after-one-call&#34;&gt;Method 1: Uninstall immediately after one call
&lt;/h3&gt;&lt;p&gt;Set &lt;code&gt;keep_alive&lt;/code&gt; to &lt;code&gt;0&lt;/code&gt; via API:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;curl http://localhost:11434/api/generate -d &lt;span class=&#34;s1&#34;&gt;&amp;#39;{
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;  &amp;#34;model&amp;#34;: &amp;#34;qwen3:8b&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;  &amp;#34;prompt&amp;#34;: &amp;#34;用一句话解释 KV cache&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;  &amp;#34;keep_alive&amp;#34;: 0
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;}&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;This is suitable for situations where the model is large, video memory is tight, and each task is independent.&lt;/p&gt;
&lt;h3 id=&#34;method-2-keep-the-model-resident-for-a-long-time&#34;&gt;Method 2: Keep the model resident for a long time
&lt;/h3&gt;&lt;p&gt;If you are using the same code model all day, you can set &lt;code&gt;keep_alive&lt;/code&gt; to a negative number:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;curl http://localhost:11434/api/generate -d &lt;span class=&#34;s1&#34;&gt;&amp;#39;{
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;  &amp;#34;model&amp;#34;: &amp;#34;qwen3:8b&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;  &amp;#34;keep_alive&amp;#34;: -1
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;}&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;This way the model will remain in memory until manually &lt;code&gt;ollama stop&lt;/code&gt; or the service is restarted. Don&amp;rsquo;t set this up for multiple large models when you don&amp;rsquo;t have enough video memory.&lt;/p&gt;
&lt;h3 id=&#34;method-3-globally-modify-the-default-resident-time&#34;&gt;Method 3: Globally modify the default resident time
&lt;/h3&gt;&lt;p&gt;&lt;code&gt;OLLAMA_KEEP_ALIVE&lt;/code&gt; can be set for Ollama services. For example, if you want all models to be retained for 30 seconds by default:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;OLLAMA_KEEP_ALIVE=30s
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Under Windows, Ollama inherits user or system environment variables. Once setup is complete, you need to exit Ollama from the tray and restart from the Start menu. If Ollama is managed by systemd on Linux, set the service environment variable and restart the service.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;keep_alive&lt;/code&gt; in the API request will override the global &lt;code&gt;OLLAMA_KEEP_ALIVE&lt;/code&gt;, so it is more suitable to set different policies for different tasks.&lt;/p&gt;
&lt;h2 id=&#34;the-key-to-multi-model-persistence-ollama_max_loaded_models&#34;&gt;The key to multi-model persistence: &lt;code&gt;OLLAMA_MAX_LOADED_MODELS&lt;/code&gt;
&lt;/h2&gt;&lt;p&gt;&lt;code&gt;OLLAMA_MAX_LOADED_MODELS&lt;/code&gt; is used to limit the number of models that can be loaded simultaneously. For example, you only want the service to retain at most one model:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;OLLAMA_MAX_LOADED_MODELS=1
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;The purpose of this setting is to avoid filling up the video memory for a long time when the model is rotated, but it is not a method of &amp;ldquo;forcing a large model to fit into the graphics card&amp;rdquo;. During GPU inference, a new model can reside concurrently with other models only if it can be completely fit into the available video memory. Otherwise Ollama will unload the old model, or put the model to a slower memory path.&lt;/p&gt;
&lt;p&gt;For a single 8GB, 12GB or 16GB graphics card, the more stable strategy is usually:&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;scene&lt;/th&gt;
          &lt;th&gt;suggestion&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;Only use one chat model every day&lt;/td&gt;
          &lt;td&gt;&lt;code&gt;OLLAMA_MAX_LOADED_MODELS=1&lt;/code&gt;, keep for 5 minutes or less&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Small model chat + Embedding&lt;/td&gt;
          &lt;td&gt;First check the actual occupancy of both. If you can put them down at the same time, then increase the quantity.&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Code model and general model are used alternately&lt;/td&gt;
          &lt;td&gt;Do not insist on dual resident, switch according to tasks and take the initiative &lt;code&gt;ollama stop&lt;/code&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Server multi-user call&lt;/td&gt;
          &lt;td&gt;Combine the model size, video memory, and request volume, and then set the concurrency and queue&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;dont-ignore-concurrency-contexts-eat-memory-too&#34;&gt;Don’t ignore concurrency: contexts eat memory too
&lt;/h2&gt;&lt;p&gt;Multi-model problems are not just about model weights. Each parallel request increases the resource consumption of the context and KV cache.&lt;/p&gt;
&lt;p&gt;Ollama also provides two related environment variables:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;OLLAMA_NUM_PARALLEL=1
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;OLLAMA_MAX_QUEUE=512
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;code&gt;OLLAMA_NUM_PARALLEL&lt;/code&gt; controls the number of requests that can be processed in parallel by the same model. When the number of concurrency increases, the required resources will increase with the context length. When using a single card locally, it is often easier to troubleshoot by leaving the default or explicitly setting it to &lt;code&gt;1&lt;/code&gt;; do not load multiple models while increasing concurrency.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;OLLAMA_MAX_QUEUE&lt;/code&gt; is the number of requests that can be queued when busy. It only solves queuing and does not increase video memory.&lt;/p&gt;
&lt;h2 id=&#34;use-modelfile-to-create-fixed-aliases-for-different-purposes&#34;&gt;Use Modelfile to create fixed aliases for different purposes
&lt;/h2&gt;&lt;p&gt;If you always set system prompt words, temperature, or context policies repeatedly for the same base model, you can use the Modelfile to create multiple local aliases. Instead of duplicating an entire set of weights, they define different configurations based on a model.&lt;/p&gt;
&lt;p&gt;For example, create a code-biased configuration file &lt;code&gt;Modelfile.code&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;FROM qwen3:8b
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;SYSTEM 你是一个中文编程助手。先说明修改思路，再给出可运行的最小代码。
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;PARAMETER temperature 0.2
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Create a model alias:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama create qwen3-code -f Modelfile.code
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Then run directly:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama run qwen3-code
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;You can also make a writing-oriented version:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;FROM qwen3:8b
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;SYSTEM 你是中文写作助手，回答前先给结论，再给必要的结构化说明。
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;PARAMETER temperature 0.7
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama create qwen3-write -f Modelfile.write
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama run qwen3-write
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Note: &lt;code&gt;qwen3-code&lt;/code&gt; and &lt;code&gt;qwen3-write&lt;/code&gt;, although sharing the same base orientation, are still different model configurations at runtime. When video memory is tight, don&amp;rsquo;t assume they can be resident indefinitely at the same time.&lt;/p&gt;
&lt;h2 id=&#34;give-scripts-or-apis-to-switch-models-by-task&#34;&gt;Give scripts or APIs to switch models by task
&lt;/h2&gt;&lt;p&gt;In the API, the model name itself is the routing field. The script does not need to restart the service, just pass in different &lt;code&gt;model&lt;/code&gt; according to the task:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;5
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;6
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;7
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;8
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;curl http://localhost:11434/api/chat -d &lt;span class=&#34;s1&#34;&gt;&amp;#39;{
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;  &amp;#34;model&amp;#34;: &amp;#34;qwen3-code&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;  &amp;#34;messages&amp;#34;: [
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;    {&amp;#34;role&amp;#34;: &amp;#34;user&amp;#34;, &amp;#34;content&amp;#34;: &amp;#34;解释这段 Python 的异常处理逻辑&amp;#34;}
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;  ],
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;  &amp;#34;stream&amp;#34;: false,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;  &amp;#34;keep_alive&amp;#34;: &amp;#34;10m&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s1&#34;&gt;}&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;A common division of labor is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Small model: classification, rewriting, summary, simple question and answer;&lt;/li&gt;
&lt;li&gt;Code model: interpret the warehouse, generate scripts, and fix errors;&lt;/li&gt;
&lt;li&gt;Embedding model: vector retrieval, not responsible for chatting;&lt;/li&gt;
&lt;li&gt;Larger models: complex problems, loaded on demand, released after use.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Writing &amp;ldquo;which model to choose&amp;rdquo; in the task routing of the code makes it easier to control speed and memory than cramming all the work on one large model.&lt;/p&gt;
&lt;h2 id=&#34;common-pitfalls-under-windows&#34;&gt;Common pitfalls under Windows
&lt;/h2&gt;&lt;h3 id=&#34;the-environment-variable-was-changed-but-it-didnt-take-effect&#34;&gt;The environment variable was changed but it didn’t take effect
&lt;/h3&gt;&lt;p&gt;After modifying &lt;code&gt;OLLAMA_KEEP_ALIVE&lt;/code&gt;, &lt;code&gt;OLLAMA_MAX_LOADED_MODELS&lt;/code&gt;, or &lt;code&gt;OLLAMA_MODELS&lt;/code&gt; on Windows, you must exit the running Ollama tray program and restart. Simply reopening PowerShell is usually not enough.&lt;/p&gt;
&lt;h3 id=&#34;model-files-crowd-the-system-disk&#34;&gt;Model files crowd the system disk
&lt;/h3&gt;&lt;p&gt;You can set &lt;code&gt;OLLAMA_MODELS&lt;/code&gt; to move the model directory to another disk, for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;OLLAMA_MODELS=D:\OllamaModels
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Save and restart Ollama. Before migrating existing models, confirm the disk space and directory permissions. Do not delete the old directory just to change the volume.&lt;/p&gt;
&lt;h3 id=&#34;i-thought-the-model-was-deleted&#34;&gt;I thought the model was deleted
&lt;/h3&gt;&lt;p&gt;After switching, you can&amp;rsquo;t see the old model with &lt;code&gt;ollama ps&lt;/code&gt;, which just means that it has been unloaded from the memory; you can still see the downloaded model with &lt;code&gt;ollama ls&lt;/code&gt;. Local model files will be deleted only by executing the following command:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama rm qwen3:8b
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2 id=&#34;a-set-of-default-strategies-suitable-for-a-single-card&#34;&gt;A set of default strategies suitable for a single card
&lt;/h2&gt;&lt;p&gt;If you only have one consumer-grade graphics card and frequently switch between multiple models, you can start with this strategy:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;OLLAMA_MAX_LOADED_MODELS=1
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;OLLAMA_KEEP_ALIVE=2m
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;OLLAMA_NUM_PARALLEL=1
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Then call the &lt;code&gt;qwen3-code&lt;/code&gt;, &lt;code&gt;qwen3-write&lt;/code&gt;, or Embedding model on a per-task basis. When you need to run a large model, execute &lt;code&gt;ollama stop&lt;/code&gt; first to stop unnecessary models; when encountering long contexts or large files, lower the number of concurrency and resident numbers.&lt;/p&gt;
&lt;p&gt;The goal of this configuration is not to allow the graphics card to load as many models as possible at the same time, but to allow each switch to be predictable and the graphics memory will not be filled up with models that will be forgotten for a long time.&lt;/p&gt;
&lt;h2 id=&#34;summarize&#34;&gt;Summarize
&lt;/h2&gt;&lt;p&gt;There are only four core commands for Ollama multi-model switching:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama ls
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama run &amp;lt;模型名&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama ps
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ollama stop &amp;lt;模型名&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;If you want to better manage models for different purposes, use Modelfile to create aliases; if you want to control loading and release, use &lt;code&gt;keep_alive&lt;/code&gt;, &lt;code&gt;OLLAMA_KEEP_ALIVE&lt;/code&gt; and &lt;code&gt;OLLAMA_MAX_LOADED_MODELS&lt;/code&gt;. First determine the number of simultaneous residents according to the video memory, and then consider multi-model routing and concurrency. The configuration will be much more stable.&lt;/p&gt;
&lt;p&gt;refer to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://docs.ollama.com/cli&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;Ollama CLI Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://docs.ollama.com/faq&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;Ollama FAQ: Model persistence and concurrency&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://docs.ollama.com/windows&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;Ollama Windows Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        </item>
        
    </channel>
</rss>
