dymad.utils.wrapper

Functions

jax_to_torch(a, device, dtype)

torch_to_jax(t)

Classes

JaxMultiInFn(*args, **kwargs)

JaxWrapper(f_jax[, jit])

class dymad.utils.wrapper.JaxMultiInFn(*args, **kwargs)

Bases: Function

static backward(ctx, *grad_y_torch)

Receives one grad tensor per forward output (or one if single output). Returns one grad tensor per forward input (same order as inputs).

static forward(ctx, f_jax, jit_flag, *x_torch)

Accepts N torch tensors, all requiring grad. Returns either a single tensor or a tuple of tensors (matching f_jax).

class dymad.utils.wrapper.JaxWrapper(f_jax, jit=True)

Bases: Module

forward(*xs)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

dymad.utils.wrapper.jax_to_torch(a, device, dtype)
Return type:

Tensor

dymad.utils.wrapper.torch_to_jax(t)
Return type:

Array | None