Every previous question in this curriculum's [04-seq-modeling] and [05-transformers-llm] sections built exactly ONE piece of a language model in isolation: [04-seq-modeling/02-embeddings/01-token-embedding-lookup] turns ids into vectors, [04-seq-modeling/02-embeddings/03-sinusoidal-positional-encoding] injects position, [01-transformer-block/07-stack-blocks] refines those vectors through many Transformer blocks, and [02-weight-tying]'s compute_output_logits turns the result into vocabulary scores. This question's entire content is WIRING, connecting five already-independently-verified pieces into one genuine, working, end-to-end forward pass, from raw integer token ids all the way to next-token logits, with no new mathematics introduced anywhere.
Implement full_lm_forward(token_ids, token_embedding_table, blocks_params, num_heads, tied, output_weight, mask), chaining: token embedding lookup, adding sinusoidal positional encoding, running the result through [07-stack-blocks]'s stack of Transformer blocks, and finally [02-weight-tying]'s output projection.
token_ids includes a leading batch dimension, (batch, seq_len): every downstream piece (attention's head-splitting, specifically) requires one.token_ids's sequence length and ADDED to the token embeddings ([05-combine-token-positional-embeddings]'s pattern), before any Transformer block runs.blocks_params and num_heads pass straight through to [07-stack-blocks]'s stack_transformer_blocks, unchanged.tied/output_weight pass straight through to [02-weight-tying]'s compute_output_logits, unchanged.token_embeddings = embedding_forward(token_ids, token_embedding_table)
positional_embeddings = sinusoidal_positional_encoding(seq_len, d_model)
x = combine_embeddings(token_embeddings, positional_embeddings)
seq_len = token_ids.shape[-1], d_model = token_embedding_table.shape[-1].
x = stack_transformer_blocks(x, num_heads, blocks_params, mask=mask)
return compute_output_logits(x, token_embedding_table, tied, output_weight)
Two more function calls, each already fully built and independently tested; this question adds no new computation of its own beyond correctly chaining them in order.
Click "Run Tests" to test your implementation