bugger.
All challenges/Pythonhardllm-tiny-decoder-v1
THE INVESTIGATION

Build a tiny GPT-style language model

Wire a tiny causal language model from token IDs through next-token logits.

LLM ArchitectureArchitecture builds

What’s going wrong

Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.

Gather token_embedding rows and add position_embedding rows at indices offset + position. For each block in blocks, apply the supplied pre-norm block helper with RMSNorm, causal projected attention, SwiGLU and residual updates. Finally apply RMSNorm with norm_out and multiply by lm_head (D×V). Return a logits row per token. Tokens and positions are in range and the context is nonempty. The fixture uses learned absolute positions and single-head, bias-free blocks.

Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.

Expected behavior

Wire a tiny causal language model from token IDs through next-token logits.

Reproduction

01 Offset and two noncommuting blocks
{"tokens":[1,0],"offset":1,"position_embedding":[[0,0],[3,0],[0,1]],"blocks":[{"attention":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[1,0],[0,1]]},"norm_attention":[1,1],"norm_ffn":[1,1],"ffn":{"gate":[[1,0],[0,1]],"up":[[1,0],[0,1]],"down":[[1,0],[0,1]]}},{"attention":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[0,0],[0,0]]},"norm_attention":[1,1],"norm_ffn":[1,1],"ffn":{"gate":[[1,0],[0,1]],"up":[[1,0],[0,1]],"down":[[1,0],[0,1]]}}],"token_embedding":[[1,2],[2,-1],[-1,1]],"norm_out":[1,1],"lm_head":[[1,0,-1],[0,2,1]],"epsilon":0.001}
[[1.402604,-0.36144,-1.583323],[0.398621,2.713684,0.958221]]
02 Zero position and no blocks
{"tokens":[0],"offset":0,"position_embedding":[[0,0]],"blocks":[],"token_embedding":[[1,2],[2,-1],[-1,1]],"norm_out":[1,1],"lm_head":[[1,0,-1],[0,2,1]],"epsilon":0.001}
[[0.632329,2.529316,0.632329]]
03 Single input token with a block
{"tokens":[2],"offset":0,"position_embedding":[[1,0]],"blocks":[{"attention":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[1,0],[0,1]]},"norm_attention":[1,1],"norm_ffn":[1,1],"ffn":{"gate":[[1,0],[0,1]],"up":[[1,0],[0,1]],"down":[[1,0],[0,1]]}}],"token_embedding":[[1,2],[2,-1],[-1,1]],"norm_out":[1,1],"lm_head":[[1,0,-1],[0,2,1]],"epsilon":0.001}
[[0,2.828252,1.414126]]

Before you begin

  • Python functions, lists and dictionaries

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.