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

**URL:** <https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492>\
**Category:** Community\
**Tags:** announce\
**Created:** [April 15, 2024, 12:48pm UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492 "2024-04-15T12:48:13Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [April 15, 2024, 12:48pm UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/1 "2024-04-15T12:48:14Z")

</div>

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](https://ocaml.org/success-stories/peta-byte-scale-web-crawler). ([Ahrefs website](https://ahrefs.com/).)

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

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!

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [April 15, 2024, 8:40pm UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/2 "2024-04-15T20:40:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [April 15, 2024, 10:14pm UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/3 "2024-04-15T22:14:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [April 22, 2024, 10:09pm UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/4 "2024-04-22T22:09:15Z")

</div>

OCANNL 0.3.2 is out now. Thanks!

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [April 23, 2024, 11:37am UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/5 "2024-04-23T11:37:16Z")

</div>

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.

```auto
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:
    gcc@13

<><> 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
└─

```

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [April 23, 2024, 11:40am UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/6 "2024-04-23T11:40:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [April 23, 2024, 11:41am UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/7 "2024-04-23T11:41:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [April 23, 2024, 9:19pm UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/8 "2024-04-23T21:19:11Z")

</div>

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’?

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [April 24, 2024, 8:09am UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/9 "2024-04-24T08:09:41Z")

</div>

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? 😉

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [April 24, 2024, 8:20am UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/10 "2024-04-24T08:20:02Z")

</div>

> [@n4323](#):
>
> 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?

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

---

<div class="post-metadata">

**Author:** ![Halberd](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/halberd/32/5029_2.png) [@Halberd](https://discuss.ocaml.org/u/Halberd)\
**Post date:** [April 24, 2024, 10:39am UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/11 "2024-04-24T10:39:10Z")

</div>

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:)

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [April 24, 2024, 10:42am UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/12 "2024-04-24T10:42:04Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [April 24, 2024, 11:39am UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/13 "2024-04-24T11:39:53Z")

</div>

quick initial feedback: i was able to `opam pin` version 0.3.3.0 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` !

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [April 24, 2024, 11:46am UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/14 "2024-04-24T11:46:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [April 24, 2024, 11:59am UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/15 "2024-04-24T11:59:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mseri](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mseri/32/91_2.png) [@mseri](https://discuss.ocaml.org/u/mseri)\
**Post date:** [April 24, 2024, 6:18pm UTC](https://discuss.ocaml.org/t/ann-ocannl-0-3-1-a-from-scratch-deep-learning-i-e-dense-tensor-optimization-framework/14492/16 "2024-04-24T18:18:00Z")

</div>

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
