Dev.to
7/22/2026

Accidentally quadratic: buffer copies made MCTS in DeepMind's mctx 3 slower
Short summary
Author discovers accidentally quadratic behavior in DeepMind's mctx library during AlphaZero-style training: MCTS tree backward pass copies entire [B,N+1,A] buffers on every loop iteration because XLA:GPU can't prove scatter-alias safety. At 64 simulations, pure tree machinery costs 125ms vs expected ~50ms. Fix involves rewriting the backward function to avoid defensive copies, yielding bitwise-identical search results with linear scaling.
- •O(N²) bottleneck traced to XLA defensive buffer copies in mcts backward pass
- •XLA:GPU materializes full tree buffers each while_loop iteration due to scatter-alias uncertainty
- •Fix rewrites ~80-line function (PR #116) for linear scaling with identical search results
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



