Comments (1)
Sorry, it took me a bit to figure out what was going on.
A Model should be pmap'able - what's happening here is a bit of a subtle bug:
First, a short-term "fix" is just wrapping it in a lambda passthrough:
import jax
from flax import nn
layer=nn.Dense.partial(features=1)
key=jax.random.PRNGKey(0)
x=jax.random.normal(key, (4, 20, 2))
_,params=layer.init(key, x[0,...])
layer_m=nn.Model(layer, params)
jax.pmap(lambda z: layer_m(z))(x)
Now, what's going on:
- in a great change google/jax#2073 made ~2 months ago to improve XLA call stack metadata JAX tries to get the
__name__
attribute from the pmap'd function, which in this case is our callable Model instance. - the problem is that in another refactoring of the base flax code a month ago baf43e7 we override
__getattr__
on Model to passthrough and grab the requested attr from Module, but inside that we are trying to evalissubclass(fetched_attr, flax.nn.Module)
andissubclass(<string object>, flax.nn.Module)
throws an error in python since it's nonsense.
We almost always use a Model inside an optimizer or indirectly in another function, and I think we must not have a unit test of a direct jit/pmap on a Model - my apologies for letting this slip through, we'll try to get a fix in asap.
from flax.
Related Issues (20)
- How to optimize multi modelโs parameter in one optimizer ? HOT 1
- Bad interaction between nnx.Rngs and custom derivatives HOT 6
- Feature request: optionally sow attention weight in `dot_product_attention`
- 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
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.