Running Two Local GGUF Models on a Home Server, Switched from Telegram A developer running a personal AI assistant on a VPS configured a single llama.cpp server on port 8080 to serve two local GGUF models — a Gemma model and Inkling-2-Mini Uncensored (IQ2_M, ~8.7 GB) — on a home server with an RTX 3060 (12 GB) and RTX 3070 (8 GB), switching between them from Telegram. The setup keeps a 64k context by using batch size 128 and a quantized q8_0 KV cache, bringing Inkling to about 11.3 GB, and uses discover_models: false with an explicit models dictionary so the Telegram picker shows a fixed list. The writeup also documents a CUDA_DEVICE_ORDER=PCI_BUS_ID mismatch that caused false out-of-memory errors and an unlimited -j build that triggered the OOM killer. Background I run a personal AI assistant Hermes Agent on a VPS. The local models run on a home server with two GPUs: an RTX 3060 12 GB and an RTX 3070 8 GB . The 3070 mines when idle. The 3060 normally serves a local Gemma model through llama.cpp. When the home server is off or unreachable, the assistant falls back to OpenRouter. This post covers how I added a second local model Inkling-2-Mini Uncensored, IQ2 M quantization, about 8.7 GB and made it possible to switch between the two models from Telegram. Goals • Pick Gemma or Inkling from Telegram's /model menu • Serve both models from the same llama.cpp server on port 8080 • Keep a 64k context, which the assistant needs for summarization • Keep mining idle-only, and give the LLM priority whenever it is needed What Went Wrong and Why Running cmake --build with -j and no number runs unlimited parallel jobs. CUDA compilation is memory-heavy, so the kernel's OOM killer stopped the compiler. The fix was an explicit job count -j 1 and a background build with nohup. Lesson: A bare -j does not mean "use all cores." It means unlimited. The 3060 showed about 11.9 GB free, yet loading an 8 GB model failed. I tried several wrong fixes first: batch size, multimodal offload, and locked-memory limits. The real cause was that the production service set CUDA DEVICE ORDER=PCI BUS ID, but my interactive shell did not. Without it, CUDA numbers GPUs by speed, so CUDA VISIBLE DEVICES=0 pointed at the 3070. nvidia-smi lists GPUs in PCI order, which made the mismatch hard to see. Lesson: When CUDA reports out of memory on a device that has free memory, first check which physical GPU the process actually uses. In Telegram, /model for a custom provider lists the models returned by the endpoint's /v1/models. The server runs one model at a time, so the list showed only whichever model was loaded. That looked odd next to the OpenRouter list, which is a fixed catalog. Reading the Hermes source showed that a custom provider's list comes from /models unless you set discover models: false. With that flag, Hermes uses the models: dictionary in config.yaml. Entries that share the same URL are also merged into one picker row. So I put both models under a single provider entry. Lesson: For a fixed picker list on a custom provider, use discover models: false with an explicit models: dictionary. Hermes requires at least 64,000 tokens of context for summarization. Inkling at 8k could not handle that step. Running Inkling at 64k on the 3060 took two changes: • Batch size -b 128 and micro-batch -ub 128, to shrink the compute buffer • Quantized KV cache --cache-type-k q8 0 --cache-type-v q8 0 , to shrink the KV cache Inkling then ran at about 11.3 GB with a 64k context. Only about 1 GB stayed free, so long conversations are the next thing to watch. Several things start or stop the LLM server without a manual command: • An idle monitor switches the 3060 to mining after 10 minutes without GPU load • A wake hook starts the server before each model call by design, so the LLM takes priority over mining • systemd restarts a failing service I disabled the idle timer during tests and re-enabled it afterward. Final Architecture • One llama-server unit on port 8080. Model arguments come from an environment file gemma.env or inkling.env . • One binary llama.cpp build 12652 for both models. • A root-owned switch script that restarts the server only when the requested model differs from the running one. • A restricted SSH command channel that the assistant uses to call wake-llama or wake-inkling. • A per-turn wake plugin that picks the wake command from the model path in config.yaml. Provider Configuration Example Here is a sanitized example of the config.yaml sections that make the picker and the switching work. Replace the placeholders with your own values. Do not put API keys in the file. Use an environment variable instead. model: default: /models/inkling2/Inkling-2-Mini-Uncensored-AD-IQ2 M.gguf the model in use now provider: custom:home-server the provider name shown in /model base url: http://:8080/v1 context length: 65536 global default lost on /model switch providers: custom:home-server: base url: http://:8080/v1 key env: OPENAI API KEY key comes from the environment, not from this file default model: /models/gemma4-12b-qat-q4 k m.gguf listed first in the picker discover models: false do not ask the server for its model list models: /models/gemma4-12b-qat-q4 k m.gguf: context length: 65536 /models/inkling2/Inkling-2-Mini-Uncensored-AD-IQ2 M.gguf: context length: 65536 request timeout seconds: 120 custom providers: per-model overrides that survive /model switches fallback providers: What each key does • providers.custom:.discover models: false stops Hermes from asking the server for its model list. The picker then shows only the models: you wrote. • models: is a dictionary keyed by model path. The first entry in the list comes from default model. • custom providers with the same URL is merged into the same picker row. Use it for per-model context length, because model.context length alone is lost after a /model switch. • key env names an environment variable that holds the key. The key itself stays out of the YAML. How to Switch Models from Telegram Notes • Pressing Cancel leaves the current setting unchanged. • Choosing a model only records it. The model loads on the next message. • If the home server is off, the assistant falls back to OpenRouter. • Keep the menu's selection and the server's active model in agreement. If they differ, the wrong model can answer or the request can fail. Takeaways • Read the source of your tools before guessing. I spent hours tuning VRAM settings, but the picker problem was solved in minutes once I read the code. • Keep "what the config says" and "what is running now" separate in your head, and check both. • Back up before every config change, and keep a restore command next to each change. -- Telegram からモデルを切り替える、自宅サーバーでのローカルLLM運用 背景 VPS で AI アシスタント(Hermes Agent)を動かしています。ローカルの LLM は、自宅サーバーの2枚の GPU(RTX 3060 12GB と RTX 3070 8GB)で動かしています。3070 はアイドル時に採掘に使い、3060 は通常、llama.cpp で Gemma を動かします。自宅サーバーに繋がらないときは、OpenRouter に自動で切り替わります。 この記事では、2つ目のローカルモデル(Inkling-2-Mini Uncensored、IQ2 M、約8.7GB)を追加して、Telegram から2つのモデルを切り替えられるようにした話をまとめます。 目的 • Telegram の /model から、Gemma と Inkling を選べるようにする • 両方を、同じ llama.cpp サーバー(8080番)で動かす • アシスタントが要約に使う、64k のコンテキストを確保する • マイニングは隙間時間だけ。LLM が必要なときは LLM を優先する つまずき(と原因) cmake --build で -j に数字を付けずに実行すると、並列数が無制限になります。CUDA のコンパイルはメモリを多く使うので、カーネルの OOM キラーがコンパイラを止めました。-j 1 と明示し、nohup でバックグラウンド実行して解決しました。 教訓: -j の後の数字は省略できません。省略すると「全コア使用」ではなく「無制限」になります。 3060 に約11.9GBの空きがあるのに、8GBのモデルの読み込みが失敗しました。バッチサイズや mmproj、ロック可能メモリの上限を疑いましたが、どれも外れでした。 本当の原因は、サービス(systemd)には CUDA DEVICE ORDER=PCI BUS ID が設定されていたのに、手作業のシェルには設定されていなかったことです。この変数がないと、CUDA は GPU を速い順に番号付けします。その結果、CUDA VISIBLE DEVICES=0 が 3060 ではなく 3070 を指していました。nvidia-smi は PCI 順で表示するので、食い違いに気づきにくかったです。 教訓: CUDA の out of memory が出たら、パラメータを調整する前に、プロセスが実際にどの物理GPUを使っているかを確認しましょう。 Telegram で custom provider の /model を開くと、エンドポイントの /v1/models が返すモデルが一覧に出ます。サーバーは同時に1つのモデルしか動かさないので、一覧には今読み込まれているモデルしか出ませんでした。OpenRouter の一覧は固定なので、この違いが気になりました。 Hermes のソースを読むと、custom provider の一覧は discover models: false を設定しない限り /models から作られることが分かりました。false にすると、config.yaml の models:(モデル名をキーにした辞書)をそのまま一覧に使います。 同じURLの entry は、1つの行にまとめられることも分かりました。そこで、Gemma と Inkling を、1つの provider の中に入れることにしました。 教訓: custom provider で一覧を固定するには、discover models: false と、明示的な models: の辞書を使います。 Hermes は、要約(圧縮)のために少なくとも 64,000 トークンのコンテキストを必要とします。8k で動かしていた Inkling では、この条件を満たせませんでした。 Inkling を 64k で3060に載せるには、次の2つを組み合わせました。 • バッチサイズ -b 128 と、マイクロバッチ -ub 128(計算用バッファを小さくする) • KV キャッシュの量子化 --cache-type-k q8 0 --cache-type-v q8 0(KV の領域を小さくする) 結果として、Inkling は 64k で約11.3GB を使って動きました。空きは1GB程度しかないので、長い会話をしたときは注意が必要です。 LLM のサーバーは、次の仕組みで自動的に止まったり起きたりします。 • アイドル監視:GPU の負荷が10分間ないと、3060 をマイニングに切り替える • wake フック:LLM を呼ぶ前に、サーバーを起こす(LLM を採掘より優先するため、毎ターン送っています) • systemd:失敗したサービスを再起動する テスト中は、アイドル監視のタイマーを止めておき、終わったら戻しました。 最終的な構成 • llama-server の unit は1つ(8080番)。モデルの引数は、環境ファイル(gemma.env / inkling.env)から読む • バイナリは1つ(llama.cpp の build 12652)で、両方のモデルを動かす • root 所有の切り替えスクリプトが、要求されたモデルと今のモデルが違うときだけ、サーバーを止めて起動し直す • 制限された SSH コマンドから、wake-llama か wake-inkling を呼ぶ • 毎ターンの wake プラグインが、config.yaml のモデルのパスから、どちらを呼ぶかを決める プロバイダー設定の例(YAML) Telegram の一覧と切り替えを動かしている config.yaml の部分を、伏せた形で載せます。 などは、自分の値に置き換えてください。APIキーはファイルに書かず、環境変数(key env)で渡します。 model: default: /models/inkling2/Inkling-2-Mini-Uncensored-AD-IQ2 M.gguf 今使っているモデル provider: custom:home-server /model に出る provider 名 base url: http://:8080/v1 context length: 65536 全体の既定値(/model で切り替えると消える) providers: custom:home-server: base url: http://:8080/v1 key env: OPENAI API KEY キーは環境変数から読む。ファイルには書かない default model: /models/gemma4-12b-qat-q4 k m.gguf 一覧の先頭に出る discover models: false サーバーにモデル一覧を聞きに行かない models: /models/gemma4-12b-qat-q4 k m.gguf: context length: 65536 /models/inkling2/Inkling-2-Mini-Uncensored-AD-IQ2 M.gguf: context length: 65536 request timeout seconds: 120 custom providers: /model の切り替え後も残る、モデルごとの設定 各項目の意味 • providers.custom:<名前 .discover models: false:サーバーにモデル一覧を聞きに行かず、models: に書いたものだけを一覧に出す。 • models: はモデルのパスをキーにした辞書。一覧の先頭は default model で決まる。 • 同じURLの custom providers は、同じ行にまとめられる。モデルごとの context length は、ここに書くと /model で切り替えても残る。 • key env は、キーが入った環境変数の名前を指定する。キーそのものは YAML に書かない。 Telegram からモデルを切り替える方法 補足 • Cancel を押すと、設定は変わりません。 • モデルを選んだだけでは、読み込まれません。読み込まれるのは、次のメッセージを送ったときです。 • 自宅サーバーが落ちているときは、OpenRouter に自動で切り替わります。 • メニューで選んだモデルと、サーバーで今動いているモデルは、必ず揃えておきましょう。ずれると、違うモデルが応答したり、リクエストが失敗したりします。 まとめ • ツールの動きは、推測よりソースを読むほうが早いです。VRAM の調整に何時間もかけましたが、一覧の問題は、コードを読んだら数分で分かりました。 • 「設定に書いてあること」と「今動いていること」は、分けて考えて、両方を確認しましょう。 • 設定を変えるたびにバックアップを取り、元に戻すコマンドも用意しておきましょう。