Add transforms: grad, value_and_grad, vjp, jvp, vmap, compile, checkpoint#590
Merged
sydneyrenee merged 1 commit intomainfrom Mar 25, 2026
Merged
Add transforms: grad, value_and_grad, vjp, jvp, vmap, compile, checkpoint#590sydneyrenee merged 1 commit intomainfrom
sydneyrenee merged 1 commit intomainfrom
Conversation
…oint Function-wrapping transforms that cross the N-API boundary: JS functions are wrapped as C++ std::function via persistent references, passed to MLX transform APIs, and the resulting transformed functions are wrapped back as callable JS functions with GC-safe closure data. grad/value_and_grad: compute gradients of scalar-valued functions vjp/jvp: vector-Jacobian and Jacobian-vector products (immediate) vmap: vectorize a function over batch dimensions compile: JIT compile computation graphs checkpoint: recompute intermediates during backprop enable_compile/disable_compile: global compilation flags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements all MLX function transforms, crossing the N-API boundary with JS function wrapping.
Function transformers (return new callable functions):
Immediate transforms (compute and return results):
Global flags:
Architecture
JS functions are wrapped as C++
std::functionvia persistent Napi references, passed to MLX transform APIs (grad, compile, etc.), and the resulting transformed functions are wrapped back as callable JS functions. Closure data is stored with GC-safe cleanup via Napi::External attached to the function object.Issues addressed
Test plan