bugger.
All challenges/Pythonhardllm-latent-experts-v1
THE INVESTIGATION

Dispatch experts through a latent projection

Implement a latent mixture-of-experts block with a wide residual.

LLM ArchitectureFrontier variants

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.

down maps D features into L, router maps L into E scores, and experts contains E latent L×L matrices. For each token compute latent = x·down, select k experts by descending scores with ties by ID, then take their stable softmax-weighted mixture in latent space. Project via up (L×D) and add the original token. Return selected and output. Use simple linear experts in this exercise.

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

Implement a latent mixture-of-experts block with a wide residual.

Reproduction

01 Wide inputs are routed through one latent feature
{"x":[[1,2,5]],"down":[[1],[2],[0]],"router":[[2,-1,1]],"experts":[[[1]],[[3]],[[-1]]],"up":[[2,0,-1]],"k":1}
{"selected":[[0]],"output":[[11,2,0]]}
02 No tokens
{"x":[],"down":[[1],[2],[0]],"router":[[2,-1,1]],"experts":[[[1]],[[3]],[[-1]]],"up":[[2,0,-1]],"k":2}
{"selected":[],"output":[]}
03 Softmax of two latent experts
{"x":[[0,1,0]],"down":[[1],[2],[0]],"router":[[2,-1,1]],"experts":[[[1]],[[3]],[[-1]]],"up":[[2,0,-1]],"k":2}
{"selected":[[0,2]],"output":[[3.046377,1,-1.523188]]}

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.