Shard linear layers across tensor-parallel ranks
Reconstruct a bias-added linear layer from tensor-parallel shards.
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.
Input x is a nonempty batch, bias is an output vector, shards are nonempty matrices ordered by rank, and mode is column or row. Column: every shard has all input features and some consecutive output columns; concatenate per-rank outputs. Row: each shard owns consecutive input features and all output columns; multiply against its segment of x and sum per-rank outputs. Add bias once after gathering/reducing. Return partials by rank and output.
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
Reconstruct a bias-added linear layer from tensor-parallel shards.
Reproduction
{"mode":"row","x":[[2,3]],"shards":[[[1,2]],[[3,4]]],"bias":[0.1,-0.1]}{"partials":[[[2,4]],[[9,12]]],"output":[[11.1,15.9]]}{"mode":"row","x":[[0,0]],"shards":[[[1]],[[2]]],"bias":[1]}{"partials":[[[0]],[[0]]],"output":[[1]]}{"mode":"column","x":[[1,2]],"shards":[[[1],[2]],[[2,0],[4,1]]],"bias":[0.1,0.2,0.3]}{"partials":[[[5]],[[10,2]]],"output":[[5.1,10.2,2.3]]}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.