`torch.vmap` (or other form of parallelism) Support for `odeint_event`

Author: LucasGrassoCreated Jun 16, 2026Updated Aug 11, 2026

Ive been trying to parallelize batch solving of event odes using torch.vmap and ive got the following error.

Traceback (most recent call last):
  File "project/src/aitneuralode/test.py", line 56, in <module>
    test_forward()
  File "project/src/aitneuralode/test.py", line 19, in test_forward
    x_hat, T = build(d)(x)
               ^^^^^^^^^^^
  File "project/.venv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1778, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "project/.venv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1789, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "project/src/aitneuralode/ait_neural_ode.py", line 53, in forward
    return batch_solve(x)
           ^^^^^^^^^^^^^^
  File "project/.venv/lib/python3.11/site-packages/torch/_functorch/apis.py", line 220, in wrapped
    return vmap_impl(
           ^^^^^^^^^^
  File "project/.venv/lib/python3.11/site-packages/torch/_functorch/vmap.py", line 316, in vmap_impl
    return _flat_vmap(
           ^^^^^^^^^^^
  File "project/.venv/lib/python3.11/site-packages/torch/_functorch/vmap.py", line 507, in _flat_vmap
    batched_outputs = func(*batched_inputs, **kwargs)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "project/src/aitneuralode/ait_neural_ode.py", line 38, in solve_single
    t_star, traj = odeint_event(
                   ^^^^^^^^^^^^^
  File "project/.venv/lib/python3.11/site-packages/torchdiffeq/_impl/odeint.py", line 153, in odeint_event
    event_t, solution = odeint_interface(func, y0, t, event_fn=event_fn, **kwargs)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "project/.venv/lib/python3.11/site-packages/torchdiffeq/_impl/adjoint.py", line 206, in odeint_adjoint
    ans = OdeintAdjointMethod.apply(shapes, func, y0, t, rtol, atol, method, options, event_fn, adjoint_rtol, adjoint_atol,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "project/.venv/lib/python3.11/site-packages/torch/autograd/function.py", line 599, in apply
    raise RuntimeError(
RuntimeError: In order to use an autograd.Function with functorch transforms (vmap, grad, jvp, jacrev, ...), it must override the setup_context staticmethod. For more details, please see https://pytorch.org/docs/main/notes/extending.func.html

I think that it would be quite useful, and it would overcome the difficulties of minibatching described in the "Learning Neural Event Functions for Ordinary Differential Equations" (https://arxiv.org/abs/2011.03902) paper. What would need to be done to be able to vmap over odeint_event?