Factorio Agent Evals
Local Qwen agent evaluation, two QLoRA training rounds, and C++/CUDA inference optimization. The selected adapter produced 9.7% more plates on two validation factories.
Skills & tools
- Python
- PyTorch
- CUDA
- C++
- Transformers
- LLM evaluation
- QLoRA
- PEFT
- bitsandbytes
- Qwen3
- Linux
- Docker
- Compute Sanitizer
- Bash
- Docker Compose
- Ubuntu
- WSL 2
- Factorio Learning Environment

Overview
Factorio Agent Evals studies local LLM tool use, parameter-efficient fine-tuning, and GPU inference optimization. I built a Qwen3-4B agent with Python, PyTorch, Transformers, PEFT, and bitsandbytes, then evaluated its decisions through Factorio Learning Environment on an RTX 5070 Ti. A separate C++/CUDA experiment measures a custom RMSNorm operator inside Qwen.
Factorio provides the test environment: fuel, inventory, and production change after each action, so an agent has to maintain a factory over repeated decisions. The latest experiment completed two QLoRA rounds. On two validation factories, the selected second-round adapter produced 746 plates versus 680 for unchanged 4-bit Qwen, with zero failed actions versus eight.
I ran the experiments on Ubuntu 24.04 under WSL 2, using Docker Engine to host the Factorio server and a Linux Python environment for model inference, QLoRA training, and CUDA development. Factorio Learning Environment connected the Python agent to the server through RCON, allowing each validated action to change the simulation and return execution feedback.
Development work
I built the Python evaluation loop, validated JSON action adapter, observation and context handling, production-failure checks, and action-level logging. The adapter connects Qwen’s proposed commands to Factorio Learning Environment, records execution feedback, and advances the simulation by fifteen seconds per decision. Scripted controls check that the permitted tools can solve each fixture.
I also developed the supervised-data audit, QLoRA training workflow, checkpoint selection, and correction-verification pipeline. Each proposed correction is executed from the exact saved pre-action game state and must keep the factory producing through the original continuation horizon before it can enter a training dataset.
For inference optimization, I wrote a BF16 RMSNorm kernel with FP32 reduction and a C++ PyTorch binding. An instance-local adapter dispatches 73 full-width Qwen normalization modules to the custom implementation while preserving the existing weights.
Technical work
QLoRA trains 16,515,072 adapter parameters while the 4-bit base weights remain frozen. Each completed round used forty optimizer updates and 320 example exposures. The original dataset contains 320 verified, executed scripted examples; round two used 160 original examples and 160 samples drawn from thirteen distinct verified corrections, continuing the selected first-round adapter with a fresh optimizer.
The protocol fixes four training, two validation, and three reserved test fixtures before collection. Greedy decoding, automatic observations, two history pairs, and the fifteen-second simulation cadence stay fixed. Validation selects between update twenty and forty using survival, plate production, and an earliest-checkpoint tiebreaker. Logs separate context preparation, first-token latency, remaining generation, tool execution, simulation advancement, token counts, and GPU memory.
The CUDA track uses 256 threads per row and runs separately from fine-tuning and gameplay comparisons. Validation covered twenty-five correctness cases and bounded Compute Sanitizer memory, race, initialization, and synchronization checks. Offline model benchmarking compared eager, compiled, and custom implementations using ninety samples per backend per frozen prompt.
The runtime separates the containerized game server from the GPU-backed model process. Bash launchers coordinate Docker Compose server restarts and run the Python controllers under an ordinary Linux account. Pinned package versions, a fixed server-image digest, and saved-state hashes record the environment behind each experiment.
Challenges and decisions
The first training round regressed on validation. I retained those runs and used exact-state correction replays to build the second-round mixture rather than treating training loss as evidence of better gameplay. Across the workflow, eighteen of twenty-one correction replays passed; thirteen supplied round-two training data.
After round two, only five distinct eligible corrections passed replay and continuation. The frozen protocol required at least eight, so the workflow stopped before round three and the fifteen final-test episodes. The smaller correction set remains recorded as insufficient for training.
Benchmarking also required separate interpretations of behavior and speed. The selected adapter reduced failed actions and increased validation production, but did not make inference faster. Standalone CUDA timings and complete model-response timings have their own baselines; the custom kernel was not used in the QLoRA comparison.
A writable Docker save mount changed six master fixture archives during setup. I recovered their byte-identical originals and changed the restore workflow to mount disposable working copies instead. Hash checks and load receipts verify the starting state while keeping the master fixtures outside the server’s writable save path.
Results and current state
The selected second-round adapter increased combined validation production from 680 to 746 plates (+9.7%). Failed actions fell from eight to zero across 160 decisions per condition, a decrease from 5% to 0%. Both conditions reached the twenty-minute cap on both factories, so measured survival did not increase. These single-seed validation results were used for checkpoint selection; final-test evaluation remains unperformed.
All four second-round training factories reached twenty minutes. Their unchanged baselines lasted two, six, nine, and nineteen minutes. Those factories contributed training data, so this is a training diagnostic rather than held-out improvement. The workflow retained twenty-two model episodes and twenty-one correction replays. Each training round took about eleven minutes and peaked at 8.09 GiB of allocated GPU memory.
The separate RMSNorm experiment achieved 5.21× standalone speedup on a captured 1,006-row prompt shape and 4.80× on a single-token shape against the installed eager GPU reference. Complete offline responses showed 1.11–1.17× paired median speedups over eager execution across five frozen prompts, with identical greedy tokens and parsed actions. These timings establish an offline inference result, not faster gameplay. The repository retains reports, traces, pinned configurations, source snapshots, and hash-verification tools for both tracks.