OpenViSTAI · Agents · Blockchain · Crypto
Menu
AI Developer Tools & SDKs

Ocaml Torch

Ocaml Torch is an OCaml library providing bindings to PyTorch’s tensor functionality through the PyTorch C++ API. It supports NumPy-like tensor computation, tape-based automatic differentiation, and GPU acceleration, with repository examples for machine-learning tasks.

Independent OpenViST project profile, based on linked sources.

Ocaml Torch — OpenViST project profile in AI Developer Tools & SDKs.
OpenViST project illustration. See the linked sources for product details.
Understand the project

Practical overview

When it fits

Use it when an OCaml project needs PyTorch tensor operations or when exploring machine-learning workflows in OCaml. Check the Jane Street torch repository for ongoing development, since this project’s README says development has moved there.

Who it is for

  • OCaml developers adding tensor-based numerical computation to applications.
  • Machine-learning practitioners building experiments and model workflows in OCaml.
  • Developers who need differentiable tensor computations or GPU-backed tensor operations from OCaml.

Documented uses

  • Create and manipulate tensors in OCaml.
  • Build differentiable computations and train models using tensor operations.
  • Explore documented examples such as MNIST, ResNet fine-tuning, GANs, and Python-model execution.
Before you choose

Requirements & limits

  • The bindings use the PyTorch C++ API and are described as mostly automatically generated.
  • The README associates the repository’s current tip and opam package v0.7 with PyTorch 2.0.0.
  • On Linux, the README calls for libtorch with the cxx11 ABI; opam installation installs CPU libtorch automatically.
  • The README provides CUDA 11.7 libtorch guidance for GPU-oriented setup.
  • The repository is licensed under Apache-2.0, and its README directs ongoing development to Jane Street’s torch repository.

Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.

Source-based practical guide

Install the CPU package and build a tensor example

Set up the opam package, then compile and run the README’s basic Dune tensor program.

Before you start

  • An OCaml environment with opam and Dune available.
  • The README states that opam installation automatically installs CPU libtorch.

Steps

  1. Install the package with opam install torch.

  2. Create example.ml containing open Torch and a program that creates and prints Tensor.randn [ 4; 2 ].

  3. Create a Dune file declaring an executable named example linked with the torch library.

  4. Run dune exec example.exe to compile and run the example.

Expected outcome

A small OCaml program that creates and prints a random tensor using the Torch library.

Guide limitations

  • The README warns that building the bytecode target may not work on macOS.
  • The repository README says development has moved to Jane Street’s torch repository.
Source-based practical guide

Prepare the repository examples with a downloaded libtorch

Configure the documented alternative libtorch path and build the repository examples.

Before you start

  • Linux, with a libtorch package using the cxx11 ABI as specified by the README.
  • Git and the tools required by the repository’s make all build.

Steps

  1. Download and extract a suitable libtorch package.

  2. Set LIBTORCH to the extracted directory.

  3. Clone the repository and change into its directory.

  4. Run the command below.

    Documented command
    make all

Expected outcome

The repository examples are built using the configured libtorch directory.

Guide limitations

  • The README’s Linux guidance specifies cxx11 ABI packages and lists CPU and CUDA 11.7 builds.
  • The guide documents building the examples, not running a particular model or verifying GPU operation.
Evidence and transparency

Sources & review

Source record details
Source availability
Active
Sources checked
14 October 2026
Original website title
LaurentMazare/ocaml-torch · Official homepage title · retained in its source language