Purifying pattern #14661
Replies: 3 comments 9 replies
-
@EelcoHoogendoorn (Not a core JAX developer, but interested reader) State is not incompatible with functional programming, when done properly. Have you looked at JAX's new state module or Oryx? To be honest with you, I'm not sure why the author of I'd like to understand why the state model in this library isn't similar to Oryx's model of state - or if that model is incompatible with certain design decisions. |
Beta Was this translation helpful? Give feedback.
-
The JAX state module seems an internal component, not an end user api? I was not aware of Oryx, no. Indeed it seems to also implement a form of what id call a 'purify pattern' (like flax and haiku and ninjax); lending further support to the notion that this is a wheel thatd be nice to invent once, rather than having it tied to some kind of special-purpose library. The ninjax implementation makes quite some sense to me; but like this oryx variant, it is not exactly up to the testing and documentation standards that id expect of a first-class construct of a language. |
Beta Was this translation helpful? Give feedback.
-
How does this compare to things like Equinox? |
Beta Was this translation helpful? Give feedback.
-
I was hoping to discuss what id call the 'purify pattern'. Versions of this are implemented in haiku's transform method, and also in flax.linen. The recently released ninjax provides an especially simple and general implementation of this pattern.
Ninjax can be used to write almost arbitrarily statefull and very 'torch like' code. It has some small examples but I think its more descriptive and motivating example is the dreamerv3 code.
Personally, I quite like the conceptual idea, and the elegance of the resulting code. (well most parts of it anyway)
I figured there must be some grumpy old purist functional programmers here that can put up a good rant as to why anyone would think theyd put in the time to make such a great functional programming language only for vandals to write state-like frameworks around it.
Or is that not the case, and is the purify pattern something that should actually be regarded as having a proper place in a functional language? If we called it a 'monad', would that make people feel better about it?
Jokes aside, I am curious to see some core jax developers opinions on something like the purify pattern. One thing that worries my is composability; if you look at the ninjax source it has to overload core operations like scan and grad to work properly; and with the limited unit testing in ninjax and limited experience I have using it, I am not quite confident that composing these would not come back to haunt me.
But if the purify pattern is actually a quite general pattern that is considered to be 'legit' by real functional programmers, I wonder if there isnt a case to be made to have it supported as a first class primitive to the JAX library itself?
Beta Was this translation helpful? Give feedback.
All reactions