Retrieved article excerpt
Open article · Retrieved 2026-11-20T19:25:30.527258+00:00
[Ankit Gupta](https://ankitg.me)
- [Blog](https://ankitg.me/blog)
- [Contact](https://ankitg.me/contact)
/
- [Github](https://github.com/ankitvgupta/)
/
---
# Vibecoding an inference chip
Or rather, I vibe-coded an FPGA into running an LLM. And it… just worked.
Friday. November 20, 2026
One of the more entertaining things about programming recently is that coding agents let me work in entirely new domains by giving me access to new programming languages and paradigms. Lately, that has meant hacking on hardware, now that writing low-level software is much easier. So, in this blog post, I’m going to try to recount the experience of vibe coding an FPGA, going through a series of “oh shit” moments several times, and giving myself a new appreciation for what’s possible if you have a large token budget (thanks YC) and interesting problems to point the models at.
I overheard some founders recently talk about how FPGAs work. I’ll admit I was relatively naive about them. I’d never really experimented with them in my startup or in college, so I knew little about them before. The basic idea I was familiar with: you can program a circuit into a reprogrammable chip. So rather than having a general purpose computing architecture (like a CPU) you can have a reprogrammable one, i.e. the configuration loaded onto the chip determines how its logic and routing are connected, and that (in theory) enables performance advantages. I also know that it took a mountain of C++ to write and involved manually analyzing waveforms for simulation and verification. I had never done this before though and it seemed cumbersome.
That’s about what I knew going into this.
Naturally, my ML brain thought “could we use these for AI inference”. I’m not the first to think this — there are a few repos attempting to port ML models to FPGAs on Github. But I hadn’t actually seen a writeup on whether coding agents are good at writing the low level C++ and Verilog code to program them and verifying the outputs so that they actually run accurately. (Spoiler alert, they are incredible at programming them.)
So I decided I needed to get my hands on one. AWS has F2 instances with FPGA hardware, and that seemed easier than going and buying physical hardware, so I asked Codex to spin up a reservation and got cooking. It had a relatively limited memory of 16 GB of FPGA HBM. Around the same time, I was working with the DeepGrove founders who were discussing their new ternary weight architecture that is well suited for memory limited cases. It’s SOTA on Mac hardware with actual agentic tool calling, so I figured why not, let’s see if I can get this working on an FPGA and fast enough to be useful.
What followed was a cloud agent running in Conductor for several days with me mostly just encouraging it periodically while it both (1) got a model fully running and (2) increased its speed by 33× from the first full-model bit-exact baseline to get it to a real-time relevant speed. It was one of the most mind blowing autoresearch loops I’ve run, ultimately writing roughly 3M lines across the experiment history and parsing 30M lines of output files, burning only $10,000 in Claude and OpenAI tokens to run hundreds of experiments. Most of the code is C++ and some Verilog. It’s been probably a decade since the last time I wrote any serious amount of C++ and I’ve never written Verilog. I honestly don’t know the first thing about Verilog. Most of my prompts were not particularly clever: they consisted mostly of me saying things like “you’re a superintelligent model, time to be more creative” and “let’s go for 2x faster, you got this”. Sometimes I brought some ML knowhow like “hey it’s time to consider speculative decoding” or “why is that running on CPU, you should port it”. But for the most part, it was just vibes and I’m pretty sure that with enough time the model would have figured out those things. Also, it seemed that both Astra and Opus (new Fable wasn’t out yet) were pretty capable at this and I could use them interchangeably. I’m sure someone has a good benchmark for which is smarter but both passed my smart-enough threshold.
[Timeline of 166 prompts and FPGA inference speed, highlighting seven steering prompts as throughput rises to 213 tokens per second](https://ankitg.me/assets/fpga-prompts.png)
Summary of my most impactful prompts. Most of that first third is just getting AWS set up and approving quota for f2 instances.
## From “it works” to 213 tokens per second
Getting faster, one experiment at a time
Measured benchmark tokens/s · select a step to see what changed
Baseline
6.43
Host overhead
8.07
Burst attention
14.02
Parallel router
20.53
Glue engine
30.24
New pipeline
49.21
Prompt speculation
51.25
Router relay
58.43
Head shadow
94.44
Draft model
105.63
Memory ports
108.81
Attention overlap
134.99
Weight packing
171.3
Re-speculation
184.19
Parallel head loader
213.13
**Step 14 · 33.13× baseline**
A head loader that reads both of its memory banks at once (+17.3%, measured on and off on one image), a runtime expert-prefetch policy, and the router-job timing fix; run one clock step lower (225/425 MHz) after a soak test found random faults at 231.25.
The chart follows the measured optimization sequence: **6 → 213 tokens/s**, or **33×** the baseline.
## How much did the human advice help?
At one point, around when it got to 10 TPS, I messaged the DeepGrove founders about this, and they replied surprised that it was working so easily, saying they had tried this a few months back and the models were not quite good enough to be particularly effective. They sent me a prompt that summarizes some of their lessons and I copy-pasted it into my session to see if it’d matter. It was essentially the most significant piece of actual guidance I added to this session. The prompt is reproduced below.
Read the full FPGA design prompt
here is what someone else did for a dense bs=1 decode optimized fpga implementation for a dense qwen style model with ternary weights. you should take this with a grain of salt and pick things that you believe are acutally useful to add to your plan. Please also dont do things if you dont think is useful that take a lot of times like runnning really long test of a cycle accurate simulation etc or like physical design since those can take like hours. here are some ideas please pick and choose use this as context and not somehting that you shoudl be strictly guided by somethings that could help. prioritiize speed of like getting this up and running though..
### MATMUL (TERNARY ENGINE)
- No multipliers. A 2-bit weight drives a 3:1 mux that picks x, ~x, or 0.
The unused 4th code raises an error flag, so corrupt weights get caught.
- Negation is ~x + 1. Lanes flag negatives, and the row reducer adds the +1s
once per row instead of once per lane.
- Activations are grouped integers: INT12, or INT16 where we needed more
range (MLP down projection). Reduce as integers, apply FP32 group scales,
accumulate in FP32.
- The pre-projection RMSNorm is deferred: quantize the activation first,
apply the normalization scale after accumulation. It’s cheaper and
numerically equivalent.
- 8 cores in two clusters. Projections that are independent (gate/up) run
at the same time on separate core groups.
- Result: about half the DSPs of an INT8/INT16 design at the same rate,
traded for more LUTs.
### MEMORY
- Weights are packed at 2 bits, 8x more per transfer than 16-bit. At batch 1,
weight fetch costs far more energy and time than the math.
- Weights stream from HBM straight into the compute lanes and skip the
on-chip buffers (they’re used once per token). Activations are cached next
to each core and reused across rows.
- HBM routing is one chain per memory channel instead of a big crossbar.
Lay out data so all 32 channels stay busy.
- On-chip buffers are typed slots with an explicit lifecycle
(open -> write -> commit -> read -> release). Each slot has a side memory
for scales/exponents. The buffer checks format, range and producer, which
catches scheduling bugs in hardware.
- The KV cache is MXINT8: 8-bit values with one shared exponent per
32-channel block. That’s small enough to stream, with accuracy held.
- For MoE: stripe each expert across every channel, and map expert ID to
address at runtime instead of using a fixed program.
### ATTENTION
- Attention streams over the cache in 64-token tiles with an online softmax
(FP32 running max/sum). The full score matrix is never stored.
- Probabilities are UINT16 and the context accumulates in FP32.
- Each attention unit interleaves two independent jobs on one datapath
(C-slow), which hides pipeline latency without duplicating hardware.
- Q/K head norm and RoPE got their own small vector unit, so they don’t
block the general vector path. The V projection overlaps with that work.
- New K/V is appended to HBM as soon as it’s produced. We used a sliding
window to bound cache reads.
### SCHEDULING
- One controller issues work in program order, with tags and barriers.
Engines overlap only when the buffer dependencies are explicit, so we got
overlap without races.
- For MoE: the router is the new critical path, because nothing can fetch
until it finishes. Keep it in FP32 (lower precision changed which experts
were picked), and overlap whatever you can around it.
### CORRECTNESS (maybe not neecessary to folow super close)
- We fixed a numerics contract first (formats, rounding points, operation
order) and built hardware to match it. Vector ops must match the reference
model’s order and precision, not just be “close”.
- Verification ladder:
1. Per-block cocotb unit tests.
2. One full layer co-simulated against the real checkpoint.
3. Multi-token, full 24-layer decode compared token-for-token with a
reference oracle.
4. Byte-level accounting of KV cache writes.
- We kept simulation results, timing signoff and board results separate,
and never claimed one from another.
- Every published number links to the report it came from.
### PHYSICAL DESIGN (maybe not necessary for u)
- The chip has 3 regions (SLRs). Keep wide datapaths inside one region and
register every crossing. Long links use credits, not combinational ready.
- We placed engines next to their data: memory logic near HBM, attention in
the DSP-dense region.
- Screen logic depth (10 levels max at 250 MHz) right after synthesis, and
fix it with pipelining, sharding, or C-slow. Full place-and-route is
saved for integration.
- Dev loop: small change -> lint -> unit test -> quick synthesis ->
depth/timing check -> restructure.
The coding agent diligently considered these asks, but it didn’t seem to make all that much of a difference qualitatively. Indeed, when I asked it later to read all of the logs and determine which of these instructions it actually used, it said:
Read the agent’s retrospective: what it adopted and rejected
Its biggest design ideas were already in my plan before you pasted it.
You pasted it on Oct 29 at 21:50 UTC: 4,741 characters describing what someone else did for a dense, batch-1, ternary FPGA decoder. Within 70 seconds I had sorted it into ten ideas to adopt and five to reject, and written that into every design agent’s brief. The shorter remark from your friend Edward, about using lookup tables as logic gates, came 24 minutes earlier and left nothing on the speed line.
**Design ideas I adopted: mostly confirmation.**
- Already planned: streaming weights straight into the compute lanes, running rows in parallel, and reading the attention cache in bursts were all in the design brief I’d launched 35–40 minutes earlier.
- Match what was later built:
- interleaved lanes in the router (step 3);
- a separate unit for head norms and RoPE (step 4);
- a program-order sequencer (step 5);
- a registered boundary on every crossing between dies (steps 8 and 12).
- I can’t show th