DEV Community

Abrham Achemo
Abrham Achemo

Posted on

Two AI agents for the AMD AI League: code repair and a hidden-map game on AMD GPUs

The AMD AI League by lablab and AMD planned a series of matches. Matches 5 and 6 no longer appear on the League page, but by then I had built entries for both and run them on a real AMD Instinct MI300X. The lessons were too useful to keep to myself, so here they are, and the Match 5 code is now open source.

Both were built to the League's shared rules: a Docker image on AMD's ROCm base, the model loaded on the GPU, the answer written to a JSON file, and roughly 30 seconds per item.

Match 5: an agent that repairs code

The task as I understood it: a bug comes in (a broken file and its tests, or a whole repository and an issue), and the agent sends back a fix.

Lesson 1: verify, don't trust

A 7B code model's first patch is a coin flip. So the agent never trusts a patch. It proposes, verifies, and keeps the best:

  1. Already green? If the tests pass on the original, return it untouched. An edit there can only lose points.
  2. Cheap mutations first. About 400 single-edit candidates: flipped comparisons, off-by-one bounds, // vs /, and/or, mutable default arguments. Lines named in the traceback go first. Each runs in its own throwaway folder. A fix is usually found in about 0.1 seconds, and this step fixes the whole family of classic bugs without touching the GPU.
  3. Then the model (Qwen2.5-Coder on ROCm), asked for a minimal fix. Every sample goes through the same checks.
  4. Rank by evidence: pass > compiles > unknown > fail > broken. If nothing beats the original, return the original.

On my 8 synthetic test cases, 7 were handled with no model at all.

Lesson 2: whole repositories are a different problem

For repository-level tasks (an issue plus a whole codebase, like SWE-bench), I split every source file into functions and classes, ranked them with BM25 against the issue, and showed the model only the best chunks of the top three files. The model answers with SEARCH/REPLACE blocks.

I rebuilt 25 practice tasks from the public history of requests, httpx, rich and fastapi, and measured each part on its own:

  • The lines the real fix touches were in the model's view in 20 of 25 tasks (up from 12).
  • A perfect answer made it through my own plumbing in 25 of 25 (up from 19).

Lesson 3: on the real GPU, speed was not the problem

On the MI300X, a 14B model read the prompt in under a second and answered every task inside the time limit, with a median of about 14 to 15 seconds. More time did not help: 25 s and 90 s scored the same.

The real failure was boring. The model's SEARCH text often didn't match the file, because it dropped the blank lines. Tolerant matching, plus rewriting the whole function when no edit applies, fixed that, and now 24 of 25 tasks end with a patch that applies (before, about half ended with no patch at all).

The honest score after that was 4 of 25 resolved. The remaining problem is choosing the right file. In six tasks the right file was ranked second and was even in the model's view, but the model edited the first one. That's the next thing I would attack.

Match 6: an agent that learns an unknown game

The brief: learn an unfamiliar strategy game, explore hidden maps, finish missions, and use as little compute and as few tokens as possible.

Lesson 4: the cheapest token is the one you never spend

  • A zero-token core. The agent keeps a map of everything it has seen, explores the nearest unseen edge, plans shortest paths, avoids traps and respects locks. Most moves need no model at all.
  • Read the rules cheaply. A regular expression reads legend lines like K = key first. Only if that fails does the model make one call that returns the rules as JSON, cached for the rest of the run.
  • Ask the model only when stuck, with a tiny answer and a hard token budget.

On a toy hidden-map game with keys, locked doors, traps and an exit, it won 100 of 100 maps with zero tokens. A stress test on 21x21 maps won 79 of 84 across seven map types.

Lesson 5: load the model once

A small model (Qwen3-4B) runs in a resident server that the container starts, so no game pays the load time. On the MI300X it loaded in about 14 seconds, used about 8.6 GiB of VRAM, and answered in about 1.2 seconds per model call.

Lesson 6: the GPU run found a bug the tests missed

When the rules named no actions, the model invented one ("move"). Every CPU test passed, including the ones with a fake model. The first real run on the GPU showed it. The fix was simple: keep only the actions the rules actually name. The lesson: always make one real run on the target hardware.

What carries over

  • Verification beats a bigger model.
  • Measure each stage separately (localize, apply, solve) or you can't tell what to fix.
  • Keep stdout clean, build for the right architecture, and load the model once.
  • Test on the real GPU at least once. AMD's free GPU access for participants made that possible.

The Match 5 code-repair agent is open source (MIT): https://github.com/abrsh43210/amd-code-repair-agent

My Match 4 entry (a web research agent) is public here: https://github.com/abrsh43210/amd-league-mc4-web-public

Built for the AMD AI League by lablab and AMD: https://lablab.build/ai-hackathons/amd-lablab-ai-academy-challenge

I used an AI coding assistant while building these entries.

Top comments (0)