Comments (3)
We've also found the below module useful. Anyway, won't be offended at all if you guys don't like these; your reactions help us understand the design motivations better and we can always just keep them out of tree.
class Ensemble(nn.Module):
def apply(self, x, modules, args):
return [module(x, **arg) for (module, arg) in zip(modules, args)]
from flax.
So, I've written a ton of combinator / concatenative style NN code both in the original "stax" NN prototype as well as "trax" which also uses combinators for everything. Certainly combinator code ends up being the most concise way to construct NNs, and for straight-through models w. layers taking a single input and single output it's an elegant approach.
The real problem happens w. more complicated dataflow where you start needing to use Parallel
combinators (what you call Ensemble
there I think) and then start having to worry about nested tuple packing and unpacking or you switch to a stack-based inter-layer convention like traditional point-free "concatenative" languages. The problem with these conventions is that they lead to a "write-only" language - it's easy to make concise code, but the code isn't self-documenting any longer, all the dataflow is hidden from view and requires readers to bounce all over the layer libraries to reason-out what the heck is going on. That's why in flax we avoid such constructs for the most part, we prefer the slightly more explicit argument passing so that it's always clear what data's being passed in a single local read-through.
That said we're not ideological about such things and encourage our users to set up combinators if that's how they want to rig their code. I'm just not sure we want to encourage it by having combinators in-tree based on a lot of personal experience trying to maintain such code.
from flax.
Thank you for the thorough explanation! Makes sense to me. Closing!
from flax.
Related Issues (20)
- Bug in guide "Scale up Flax Modules on multiple devices" flax.errors.InvalidRngError: RNGs should be of shape (2,) HOT 3
- NNX Conv documentation states that kernel size can be an integer for 1D convs. HOT 1
- Bug in Tutorial: Jax 101 Working with PyTrees "AttributeError: module 'jax.tree_util' has no attribute 'register_static'" HOT 5
- flax is significantly slower than pytorch HOT 1
- NNX attention layer missing `qkv_features` arg HOT 2
- Metadata in `nnx.param_field` is not passed to the Param class
- Swapping selected layers with a different layer. HOT 1
- Quick start badges point to 404 HOT 1
- A guide on distributed training
- Proposal: StackedRNNCell HOT 3
- Is it an API like model.summary in Pytorch? HOT 1
- Documentation issue: batch_stats in batchnorm need to be marked as mutable even in test/inference HOT 1
- How to implement the same functionality as hk.BatchApply in flax HOT 6
- [Feature request]Unify the order of input arguments and returns โโof RNN HOT 2
- Precision error using checkpoint with CUDA
- [struct.dataclass] Consider adding optional `kw_only` arguments HOT 4
- Instance Normalization HOT 1
- Cannot assign arrays to dataclass fields in `nnx` HOT 2
- Flax not found for ppc64 power9 HOT 3
- Cannot use static_argnums with flax.linen.checkpoint on a Module whose __call__ has a boolean control flag HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flax.