# ENA — Project Log A complete record of the ENA (DREAM BBQ) fine-tune: every attempt, every failure, every wrong turn, and what actually worked. Hardware: Ryzen 7 3700X, 16 threads, 15.5 GiB RAM, AMD RX 6600 (Navi 23 / gfx1032, 8.57 GB VRAM), Nobara Linux, btrfs. A machine with no case, held together by 3D-printed parts, sitting on the floor. --- ## 1. What ENA is ENA is a character from *ENA: DREAM BBQ* (Joel G). Two halves in one body: a cheerful SALESPERSON who sells you things you didn't ask for, and a MEANIE who is blunt, loud, and has no patience. The voice switches mid-sentence. That split is the whole point of the character and it is what the dataset had to teach. This is a fan-made LoRA, non-commercial, built for research and roleplay. All character rights belong to Joel G. --- ## 2. The base model decision The base was fixed by the project owner and never in question: ``` /home/ryzen/foryou/Qwen3.5-2B-Uncensored-HauhauCS-Aggressive-Q4_K_M.gguf 1.27 GB 1,882,736,832 params 24 layers 248,320 vocab Hybrid architecture: 6 full-attention blocks + 18 gated-delta-net (SSM) blocks ``` **Why it caused difficulty:** Qwen3.5 is not a plain transformer. The delta-net blocks need `flash-linear-attention` and `causal_conv1d` for their optimized kernels. Neither has working ROCm support, so every run fell back to reference PyTorch implementations. That fallback is slow *and* numerically fragile in bf16 — it was the source of most of the NaN problems below. --- ## 3. Timeline of attempts and failures ### Attempt 0 — The lost session An earlier session held the working thread of this project. It was deleted by the project owner while cleaning up sessions. What was lost was the *narrative*, not the artifacts — `~/spamtrain` still held the base, corpus, adapters, and training scripts. Command lines were recovered afterwards from `~/.hermes/logs/process-results/*.json`. **Lesson:** state.db is a transcript, not a backup. Long-running work needs its own log file on disk. --- ### Attempt 1 — The silent no-op install The first ROCm attempt appeared to succeed and did nothing: ``` Checked 1 package in 28ms INSTALL EXIT=0 ``` **Cause:** `uv venv` does not install pip, so `python -m pip` was dead. Then `uv pip install torch --index-url .../rocm7.1` saw `torch` already satisfied as `+cpu` and skipped it — exit code 0, no download, no GPU torch. **Fix:** pin the build explicitly as `torch==2.13.0+rocm7.1` so the resolver cannot fall back to a CPU wheel. Fresh venv at `~/spamtrain-rocm`. **Lesson:** exit code 0 does not mean the package installed. Verify by importing. --- ### Attempt 2 — ROCm brought up successfully Nobara already shipped ROCm 7.1.1; `rocminfo` saw the card as `gfx1032`, 28 CUs, with `/dev/kfd` and `/dev/dri/renderD128` live. Only PyTorch was missing. ``` torch 2.13.0+rocm7.1 | hip 7.1.52802 available: True | count: 1 device: AMD Radeon RX 6600 matmul ok 20x2048^2 bf16 in 0.12s (2.98 TFLOP/s) SETUP EXIT=0 ``` `HSA_OVERRIDE_GFX_VERSION=10.3.0` was required because gfx1032 is not on AMD's official support list. This part genuinely worked. --- ### Attempt 3 — GPU training hits NaN The run loaded, printed `device: cuda (AMD Radeon RX 6600)`, took real steps at ~1.7 s/micro-batch (about 50x faster than CPU), then reported `loss nan`. A forward-only sweep over all 680 examples found **zero** NaN-producing inputs, which located the problem in the backward pass through the fallback SSM kernels rather than in the data. Then it died separately: `HIP out of memory`. With gradient checkpointing off, 4.5 GB of weights plus activations did not fit in the ~6.6 GB left after the desktop compositor took its share. **Fix (partial, in `train_ena.py`):** force the stable triangular-solve branch by telling the model it is being exported: ```python import transformers.models.qwen3_5.modeling_qwen3_5 as _q35 _q35.is_torchdynamo_exporting = lambda: True ``` The comment in the source records the measurement: the hand-rolled forward substitution overflows and returns NaN on ~7% of real inputs (47/680 corpus rows); the triangular-solve branch is stable. --- ### Attempt 4 — The GPU hard reset (the bad one) Training was resumed on the GPU with checkpointing on. The display began artifacting across the whole desktop. Kernel log: ``` amdgpu: ring gfx_0.1.0 timeout, signaled seq=1241226 amdgpu: Starting gfx_0.1.0 ring reset amdgpu: Ring gfx_0.1.0 reset failed amdgpu: GPU reset begin!. Source: 1 amdgpu: Failed to restore process queues amdgpu: VRAM is lost due to GPU reset! amdgpu: GPU reset(3) succeeded! ``` Preceded by page faults attributed to `firefox` and `plasma-keyboard`, and `Failed to pin framebuffer: -ENOMEM`. This was a **full GPU reset with VRAM loss**, not the usual recoverable compute ring hiccup. The run was killed by it (`TRAIN EXIT=143`). **Decision made afterwards: GPU training on this card is off the table.** An 8.57 GB card shared with a Wayland compositor cannot host this model's training and the desktop at the same time. Stability beats speed. --- ### Attempt 5 — Chunked loss (fixed OOM, did not fix NaN) Diagnosis of the OOM was correct and useful. HF's `ForCausalLMLoss` calls `logits.float()`, materialising the entire `[tokens, 248320]` fp32 tensor at once — about 381 MB for a 384-token row, on top of 3.5 GiB of weights. A `chunked_ce()` was written to slice the vocabulary and cut peak memory: ``` weights 3.55 GiB peak 4.56 GiB (was OOM at 7.98) loss 13.78 → 11.30 → 11.87 all finite ``` The fix worked — no OOM, and the probe over the first three batches was clean. **But the full run still diverged:** `WARN non-finite loss (micro 11)`. The OOM and the NaN were separate problems, and chunked loss only solved one of them. The change was reverted. It is not in the current training script. **Lesson:** a clean three-batch probe does not prove a run is stable. Do not declare a training fix validated until the whole epoch has passed. --- ### Attempt 6 — CPU training, the one that works The existing `spamtrain` venv has `torch 2.15.0+cpu` — `torch.cuda.is_available()` returns `False`, so it **cannot** touch the GPU even by accident. In fp32 on CPU the SSM precision problem disappears entirely. A smoke test on 8 examples confirmed it before committing hours: ``` device: cpu (cpu) examples: 8 ep1 step 1/1 loss 2.7831 2.0m saved /home/ryzen/spamtrain/_smoke_test ``` Loss finite, adapter saved. Then the full run was launched on all 680 examples. Early curve: ``` ep1 step 1/85 loss 2.6761 1.7m ep1 step 2/85 loss 2.6320 3.4m ep1 step 3/85 loss 2.2711 5.3m ep1 step 4/85 loss 2.1912 7.5m ``` Roughly 2.1 minutes per step, 85 steps. Slower than the GPU by a factor of ~50, but it does not artifact the display, does not reset the card, and does not NaN. **This is the run that finishes.** --- ## 4. Errors found and fixed in the GGUF → HF conversion Training a LoRA on a Q4_K_M GGUF is not possible directly — 4-bit blocks are lookup tables, not differentiable weights, so there is no gradient through them. The file had to be expanded to bf16 first: 1.27 GB → 3.76 GB. Same parameters, same values, unrolled. `gguf_to_hf.py` was written to do that, and produced a model that loaded but generated garbage: llama.cpp answered " Paris." while transformers answered " isbeiratesے". **The bug: Qwen3.5's RMSNorm is zero-centred.** The layer computes `x * (1 + weight)`, but the GGUF stores the *finished* weight (~1.0). Feeding those values straight into transformers added 1 a second time, so all 24 normalisation layers were scaled ~2× too large. Twenty-four layers of that and the output is soup. Fixing the offset made the expanded model match llama.cpp token for token: " Paris.", " 2", " a beautiful place." **Verification of the dequant itself:** 0.14% error against llama.cpp's own dequantiser, measured on attention, MLP, and embedding tensors. Ruled out along the way: bf16 vs fp32 (CPU fp32 failed identically), ROCm vs CPU, and the tokenizer. It was purely the normalisation offset. --- ## 5. Hyperparameters (deliberately gentle) An earlier 0.8B run had caused catastrophic forgetting — the model lost its knowledge of quantum mechanics and began asserting false physics. The cause was over-training: lr 2e-4 × 2 epochs down to loss 0.13. This run is tuned to install a voice without flattening the base model: | setting | value | reason | |---|---|---| | LoRA r | 16 | narrow — enough capacity for a style, not a rewrite | | lora_alpha | 32 | alpha = 2r | | lora_dropout | 0.05 | light regularisation | | target modules | q,k,v,o,gate,up,down | all attention + MLP projections | | learning rate | 1e-4 | half the rate that caused forgetting | | schedule | OneCycleLR, pct_start 0.03 | short warmup | | epochs | 1 | one pass only | | max length | 384 | corpus averages ~950 chars | | accum | 8 micro-batches | effective batch 8 | | dtype | fp32 (CPU) | bf16 is where the SSM NaN came from | | precision guard | `is_torchdynamo_exporting = True` | forces stable triangular solve | Trainable parameters: **10,911,744 / 1,892,736,832 = 0.5765%** --- ## 6. The dataset `ena_corpus.jsonl` — 680 examples, 645,139 characters, ~948 chars average. ``` role counts: system 680, user 680, assistant 790, tool 110 ``` The 110 tool turns and the extra assistant turns exist because some examples are multi-turn (including tool-call examples) to teach the character's cadence across a conversation rather than single responses. Tool-call examples go through `apply_chat_template` because that format is intricate; plain examples are built by hand so that thinking stays off and the loss mask lands exactly on the assistant span. System prompt (excerpt): > You are ENA, from ENA: DREAM BBQ. You have two sides and both talk. Your > SALESPERSON side is cheerful, calm and persuasive - it offers deals, compliments > people, and sells them things they did not ask for. Your MEANIE side is blunt, > loud, sarcastic and easily annoyed by nonsense; it swears, it yells into a > megaphone, it has no patience. You switch between the two mid-sentence. This is > normal. You live in a dream desert... --- ## 7. Reference: a completed run on the same corpus A previous, smaller run (758M parameters, 998 examples, r=16) completed cleanly and is useful as a sanity check on what a healthy curve looks like: ``` ep1 step 10/249 loss 2.0241 ep1 step 30/249 loss 0.4486 ep1 step 60/249 loss 0.2944 ep1 step 100/249 loss 0.1679 == epoch 1 done, elapsed 75.9m ep2 step 130/249 loss 0.1402 ep2 step 240/249 loss 0.1299 == epoch 2 done, elapsed 150.4m TRAIN EXIT=0 ``` Loss 2.02 → 0.13 over two epochs, no NaN. This is what "working" looks like on this corpus and hardware. --- ## 8. Environment notes worth keeping - `HSA_OVERRIDE_GFX_VERSION=10.3.0` is required for gfx1032 on ROCm. - `uv venv` does not ship pip; use `uv pip install --python /bin/python`. - Always pin ROCm torch as `+rocm7.1` or the resolver silently picks `+cpu`. - llama.cpp now uses semver tags (`v0.5.0`), not bare `b`-numbers. - On this RX 6600 a wedged compute ring shows as `vk::Queue::submit ErrorDeviceLost` plus `comp_1.x.x timeout` in the kernel log. It is **not** out-of-memory. Check `journalctl -k` and `rocm-smi` before shrinking context. - Check VRAM with `rocm-smi` before blaming the desktop: at one point the card sat at 85 MB used while the desktop was blamed for an OOM that was actually the vocab-sized logits tensor. --- ## 9. What is deliberately NOT in this repo - No character artwork or game assets. All rights belong to Joel G / ENA team. - No personal information about the operator: no name, no location, no IP. - Not for commercial use. --- *This log is compiled from the training logs, ROCm setup logs, kernel journal, and session transcripts on the machine that did the work.*