[ANN] OCANNL 0.3.1: a from-scratch deep learning (i.e. dense tensor optimization) framework

Hi! I’m happy to announce release 0.3.1 of OCANNL, a tensor optimization framework with:

  • concise notation via PPXs,
  • powerful shape inference,
  • backpropagation (first-order automatic differentiation),
  • low-level backends – currently only one, CPU via gccjit, but Cuda is on the horizon.

OCANNL is sponsored by Ahrefs. (Ahrefs website.)

ahrefs/ocannl: OCANNL: OCaml Compiles Algorithms for Neural Networks Learning (github.com)

I am not submitting it to Opam yet as OCANNL is insufficiently documented at the moment. I welcome your feedback if you decide to take a look!


I was unable to install via opam pin on an ARM macbook. I got cudajit as missing dependency. Then I pinned lukstafi/ocaml-cudajit as mentioned on the ocannl README. But installing that fails as I don’t have nvidia hardware.

Ah, I verified that the project works without cudajit, but somehow the dependency snuck back in. I’ll fix it tomorrow with version 0.3.2.

OCANNL 0.3.2 is out now. Thanks!

still no luck installing…

there appear to be two issues: a warning about gcc although it was already installed by homebrew, and some remaining dependency on cudajit. i append a terminal session transcript which might help.

b086-mac003:github USER$ opam pin list
arrayjit.0.3.2    (uninstalled)  git  git+file:///Users/USER/Tresors/Code/github/ocannl#master
ocannl.0.3.2      (uninstalled)  git  git+file:///Users/USER/Tresors/Code/github/ocannl#master
ocannl_npy.0.3.2                 git  git+file:///Users/USER/Tresors/Code/github/ocannl#master
b086-mac003:github USER$ opam install ocannl

<><> Synchronising pinned packages ><><><><><><><><><><><><><><><><><><><><>  🐫
[ocannl.0.3.2] synchronised (no changes)

[WARNING] Opam package conf-libgccjit.1 depends on the following system package that can no longer be
          found: gcc@13
Constructing initial basis...
Number of 0-1 knapsack inequalities = 3554
Constructing conflict graph...
Conflict graph has 1172 + 684 = 1856 vertices
The following actions will be performed:
  ↻ recompile conf-libgccjit 1      [upstream or system changes]
  ↻ recompile gccjit         0.3.2  [uses conf-libgccjit]
  ∗ install   arrayjit       0.3.2* [required by ocannl]
  ∗ install   ocannl         0.3.2*
===== ∗ 2   ↻ 2 =====
Do you want to continue? [Y/n] y

The following system packages will first need to be installed:

<><> Handling external dependencies <><><><><><><><><><><><><><><><><><><><>  🐫
Let opam run your package manager to install the required system packages?
(answer 'n' for other options) [Y/n] y
+ /opt/homebrew/bin/brew "install" "gcc@13"
- Warning: gcc 13.2.0 is already installed and up-to-date.
- To reinstall 13.2.0, run:
-   brew reinstall gcc

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
⬇ retrieved gccjit.0.3.2  (cached)
⊘ removed   gccjit.0.3.2
⊘ removed   conf-libgccjit.1
∗ installed conf-libgccjit.1
∗ installed gccjit.0.3.2
[ERROR] The compilation of arrayjit.0.3.2 failed at "dune build -p arrayjit -j 8 @install".

#=== ERROR while compiling arrayjit.0.3.2 =====================================#
# context     2.1.5 | macos/arm64 | ocaml-variants.5.1.1+options | pinned(git+file:///Users/USER/Tresors/Code/github/ocannl#master#5ace0ea965e26b3d58fdcd401674bf99bca23520)
# path        ~/.opam/51/.opam-switch/build/arrayjit.0.3.2
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p arrayjit -j 8 @install
# exit-code   1
# env-file    ~/.opam/log/arrayjit-97185-bea3b6.env
# output-file ~/.opam/log/arrayjit-97185-bea3b6.out
### output ###
# Error: The implementation arrayjit/lib/cuda_backend.pp.ml
# [...]
#           ?name:string ->
#           context ->
#           Arrayjit.Indexing.unit_bindings ->
#           Arrayjit.Low_level.traced_store * Arrayjit.Low_level.t ->
#           context * Arrayjit.Indexing.jitted_bindings *
#           (unit -> Arrayjit.Tnode.work)
#         Type unit -> unit is not compatible with type Arrayjit.Tnode.work
#         File "arrayjit/lib/cuda_backend.mli", lines 11-16, characters 0-59:
#           Expected declaration
#         File "arrayjit/lib/cuda_backend.missing.ml", line 10, characters 4-7:
#           Actual declaration

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
┌─ The following actions failed
│ λ build arrayjit 0.3.2
┌─ The following changes have been performed (the rest was aborted)
│ ↻ recompile conf-libgccjit 1
│ ↻ recompile gccjit         0.3.2

Yes I just saw the failures from the CI runs. I’m sorry. Hang on, I’ll try to get OCANNL 0.3.2 into opam.

Ah that’s a different problem, and really my bad, code rot on the Cuda backend mock file…

Third time the charm. OCANNL 0.3.3 is out now. I might need to change the name of the project, because of the lint warnings: Possible name collision with packages ‘OCADml’, ‘ocal’, ‘ocaml’?

thanks! i was able to install now (warnings about gcc@13 being already present are still there)

personally, i find the linter warnings overly cautious, especially if names are case sensitive. but maybe there are other nice names? tenno? tensO? ODL? OCDL? :wink:

I’d go with neural_nets_lib. OCANNL is both “Ocaml Compiles Algorithms for Neural Nets Learning” and “OCAml Neural Nets Library”.

Apologies for the overly excited linter warnings, this is still a work in progress! Your feedback is very helpful, and after some changes the linter passes for OCANNL:)


But I changed the package name already! The warnings were kinda helpful. Edit: ah, using all-capitals OCANNL as package names would make sense. But I went with project ocannl consisting of packages arrayjit and neural_nets_lib.

quick initial feedback: i was able to opam pin version and install it on macos M1. homebrew claimed gcc was already installed. then trying out dune test this failed with linker errors, apparently ld not finding a library emutls_w. after some googling i followed a suggestion to manually brew reinstall gcc. after this last step i could successfully dune test !

I’m not much able to help, I’m not a macos expert. I filed Potential problems on MacOS · Issue #8 · lukstafi/ocaml-gccjit What I noticed is that on MacOS, gcc can actually point to clang, maybe it’s related to that, but I don’t know.

Currently everything works! Maybe someone in the know can help fix the installation at some point.

That is not a problem, you don’t need to do anything about it. The name conflict is an experimental feature of the lint and we are still tweaking it