{
  "version": 1,
  "language": "en",
  "title": "Prefill gives logits for the first output token",
  "description": "The timeline shows queueing, prompt prefill, first-token sampling, decode iterations and completion. Prefill supplies first-token logits, and streaming can overlap subsequent decode.",
  "caption": "Prefill’s last prompt position supplies the first sampled token. Decode then uses generated inputs, and output can stream during subsequent steps. The phase widths are schematic. The author made this explanatory diagram. The playback is an example. Animation time is not measured runtime.",
  "alt": "Request timeline: queueing occurs before prefill, which makes prompt K/V and first-token logits. Decode extends the sequence while sampled tokens stream.",
  "sources": [
    {
      "path": "content/blog/2026-06-08_llm-inference-full-stack-systems/post.md",
      "sha256": "09bb02fb1815396601a7302f5924ed7b6b047a559ec5350a812ea9153627a653",
      "description": "Current article explanation, equations, assumptions and retained citations."
    },
    {
      "path": "research/dynamic-mechanisms-2026-10-21/before/content/blog/2026-06-08_llm-inference-full-stack-systems/illustrations/02-latency-ledger-algorithm.svg",
      "sha256": "a18d447850fad8c5c36d8ddb5e3603e8a0a73b9fe3af45ea95ea4a2dec851a72",
      "description": "Frozen prior illustration; exact pre-migration bytes retained."
    },
    {
      "path": "content/blog/2026-06-08_llm-inference-full-stack-systems/illustrations/source-notes.json",
      "description": "Existing article illustration provenance, retained unchanged."
    }
  ],
  "limitations": [
    "The playback is an example. Playback duration is not measured runtime."
  ],
  "targets": {
    "work0": {
      "id": "mechanism-work0",
      "kind": "node",
      "label": "wait"
    },
    "out0": {
      "id": "mechanism-out0",
      "kind": "node",
      "label": "none"
    },
    "kv0": {
      "id": "mechanism-kv0",
      "kind": "node",
      "label": "metadata"
    },
    "work1": {
      "id": "mechanism-work1",
      "kind": "node",
      "label": "prefill"
    },
    "out1": {
      "id": "mechanism-out1",
      "kind": "node",
      "label": "first token"
    },
    "kv1": {
      "id": "mechanism-kv1",
      "kind": "node",
      "label": "make K/V"
    },
    "work2": {
      "id": "mechanism-work2",
      "kind": "node",
      "label": "next input"
    },
    "out2": {
      "id": "mechanism-out2",
      "kind": "node",
      "label": "next token"
    },
    "kv2": {
      "id": "mechanism-kv2",
      "kind": "node",
      "label": "read + write"
    },
    "work3": {
      "id": "mechanism-work3",
      "kind": "node",
      "label": "next input"
    },
    "out3": {
      "id": "mechanism-out3",
      "kind": "node",
      "label": "next token"
    },
    "kv3": {
      "id": "mechanism-kv3",
      "kind": "node",
      "label": "read + write"
    },
    "work4": {
      "id": "mechanism-work4",
      "kind": "node",
      "label": "next input"
    },
    "out4": {
      "id": "mechanism-out4",
      "kind": "node",
      "label": "next token"
    },
    "kv4": {
      "id": "mechanism-kv4",
      "kind": "node",
      "label": "read + write"
    },
    "work5": {
      "id": "mechanism-work5",
      "kind": "node",
      "label": "done"
    },
    "out5": {
      "id": "mechanism-out5",
      "kind": "node",
      "label": "last event"
    },
    "kv5": {
      "id": "mechanism-kv5",
      "kind": "node",
      "label": "Release request references"
    }
  },
  "stateLabels": {
    "stage": "Stage",
    "artifact": "Artifact"
  },
  "scenarios": [
    {
      "id": "one-request",
      "title": "Sample first from prefill logits",
      "description": "Sampling uses prefill logits for the first token.",
      "initial": {
        "stage": "Prepared",
        "artifact": "Kept inputs"
      },
      "unselected": [],
      "steps": [
        {
          "title": "Wait in queue",
          "description": "The request waits in the queue.",
          "duration": 3000,
          "active": [
            "work0",
            "out0",
            "kv0"
          ],
          "paths": [],
          "state": {
            "stage": "Wait in queue",
            "artifact": "The request is in the queue."
          }
        },
        {
          "title": "Process the prompt",
          "description": "The model processes the prompt.",
          "duration": 3000,
          "active": [
            "work1",
            "kv1"
          ],
          "paths": [],
          "state": {
            "stage": "Process the prompt",
            "artifact": "Prompt K/V and last-position logits"
          }
        },
        {
          "title": "Sample the first token",
          "description": "The sampler samples the first token from prefill logits.",
          "duration": 3000,
          "active": [
            "out1"
          ],
          "paths": [],
          "state": {
            "stage": "Sample the first token",
            "artifact": "Token 1 can stream before a decode pass."
          }
        },
        {
          "title": "Decode iteration 1",
          "description": "The model processes generated input in decode iteration 1.",
          "duration": 3000,
          "active": [
            "work2",
            "out2",
            "kv2"
          ],
          "paths": [],
          "state": {
            "stage": "Decode iteration 1",
            "artifact": "Generated input gives token 2, and K/V stays in memory."
          }
        },
        {
          "title": "Decode iteration 2",
          "description": "The model processes generated input in decode iteration 2.",
          "duration": 3000,
          "active": [
            "work3",
            "out3",
            "kv3"
          ],
          "paths": [],
          "state": {
            "stage": "Decode iteration 2",
            "artifact": "Generated input gives token 3, and K/V stays in memory."
          }
        },
        {
          "title": "Decode iteration 3",
          "description": "The model processes generated input in decode iteration 3.",
          "duration": 3000,
          "active": [
            "work4",
            "out4",
            "kv4"
          ],
          "paths": [],
          "state": {
            "stage": "Decode iteration 3",
            "artifact": "Generated input gives token 4, and K/V stays in memory."
          }
        },
        {
          "title": "Complete and release request references",
          "description": "The engine releases the completed request’s references.",
          "duration": 3000,
          "active": [
            "work5",
            "out5",
            "kv5"
          ],
          "paths": [],
          "state": {
            "stage": "Complete and release request references",
            "artifact": "The engine completes the request. Reusable/shared blocks may stay."
          }
        }
      ]
    }
  ]
}
