I have a function that is roughly as follows
from flax import nnx
from jax import Array
from typing import List
def predict(models: List[nnx.Module], imgs: Array):
for i, agent in enumerate(agents):
prediction = models(imgs[i, ...])
I want to avoid looping over these models to get the predictions. Ideally I use jax.vmap or nnx.vmap to create a new function predict that does everything parallelized on the GPU. However, I (obviously) can't pass a list as argument.
My desired solution:
from jax import vmap
def predict_single(model, img):
return model(img)
predict = vmap(predict_single)
Error message
ValueError: vmap was requested to map its argument along axis 0, which implies that its rank should be at least 1, but is only 0 (its shape is ())
How should I solve this?