byhandPro Tools

Diagram

Open the black box

A model is a black box. Most diagrams of it are too: a box marked "Attention" that never opens, and never shows its code.

The ByHand diagram tool opens them. It draws the diagram from the program itself, so every box opens, level by level, down to the lines of code it stands for. Gemma 3 1B starts as five boxes: the token embedding, Group × 4, SlidingLayer × 2, a norm and the LM head. Open Group and keep going until you reach Q, its norm and its RoPE. Click a box to see its lines; put your cursor on a line to see its box.

byhand
  1. 1
Diagram
Open in byhand Pro →

Open and close

Opening Group, then SlidingLayer, then SlidingAttention: Q, its norm and RoPE
  • Double-click a box to open it one level, or click it and press Enter. A hint beside the box you've picked says so.
  • Double-click an open block's title bar to close it. Whatever you opened inside it closes too.
  • Refresh the page to start over, every block closed.

A repeat opens to the one layer it repeats. In Gemma, Group × 4 opens to SlidingLayer × 5 and a global layer. SlidingLayer opens to its two sublayers, and SlidingAttention opens to the attention as the paper draws it: Q, K and V, a norm and RoPE on Q and on K, the scores, the sliding window, the softmax, and Out.

From a box to its code

Click a box and the code selects its lines. The cursor lands on the step that defines it, the matmul or the linear, not the block's first line. The other views follow the cursor, so the Shape view shows the tensors at that step.

From the code to its box

Putting the cursor on RoPE's line opens the diagram down to the RoPE on Q

Put your cursor on any line. The Diagram opens the blocks around that line's box and scrolls to it. Where a block is used many times, it opens to the first one: | RoPE base=10000 opens Group, SlidingLayer and SlidingAttention, and lights the RoPE on the Q line.

Move the cursor elsewhere and the blocks that opened by themselves close again. The ones you opened stay open. Pointing at a line only greys its box; it never opens anything.

What it draws

The parts you know are drawn as papers draw them:

  • grouped-query, multi-query and sliding-window attention, with rotary positions noted ("RoPE 10k");
  • gated MLPs (SwiGLU, GeGLU) and mixtures of experts, with their router;
  • Mamba's mixer and other recurrent blocks;
  • norms, residual adds and the LM head, marked "tied" when it reuses the token table.

Anything else is a box with its block's name. Plumbing, such as a reshape or a rename, is never drawn.

What would you want a box to show when you open it?