bugger.
All challenges/Pythonmediumllm-rotary-embeddings-v1
THE INVESTIGATION

Rotary position embeddings (RoPE)

Rotate each adjacent feature pair using its own frequency and absolute token position.

LLM ArchitectureTransformer components

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 rows are token vectors of even dimension d, positions gives nonnegative position IDs, base is positive and output shape matches rows. For pair i, rotate (x,y) by angle position × base^(−2i/d) using (x*cos − y*sin, x*sin + y*cos). Preserve order and support empty rows input.

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

Rotate each adjacent feature pair using its own frequency and absolute token position.

Reproduction

01 Distinct pair frequencies at one position
{"rows":[[1,0,1,0]],"positions":[3],"base":100}
[[-0.989992,0.14112,0.955336,0.29552]]
02 Position zero leaves the row alone
{"rows":[[1,2,3,4]],"positions":[0],"base":10000}
[[1,2,3,4]]
03 Different absolute positions
{"rows":[[1,0],[1,0]],"positions":[2,4],"base":10000}
[[-0.416147,0.909297],[-0.653644,-0.756802]]

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.