Standard language models are trained with a next-token prediction objective: given a context, predict the very next token. Multi-Token Prediction (MTP) augments this by adding auxiliary prediction heads that predict tokens further into the future (depth ). The additional supervision signal has been shown to improve sample efficiency and downstream quality.
In this problem you will implement the depth-1 MTP training loss: a weighted sum of the standard next-token cross-entropy loss (from the main head) and an auxiliary cross-entropy loss from an MTP head that predicts two tokens ahead.
Given:
main_logits: array of shape (N, V) — logits from the main LM head over positions.main_targets: array of shape (N,) — integer token ids, the next-token targets for the main head.mtp_logits: array of shape (N-1, V) — logits from the depth-1 MTP head (one fewer position because we need a token two steps into the future).mtp_targets: array of shape (N-1,) — integer token ids two steps ahead.mtp_weight: float — weight applied to the MTP loss term.Compute:
where each term is the mean cross-entropy over its positions, using natural log and numerically stable softmax. Return the total loss as a Python float rounded to 6 decimals.
mtp_loss(main_logits, main_targets, mtp_logits, mtp_targets, mtp_weight)