Skip to content

Hardware layouts for consumer GPUs, CUDA training through quantized weights, and reasoning off for Qwen3 / gpt-oss - #19

Merged
FMXExpress merged 6 commits into
mainfrom
claude/optimistic-allen-i3bd3d
Nov 9, 2026
Merged

FMXExpress merged 6 commits into
mainfrom
claude/optimistic-allen-i3bd3d

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

memagent now runs on consumer GPUs, and was tested on one. Full write-up in bench/README.md: "One GPU for chat and training", "Hardware layouts" and "On a GPU".

[gpu] layout (new Mem.Layout)

auto is the default. It counts the GPUs llama.cpp lists: none gives cpu, one gives one-gpu, two or more give two-gpus.

layout chat training
cpu CPU CPU
chat-gpu-train-cpu GPU CPU
chat-cpu-train-gpu CPU GPU
two-gpus GPU gpu GPU second
one-gpu GPU same GPU, between turns
one-gpu-idle GPU same GPU, only after idle_min minutes without a message (and inside night when set)
custom [gpu] infer / train as written
  • one-gpu-idle: the idle run unloads the chat model. A message stops the run and loads the model back, adapters included. The stopped run's facts stay due.
  • [consolidate] train_base = auto: trains on an f32 copy when it fits on the training device. Otherwise it trains on the GGUF as loaded, and on the chat card that means the chat engine's own copy (one copy in memory).
  • The startup line says what was chosen and why.
  • The shipped memagent.ini no longer assumes two GPUs.

llama.cpp patch

  • LoRA tensors placement: new tensors go on their base weight's device instead of always on the CPU.
  • CUDA out_prod for f16 and quantized weights: the weight is dequantized one slice of rows at a time (about 256 MB) and the GEMMs are accumulated. This is the backward pass through a frozen 4-bit base.

Reasoning models (Mem.LlamaChat)

Detected from the chat template:

  • Qwen3 family: turns open with an empty <think></think>.
  • gpt-oss: turns open in the final channel.
  • Training examples use the same prefix.
  • A stray <think> block is cut from answers and from the stream.

Measured on an RTX PRO 4500 (32 GB, 23 min, about $0.27)

  • Every layout passes end to end on the card: scripts/e2e_tiers.sh / e2e_idle.sh with LAYOUT=.
  • 1.5B (small), training per run: 3.3 s through the q8_0 weights as loaded, against 5.5 s on an f32 copy, with identical gate recall.
  • Qwen3-14B Q4_K_M: chats and trains, in 12 s. Gate recall was 2 of 3; it needs training settings tuned for the 14B.
  • gpt-oss-20b and Qwen3.8-27B: chat, but abort in training. llama.cpp has no backward for MoE routing (ADD_ID, MUL_MAT_ID) or Gated DeltaNet. That needs llama.cpp work or the Python/Unsloth trainer.

Test plan

  • make test-pascal, including the new layout_test (30 checks)
  • CPU: scripts/e2e_tiers.sh (default and TRAIN_BASE=model) and scripts/e2e_idle.sh
  • GPU: all five layouts end to end, the CUDA out_prod path, and the three newer models
  • Tiny model: train_base f32 against model, same recall (memory-tiny-llama-base-*.json)
  • two-gpus on a two-card machine (not run)

Generated by Claude Code

…est whether the trainer shares the chat model

llama_adapter_lora_init_new allocated every trainable tensor on the CPU, so a GPU
run would move each layer's activations to the host. Each pair now goes in the
buffer type of its base weight (the CPU for host buffers). The trainer logs
whether its base weights are the chat engine's copy, and scripts/e2e_tiers.sh
checks that with TRAIN_BASE=model.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…h idle-time training on one card

auto | cpu | chat-gpu-train-cpu | chat-cpu-train-gpu | two-gpus | one-gpu |
one-gpu-idle | custom (the old infer/train). auto counts the GPUs llama.cpp lists:
none -> cpu, one -> one-gpu, two -> two-gpus. train_base = auto picks an f32
copy when it fits on the training device, else the model as loaded (Mem.Layout,
tests/layout_test.lpr, 30 checks).

one-gpu-idle / train_when = idle: a run waits for idle_min minutes without a
message (inside night when set), unloads the chat model and trains; the next
message stops it and the model loads back with its adapters. A cancelled run's
facts stay due. scripts/e2e_idle.sh passes on the CPU. The shipped
memagent.ini no longer assumes two GPUs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…eights; reasoning off for Qwen3 and gpt-oss

On a rented RTX PRO 4500 (32 GB, 23 min, about $0.27): scripts/e2e_tiers.sh
and e2e_idle.sh pass for one-gpu (f32 copy and shared weights),
chat-gpu-train-cpu, chat-cpu-train-gpu and one-gpu-idle; auto picks one-gpu.

packaging/llama-patches: CUDA out_prod dequantizes an f16 or quantized weight
a slice of rows at a time, so training runs through the model as loaded on the
card: the 1.5B trains in 3.3 s per run against 5.5 s on an f32 copy, with the
same recall.

Mem.LlamaChat: reasoning models answer with reasoning off (empty <think></think>
for the Qwen3 family, the final channel for gpt-oss), training examples to
match, and a leading <think> block is cut from answers and the stream.
Qwen3-14B now trains (recall 2 of 3 in 12 s); gpt-oss-20b and Qwen3.8-27B chat
but abort in training (no llama.cpp backward for MoE routing or Gated DeltaNet).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
@FMXExpress
FMXExpress merged commit bea2b69 into main Nov 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants