Build a tiny GPT-style language model
Wire a tiny causal language model from token IDs through next-token logits.
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
{"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]]
{"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]]
{"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.
Read the report, then sign in to start your investigation.