I’m excited to announce the alpha release of Raven, a modern scientific computing ecosystem for OCaml.
What is Raven?
Raven is a collection of libraries and tools for numerical computing and machine learning, including:
- Nx: Multi-dimensional arrays with NumPy-like operations and pluggable backends (now pure OCaml, C FFI, Metal, next CUDA, WebGPU, etc.) - our equivalent of NumPy
- Rune: Automatic differentiation and device placement, building toward JIT compilation - our equivalent of Jax
- Kaun: Deep learning framework inspired by Flax/PyTorch, built on Rune
- Sowilo: Computer vision library with differentiable operations, build on Rune
- Hugin: Plotting library for data visualization - our equivalent of matplotlib
- Quill: Markdown-first interactive notebooks - very different from Jupyter, but our answer to interactive notebooks
The ecosystem is designed to work together seamlessly, with Nx as the foundation, Rune providing differentiable computation, and domain-specific libraries building on top.
Getting Started
Install Raven via opam:
opam install raven
Here’s a quick example showcasing automatic differentiation with Rune:
open Rune
(* Define a simple neural network layer *)
let layer ~w ~b x = add (matmul x w) b
(* Compute mean squared error loss *)
let mse_loss ~w ~b x y =
let pred = layer ~w ~b x in
let diff = sub pred y in
mean (mul diff diff)
let result =
(* Choose device - Rune.ocaml, Rune.c, Rune.metal *)
let dev = Rune.c in
(* Initialize parameters on the device *)
let w = randn dev float32 [| 3; 2 |] in
let b = zeros dev float32 [| 2 |] in
let x = randn dev float32 [| 10; 3 |] in
let y = randn dev float32 [| 10; 2 |] in
(* Compute loss and gradients *)
let loss, grad_w = value_and_grad (fun w -> mse_loss ~w ~b x y) w in
Printf.printf "Loss: %g\n" (unsafe_get [] loss);
grad_w
val result : (float, Rune.float32_elt, [ `c ]) Rune.t =
[[-1.74967, 0.863766],
[-0.140407, -0.269364],
[0.593187, 0.0197736]]
Loss: 2.13033
For more examples and detailed documentation, visit raven-ml.dev.
Why Raven?
Today’s machine learning ecosystem is converging on frameworks built atop ML compilers: high-level Python APIs that build computation graphs, then JIT compile them for performance.
In parallel, JAX and Flax have gained popularity with their functional APIs. For instance, JAX uses
function transformations (grad, jit, vmap) to implements its core features.
This is a landscape where OCaml has natural advantages. OCaml excels at building compilers, which includes ML compilers, and as a functional language, it’s a more natural fit for functional ML APIs than Python with JAX.
Given these technical advantages, Python’s dominance comes down to developer experience: the massive ecosystem and excellent prototyping ergonomics. We believe that with the right tooling, OCaml can match Python’s productivity for prototyping and exploratory work. And the ecosystem gap doesn’t have any fundamental challenge: we “just” need to write a lot of code.
If Raven succeeds, we believe it will offer a much more compelling alternative to Python: a language that enables rapid prototyping while eliminating the gap between exploration and production. You’ll move from local development to production without switching languages, without separate teams, without maintaining two stacks.
Technical Highlights: Rune’s autodiff engine
One interesting aspect of Raven is Rune’s implementation of automatic differentiation using OCaml’s effects system. As far as we know, this is the first production-scale autodiff engine built on effects, drawing on research by Jesse Sigal and earlier work by KC Sivaramakrishnan.
The architecture follows a modular design:
- Pluggable backends in Nx allow implementation for different hardware
- Rune implements an Nx backend that raises effects for all operations.
- These effects are either caught by an effect handler (e.g. grad, jit), or, if unhandled, executed eagerly
- This allows for composable effects handlers (e.g. grad (grad f), jit (grad f), etc.)
Technical Highlights: Quill Notebooks
Quill reimagines interactive notebooks with a Typora-like experience. Markdown renders live as you write, switching to raw markdown when you focus on a section for editing. This creates a natural writing experience where code blocks integrate naturally into your document.
The result is a distraction-free notebook environmnet, that prioritizes focused writing, while still providing full editor features within code blocks (coming soon ™!).
While still early, we’re excited to see how the community reacts to Quill when it is stable enough for daily use - we really think it has the potential to offer a much better notebook experience for teaching, reading, and other workflows.
Current Status
This is an alpha release. APIs are stabilizing but may still change. Things will break - this is expected at this stage! If you encounter bugs, please open an issue on GitHub; community feedback is invaluable to get to a stable release.
We’re currently focused on:
- Stabilizing core APIs for the 1.0 release
- Writing documentation and user guides
- Supporting early users adoption (FFT, linear algebra, CUDA backend)
Post-Alpha priorities include JIT compilation and stable Quill environment.
Building a Community
One bet we’re taking with Raven is that it will allow a scientific and ML community in OCaml to flourish. As of now, it’s still largely a one-person project. While I’m committed to its development, we really need to see the development of a larger community for a project of this size
to survive.
If you’re interested in the project, the best thing you can do is to engage—whether by opening issues, reaching out, or contributing. Alongside reaching a first stable release, building a community is Raven’s main priority from now on, so any kind of contribution or engagement will be deeply appreciated. If there’s anything I can do to make Raven more welcoming and approachable, let
me know.
I’ve always believed that the best way to grow OCaml adoption is to provide killer apps for specific use cases (just like Rails did for Ruby). Raven’s not quite there yet in terms of advantages over Python, but it can get there, and if that’s something you’d like to contribute to, please reach out!
Getting Involved
Here are immediate ways to contribute as we work toward a stable release:
For users:
- Try the libraries with your workflows and report issues
- Share feedback on API design and usability
- Help test on different platforms and configurations
For contributors:
- Optimize eager execution backends while we build JIT compilation
- Add missing NumPy/Jax/Flax operations to Nx/Rune/Kaun
- Contribute examples and documentation
Don’t hesitate to reach out if you’d like to be involved closely with the core development:
- JIT compilation
- Stabilize Quill (many bugs to fix!)
- New libraries
Resources:
- GitHub: GitHub - raven-ml/raven: Modern scientific computing for OCaml
- Documentation: Documentation - raven
- Contact: thibaut.mattio@gmail.com
Acknowledgments
I’d like to thank our early contributors and testers who have helped shape Raven:
- @axrwl
- @gabyfle
- @hesterjeng
- @ghennequin
- @kayceesrk
- @blueavee
Special thanks to our GitHub sponsors for their support:
Your feedback, contributions and support have been invaluable in getting Raven to this alpha release - thank you!
Supporting Raven’s Development
As Raven grows, I’m looking for sustainable ways to continue dedicating time to the project. If you’re an industrial user interested in using Raven for your machine learning or scientific computing needs, I’d love to talk about how we can work together.
For individuals who want to support the project, I have a GitHub Sponsors page. Any contribution, no matter the size, is deeply appreciated and helps ensure Raven’s continued development.