Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion python/mlx/nn/layers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ def apply_to_modules(self, apply_fn: Callable[[str, Module], Any]) -> Module:
instance).

Args:
apply_fn (Callable): The function to apply to the modules.
apply_fn (Callable): The function to apply to the modules which
takes two parameters. The first parameter is the string path of
the module (e.g. ``"model.layers.0.linear"``). The second
parameter is the module object.

Returns:
The module instance after updating submodules.
Expand Down
28 changes: 24 additions & 4 deletions python/src/transforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,8 +1238,18 @@ void init_transforms(nb::module_& m) {
same in number, shape, and type as the inputs of ``fun`` (i.e. the ``primals``).

Returns:
list(array): A list of the Jacobian-vector products which
is the same in number, shape, and type of the inputs to ``fun``.
tuple(list(array), list(array)): A tuple with the outputs of
``fun`` in the first position and the Jacobian-vector products
in the second position.

Example:

.. code-block:: python

import mlx.core as mx

outs, jvps = mx.jvp(mx.sin, (mx.array(1.0),), (mx.array(1.0),))

)pbdoc");
m.def(
"vjp",
Expand Down Expand Up @@ -1277,8 +1287,18 @@ void init_transforms(nb::module_& m) {
same in number, shape, and type as the outputs of ``fun``.

Returns:
list(array): A list of the vector-Jacobian products which
is the same in number, shape, and type of the outputs of ``fun``.
tuple(list(array), list(array)): A tuple with the outputs of
``fun`` in the first position and the vector-Jacobian products
in the second position.

Example:

.. code-block:: python

import mlx.core as mx

outs, vjps = mx.vjp(mx.sin, (mx.array(1.0),), (mx.array(1.0),))

)pbdoc");
m.def(
"value_and_grad",
Expand Down
Loading