It is a very bad idea to handle the KV cache in Jax naively like that. Jax requires static shapes. You're creating dynamic shapes there, causing a ton of recompilation.
I was curious what else made it not fit for production. Anything fundamental or just minor issues like this?
Would that suggest to you what you did wrong? Or purely show you what you got right? How chatty is this variable?
Also in any case to get optimized code you need flash attention and many other tricks.