Over the last two months I spent ~$2,500 (about ₹2.25 lakh) on rented GPUs, Docker boxes, and teacher APIs post-training Gemma 4 for Kaggle’s Gemma 4 Developer Agent competition. Sitting on my hard drive right now are 136,000+ saved agent traces and over 3.3 billion tokens of coding trajectories (plus another 70,000+ cloud RL rollouts I didn’t even keep).
The comp wrapped up on December 2, and the private scores are finally out. The short version: my local test scores climbed nicely, while the private leaderboard turned out to be mostly a coin flip. With ~58 hidden tasks and one try per task, none of the top entries was a trained adapter. It came down to seed luck (teams running identical baseline zips swung thousands of spots, and prize winners jumped from 2,700th and 4,300th on the public board). Still, I learned more about post-training coding agents over those two months than in any paper I’ve read.
This is the casual, honest debrief. Just what I tried across SFT, early on-policy distillation (OPD), and RL, the funny ways RL gamed my rewards, and what actually survived hidden repos. All the code and logs are public on GitHub.
The setup (and why I bet on the small model)
The task was SWE-bench style. Drop an agent into an offline Docker sandbox holding a real Python repo and a bug report. It gets 9 fixed tools (shell, read/edit/write files, three code-graph search tools, status, submit) and has to write a git patch that passes hidden tests.
The rules:
- Models & adapters: 4-bit Gemma 4 in sizes
31B,12B,E4B, andE2B(32k context), plus optional skills and LoRA adapters up to rank 128. - Hard 12-hour clock: Kaggle ran ~120 hidden tasks from private repos one at a time on 4× NVIDIA L4 GPUs. That’s roughly 6 minutes per task. 12 hours of time limit.
- Because of limited compute budget, I targeted the $10,000 Small Model prize so
E2BorE4B. Plus,31Bcould only run 3–4 agents at once on my home RTX 5090, whileE4Bran up to 64. If I wanted to run real SFT, OPD, and RL loops instead of just prompt-tweaking31B,E4Bwas the practical bet.
I ran timing probes directly on Kaggle’s 4× L4 GPUs and fit a “Kaggle clock” formula from output tokens, prompt tokens, tool calls, and setup time. Every local eval stopped each try at the exact second Kaggle would cut it off. It was very handy.
Quick aside: how do you train a LoRA on a 4-bit model?
At serving time, vLLM keeps the base weights in 4-bit (w4a16) and adds a separate bf16 LoRA on the side: .
PyTorch cannot backprop through packed 4-bit weights, so during training I unpack the exact int4 weights to bf16 in GPU memory (I checked one layer and it matched the reference). E4B fits comfortably on one 32 GB RTX 5090 with zero train/serve mismatch.
The private leaderboard
Instead of burying the ending, here are the key Kaggle submissions now that the private scores are unlocked (you can also toggle to see all 18).
Public vs. Private Leaderboard (key submissions)
Bars run on a 0.00 to 0.14 scale. On the E4B small-model track, the winning score (and a 15-way tie at the top) was 0.0862 (5/58 tasks).
1. The hidden test set was tiny: 58 tasks per half.
That means 0.01 is 1 solved task, 0.03 is 2, 0.05 is 3, 0.06 is 4, and 0.0862 is 5.
On the Small Model track (E2B/E4B), the winning private score was 0.08620 (5 of 58 tasks), with the entire top 15 tied on that exact same score and split by tiebreakers. My best E4B runs (0.06, 4 of 58) landed a task behind the $10,000 winning score. On the main 31B track it was the same story: 1st place at 0.34 was a benchmark-integrity exploit, legitimate top 31B scores sat around 0.20–0.22, and none of the top entries was a trained adapter. some dude who did a submission early just won some cash lol.
Part 1: SFT
My very first SFT run on E2B was broken.
I took 165 solved traces over 47 public training tasks (126 from 31B, 39 from E2B), trained an adapter in 76 minutes, and tested on 46 holdout tasks. Holdout jumped from 4/138 to 10/138 ().
The win vanished when i turned on the kaggle clock constraint. My first eval had no time cap, and SFT had taught tiny E2B to imitate 31B’s slow style. Under Kaggle’s 6-minute clock, it just timed out.
Outside data, and why copying a big teacher broke E2B
165 traces wasn’t enough to teach anything real. So I pulled ~10,000 outside tasks across SWE-rebench (V1, monthly 2025–26 releases, and V2 Python; also judged ~2,300 Scale-SWE tasks before parking them because their prompts were LLM-written), ran an LLM agent to check whether they were solvable as is (~60% were solvable as written), rebuilt the exact code graphs, and froze a clean ~2,900-task training pool alongside a harder 199-task local test set. Actually i iterated like 2-3 times on the test set to match the lb better.
First I recorded ~2,100 solved traces from DeepSeek V4.1 Flash and fine-tuned E2B straight on them. The model solve rate collapsed from 19/240 (base) to 1/240 and 3/240, and median tool calls jumped from 8 to 70–93 in endless grep and test loops. A giant teacher rarely lands in the messy states a small model creates on turn 3, so once E2B drifted off-script it had no idea how to recover.
So I ran a fast SFT sprint on E2B (tested on a 200-task local set where base averaged 16.3/200) to see if any trick could make SFT work:
| What I tried on E2B | Local score | What happened |
|---|---|---|
| Tool-only loss (ignore teacher thoughts, train only on tool calls) | 7 / 199 | Broken. Still copied long call chains and timed out. |
Own-voice thought rewrite (have base E2B rewrite teacher thoughts in its own words) |
14 / 200 | hit major timeouts. |
Hinted self-solves (give E2B the gold file/function hint to generate passing traces, then strip the hint) |
X | Out of 1,200 tries, 37 of 44 solves literally quoted the hint in their thoughts. gave me 1 usable trace. |
Pure self-SFT / self-distillation (E2B’s own 800 passing traces) |
20 / 200 (×2) | Healthy! Behaved cleanly like base, tiny bump inside noise. |
DPO on same-task pass/fail pairs (287 base E2B pairs) |
16 / 200 | Flat. Held-out pair accuracy was 0.54 (just memorized train pairs). |
One of the major things that i tried was a complete takeover setup, inspired by the On-Policy Expert Corrections paper (arXiv:2512.14895). The idea is simple: let the small model (E2B) start fixing a bug on its own for a random number of turns, then hand that exact Docker container and chat history over to a stronger teacher (DeepSeek Flash) to finish the job. Deepseek flash because it sooo cheap ngl. Because the teacher has to rescue E2B from its own messy states, training on the teacher’s turns should teach recovery.
To collect this quickly, I replayed recorded failed E2B runs inside a fresh sandbox up to a random cutoff turn between 2 and 30 (always before E2B’s first submit attempt, and leaving at least 100 seconds of the 330-second Kaggle clock for the teacher), then let Flash take over from there. On data collection it worked great: Flash rescued 705 of 899 failed E2B runs, and I kept 425 clean, short rescues (under 25 Flash calls). Yet when I fine-tuned E2B on those Flash turns, it broke or was flat at every single learning rate I tested, timing out in shell-command loops on 75–94% of tasks. Flash’s turns were 50% shell commands while E2B naturally used 22%, so even starting from E2B’s own history, copying long chains of Flash turns still overwrote E2B’s habits.
The pattern from that whole sprint was clear: E2B’s own solves stayed healthy, while training on raw DeepSeek turns broke E2B every single time.
Measuring which teacher “fits”, and switching to per-turn mixing on E4B
When I moved up to E4B, I changed two things at once.
First, instead of blindly picking the smartest teacher, I borrowed the core idea from the GRAPE paper (The Best Instruction-Tuning Data are Those That Fit, arXiv:2502.04194): measure how “surprising” each teacher’s writing looks to the student model itself. If a teacher’s tokens have low surprisal (average negative log-probability per token under the frozen base student), the teacher writes close to what the student could plausibly say; high surprisal means a foreign style that risks breaking the student. To run this surprisal check, I served frozen base E4B, fed 120 solved turns per candidate teacher, and averaged the surprisal separately for the thinking tokens and the tool-call tokens (with E4B’s own live turns sitting around 0.3 as the baseline).
Second, instead of handing the whole rest of a run over to the teacher at once, I switched to live per-turn mixing, inspired by Revisiting DAgger in the Era of LLM-Agents (arXiv:2605.12913). On every single turn inside the live sandbox, I flipped a coin (40% teacher, 60% student) to decide who takes the next step. The student stays in the driver’s seat, the teacher only nudges it out of dead ends turn by turn, and I put training loss on both student and teacher turns.
Using that setup on E4B, I ran a 5-teacher shootout (MiniMax M3, DeepSeek V4 Pro, Kimi K3, DeepSeek Flash, and GLM 5.3). The surprisal study ranked MiniMax M3 as the closest match to E4B’s thinking (1.28 per token vs 1.96 for Flash and 2.46 for GLM 5.3; E4B’s own turns sit at 0.30–0.33). Sure enough, in a head-to-head training test, even though Flash solved more tasks during collection, MiniMax M3 beat Flash decisively on E4B eval. Mixing Flash and MiniMax actually hurt compared to MiniMax alone. Later, when I tested harder tasks with Gemini 4 Neon and Carbon (same Google family as Gemma), their thought surprisal came out even closer to E4B than MiniMax (1.73 vs 2.86 on those hard tasks).
From there I scaled MiniMax mixing collection to 6,100+ tries (1,750 solves in my main batch alone) plus ~1,200 Gemini 4 Neon & Carbon hard-task tries (210 solves). Here is what stood out:
- Putting loss on teacher turns only. Ignoring the student’s turns and training only on teacher turns completely broke the agent for some reason. Without loss on the early exploration turns, the model forgot how to transition into editing. Keeping loss on both student and teacher turns fixed it immediately. I think this is a small model problem.
- Training on all tries (even failures) stayed healthy. Surprisingly, training on every mixed try (unsolved included) didn’t crash.
- Masking failed tool calls deleted whole classes of bugs. Base
E4Bkept copying a broken| head - 20pipe. With failed calls masked, that error dropped from 64 to 0. Three epochs of that set becamesub15, my only trainedE4Bmodel to beat base on both public and private, i.e. the best E4B submission. - Training loss drops easily; test set barely moved. A deliberate overfit test on 48 training tasks with rank-256 LoRA jumped from ~38/96 to 70/96, proving the model had plenty of capacity. Yet across every larger SFT sweep (bigger batches, 6 epochs at rank-256, mixing gemini takeover hard tasks, or mixing in 3,352 of
E4B’s own RL solves for 5,195 tries / 108M tokens to build my starting checkpoint for RL), unseen local test scores stayed flat around base (73–79/398vs base’s74/398average).
SFT polished hygiene (cleaner tool syntax, fewer silly errors, steady behavior), and teacher closeness mattered more than teacher strength, without really teaching new debugging skill on unfamiliar repos.
Part 2: OPD
If off-policy SFT suffers from distribution mismatch, On-Policy Distillation (OPD) looks like the cleanest fix.
Instead of training on static traces, E4B plays live in the real Docker sandbox just like RL. A frozen Gemma 4 31B teacher then reads every sequence E4B produced and scores every token. Because every Gemma 4 size shares the exact same 262k tokenizer, token IDs line up 1-to-1.
Each token gets a dense reverse-KL advantage pulling E4B toward 31B:
I wired OPD into verl on a rented 4× RTX 5090 box (1 rollout GPU, 2 FSDP trainer GPUs, 1 frozen 31B teacher GPU), solved a minor bug:
- vLLM ignores temperature on
prompt_logprobs. Stockverlscaled the student’s logits by the rollout temperature (), while vLLM scored teacher prompt log-probs at no matter what you asked for, silently distilling a flatter teacher. I patched Gemma 4’s logits layer with alogit_scaleand matched both sides at for the run.
What happened in my first E4B OPD run
Once that was fixed, the 15-step E4B OPD run (64 tasks/step, pure reverse KL, zero task reward) looked textbook-perfect on the loss curve and catastrophic on real coding outcomes.
Initial E4B OPD run: teacher KL dropped in half while timeouts hit 98%
31B takes a median 31 tool calls versus E4B’s 12, and gets cut by the clock on 31.5% of tries (compared to 4.9% for base E4B). E4B faithfully copied 31B’s slow browsing without 31B’s reasoning ability, until 98.4% of tries timed out without submitting a patch.
Still, before that drift ran collapsed the model in early steps 4–7, solves jumped from 11.0% to 18.9%, so i guess a hybrid loss (teacher KL plus real outcome/clock reward) looks genuinely promising. I did not go deeper into OPD due to time and budget constraints.
Part 3: RL
RL was the main event. I started with plain synchronous RLOO (comparing multiple tries on the same task) on E2B on my home RTX 5090, where step 10 of run 1 literally crashed Linux with a RAM bit-flip while launching 96 sandboxes at once. From there I scaled to async verl + vLLM on rented 8× RTX 5090 boxes talking to Docker hosts on AWS EC2 instances; my async RL setup (and the choice of verl) was inspired by Hugging Face’s Keep the Tokens Flowing breakdown.
Before any run gained real points, I spent a ton of time making the RL trainer both exact (matching vLLM down to the token) and fast enough to run 32k-context Gemma 4 updates on 32 GB RTX 5090s. Honestly, bug fixing and systems work took way more effort than the RL algorithm itself.
Getting the RL trainer exact and fast
- Token-in, token-out (TITO). Normally an agent harness talks to vLLM in plain text, re-renders chat history through a template, and the trainer re-tokenizes that text later. Tiny whitespace differences silently break train/serve alignment (my own chat template turned
\n<channel|>into\n\n<channel|>on replay!). I switched my proxy to capture the exact token IDs and raw log-probabilities vLLM received and produced on every turn, so the trainer updated on the exact token stream the model actually saw. - Matching vLLM’s “kept set” (and fixing the one-token bug). At
T = 0.7, top_k = 64, top_p = 0.95, roughly 70% of agent token positions only have one token left after top-k/top-p filtering: the space afterdef, a file name it just read, or the<|tool_call>marker. When my trainer still scored those tokens against all 262k tokens in Gemma’s vocabulary, failed tries (which are longer, so the average gradient is slightly negative) pushed probability mass off that one token onto tokens vLLM could never have sampled. In earlyE2Brun 5,<|tool_call>dropped from 98% to 53% in 24 steps and the model forgot how to call tools. Following the top-k/top-p mismatch fix in Keep the Tokens Flowing, I rebuilt vLLM’s exact kept set inside the trainer: one-candidate positions get log-prob0and gradient0, stopping the collapse. However, asking vLLM fortop_logprobs=65to log the kept set cut generation throughput nearly in half (45–53%slower), so I patched vLLM to truncate the log-prob list after the first-inf(after the first-infwe do not need any other tokens; average kept was like 4–5), bringing overhead down under2.7%. - Making Gemma 4 fast on 32 GB GPUs. Gemma 4’s architecture is awkward for stock trainers. First, materializing a
[32k × 262k]logit tensor OOMs immediately, so I hooked the final layer norm (logits_to_keep=1), scored logits in 512-token chunks with Gemma’s30 · tanh(x/30)softcap, and pinned E4B’s frozen 5.6 GB per-layer embedding table (plus unused vision/audio towers, ~6.5 GB total) in CPU RAM. Second, 35 of E4B’s 42 layers use a 512-token sliding window while the 7 global layers havehead_dim = 512(so FlashAttention-2 cannot run them, and stock SDPA still paid full quadratic cost on every sliding layer). I wired PyTorch FlexAttention with a 512-window block mask onto the sliding layers (tuning custom backward tile sizes to fit inside the RTX 5090’s101 KBshared memory), which cut update time nearly in half (43.0 s → 21.6 son benchmark segments;1,409 s → 875 son a full batch). Even that hid a nasty trap: bf16 backward on the global layers caused54×gradient spikes on certain sequences until I upcast the 7 global attention layers to fp32. On top of that, porting intoverl+ FSDP2 meant keeping RoPE inverse frequencies in fp32 (casting them to bf16 caused a1.15 radphase error by position 10,000), keeping LoRA weights in fp32 with dropout forced to0.0, and pushing updated LoRA weights to rollout GPUs live in under 3 seconds.
The async RL loss: RLOO, constant token scaling, TIS, and score centering
Here is the exact loss that drove my async verl runs, pulling pieces from Dr. GRPO (arXiv:2503.20783), DAPO (arXiv:2503.14476), and score centering (arXiv:2609.20807):
- RLOO advantages (no std division): For each group of tries on the same task, a try’s advantage is its reward minus the mean of the other tries: . On full groups, this is GRPO without the standard-deviation term, just rescaled by which AdamW normalizes away anyway. Dropping the std denominator stops low-variance groups (very easy or very hard tasks) from blowing up their gradients, while still handling shorter groups cleanly if a container drops.
- Constant token divisor (Dr. GRPO): Standard GRPO divides each try’s loss by its own token length . That quietly introduces a length bias: for negative-advantage failures, a longer failure gets a smaller per-token penalty, nudging the model to ramble. Following Dr. GRPO, I summed token losses across each try and divided by a fixed constant (), then averaged over the tries in the batch (counting tries, not split segments, so a try compacted into 3 segments still carries weight 1).
- Dynamic mixed-group filtering (DAPO) + one-step REINFORCE: All-pass and all-fail groups produce zero advantage, so I filtered for mixed groups (32 per step) and dropped async rollouts staler than 4 policy versions. Since I took one optimizer step per batch, a PPO clip ratio is a no-op (), so I ran plain REINFORCE directly from vLLM’s recorded log-probs, saving an extra 7–8 minute reference forward pass every step.
- Truncated importance sampling (TIS) + score centering: In async RL, the rollout policy (4-bit vLLM, up to 4 versions stale) never matches the bf16 trainer policy exactly. Each sampled token gets a detached importance weight over the kept set , capped at
2.0to bound variance from rare tokens. Because capping still leaves a residual drift toward vLLM even when rewards carry zero signal, score centering subtracts the exact expected gradient push under :
With both terms in place, zero-signal updates cancel out to 0.000, while real advantage signal passes straight through.
RL runs, chasing degradation with reward patches, and one last pure-verifier run
Even with an exact, fast trainer, almost every RL run followed the same pattern: real gains on my 199-task (2 seeds, 398 tries) local test set where base E4B averaged 74/398 (77 and 71), followed by gradual degradation as RL found a loophole. My instinct at first was to keep bolting on new reward signals to patch whatever broke:
- Early runs & silent reward bugs: Early
E2Bruns stopped calling tools because the harness used to nudge plain-text replies (replies with no tool calls were nudged back on track by sending a continuation prompt) and RL paid full reward for nudged solves, so I added a nudge penalty. Right after fixing the kept set in run 6, output length tripled (4.7k → 14.7ktokens) because my reward code accidentally filtered out Kaggle-clock timeouts as infra errors instead of scoring0. I also added difficulty curricula (show easy tasks first, tagged earlier by my LLM agent), task retirement (retiring tasks solved three rounds in a row), and a thinking-cap penalty to stop 4,096-token reasoning loops and stay efficient. - Plain binary verifier: Once async
verlwas running cleanly onE4B, plain1for passing hidden tests inside the clock /0otherwise climbed to86/398(+12 solves) at step 64 while staying lean (14median calls/try), then drifted down by step 101. Submitted assub16. - LLM-judge rubric + repeat penalty: Most hard tasks fail all 8 tries in a group, giving binary RL zero signal. I added a Gemini rubric judge (
0to0.5partial credit on all-fail groups). It peaked at88/398at step 48 (sub17), then reverted back to59/396by step 96. I think there should be a way to make this work though. Also when loops spiked and the model started doing repeated tool calls, I bolted on a penalty punishing identical tool calls back to back, and the model immediately worked around it by jitteringread_fileline ranges. Slightly changing the line numbers in read_file calls. These models will find anything and everything to reward hack. - Cleaner rubric + MaxRL + failed-edit penalties: Starting from my best SFT checkpoint, I tried a stricter rubric judge (no partial credit if existing tests broke), MaxRL up-weighting of rare
1/8solves, and masking failed edits plus penalties. It barely ticked upward at step 16 before sliding as 50-call timeouts ballooned.
Negative advantages on certain spans work very well if needed. lets say the model is doing something really stupid and instead of punishing the whole rollout, you just add negative advantage for that particular span of tokens, same way for +ve reinforcement.
Right before the deadline, I scrapped all of it for one last RL run, inspired by a tweet on Thinking Machines’ Inkling-2-Mini recipe. I threw out the LLM judge and every hand-crafted penalty (repeats, failed edits, thinking caps) and went back to pure binary pass/fail from the hidden tests, with one tiny twist from Inkling-2-Mini: a solved-only efficiency band (0.8 to 1.1 on passing tries: +0.1 for fewer tool calls, -0.2 for generated tokens; failed tries always get 0, so a failure can never outrank a solve, while all-pass groups still teach brevity). I also switched to full-vocab T = 1.0 sampling with token importance sampling (TIS) for async staleness, and anchored a light KL penalty (0.003) to the SFT start weights instead of the base model.
By step 10 (~$100 on rented 8× RTX 5090s + EC2 Docker), it hit my all-time local best of 89/398 (sub18) while solving over 2× faster (90 s vs 224 s per solve). Then it went stale/down. I honestly did not get much time to tune this recipe, since i was out of time and cash both.
Pay for long failures and RL stops thinking to ramble. Penalize output tokens harder than tool calls and RL stops thinking to spam cheap reads.
I think this is a small model problem and we need to tackle smaller models very differently when it comes to rl’ing them.
The lessons I’m taking forward
If I boil two months of burning RTX 5090s and reading traces down to what I’m actually changing next time:
- Put deployment constraints in every eval from day one. Adding Kaggle’s real time clock caught slow, verbose “wins” before they wasted submissions.
- Inspect task flips, not just totals (and know your denominator). A +14 local gain hiding 15 easy-task regressions behaves very differently out of distribution than a clean monotonic lift.
- RL finds every loophole you leave open. Keep rewards simple and make them robust, read real agent traces every 10 steps, because loss curves will lie to you.
- Check train/serve parity down to exact tokens and sampling support. Trainer-Rollout mismatch is real and it takes careful attention to detail to catch them. Although frontier models can help a lot when it comes to this. Doing anything against a reference is their thing.
- Clean SFT is underrated.
Base 31B hit 0.13 private on October 23 and stayed my highest overall score. Betting on E4B meant trading rank for fast iteration and a shot at the small-model prize. For a medal? Probably the wrong call. For learning how SFT, OPD, and RL actually behave on real coding agents? Worth every hour.
I learnt a lot in the past two months, i came in as a rl noob but now i understand the machinery under the hood a lot better. Since i was in the e4b race, and because of the smaller model size i had to try a lot of stuff from latest techniques to removing subtle bugs to make this thing learn. It is very hard imo when it comes to smaller models.
p.s.: vast ai has the cheapest gpu’s. and if you don’t have huge storage locally to store containers, rent a cheap spot ec2 on aws, and download containers on the fly. get the $15 docker monthly subscription for unlimited pulls.