Clorch is a Clojure deep-learning library backed by LibTorch — the C++ engine that powers PyTorch. It gives you PyTorch-style tensors, automatic differentiation, neural-network modules, optimizers, data loaders, mixed-precision training, and NCCL distributed training through a REPL-friendly Clojure API.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/antlobach/clorch/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Add Clorch to your project and configure the Java runtime
Quickstart
Build and train your first neural network in minutes
Tensors
Create, manipulate, and inspect LibTorch tensors from Clojure
Neural Networks
Build models with built-in layers and the defmodel macro
Distributed Training
Multi-GPU NCCL training with DDP, AMP, and checkpoints
LLM Components
RoPE, GQA, SwiGLU, KV cache, and autoregressive generation
What Clorch provides
Clorch maps directly to PyTorch’s conceptual model while presenting an idiomatic Clojure API. Every heavy operation executes in native C++ via JavaCPP, bypassing JVM overhead for tensor math.Tensor Ops
~170 operations covering arithmetic, reductions, shape manipulation, and sampling
Autograd
Automatic differentiation with requires-grad, backward passes, and no-grad scopes
Memory Control
Deterministic native-memory scopes via with-torch and PointerScope
Optimizers
SGD, Adam, AdamW, RMSprop, and Adagrad wrapping LibTorch C++ implementations
Distributions
Probability distributions with sample, log-prob, mean, and variance
AMP
float16/bfloat16 autocast and dynamic gradient scaling for CUDA training
Getting started
Add the dependency
Add Clorch to your
deps.edn using a git coordinate pointing to the latest tag.deps.edn
Start a REPL
Launch the Clojure REPL from your project directory. Clorch automatically selects CPU or CUDA natives on startup.
Create tensors and run autograd
Require the core namespaces and start experimenting with tensors and gradients immediately.
PyTorch namespace mapping
Clorch follows PyTorch’s namespace structure. If you know PyTorch, you can navigate Clorch immediately.| PyTorch | Clorch |
|---|---|
torch | clorch.torch |
torch.nn | clorch.nn |
torch.nn.functional | clorch.nn.functional |
torch.optim | clorch.optim |
torch.autograd | clorch.autograd |
torch.cuda | clorch.cuda |
torch.amp | clorch.amp |
torch.distributed | clorch.distributed |
DistributedDataParallel | clorch.nn.parallel |
torch.distributions | clorch.distributions |
torch.linalg | clorch.linalg |
Dataset / DataLoader | clorch.data |
Clorch follows PyTorch concepts but does not expose every PyTorch symbol. Check the API documentation or source before translating a Python call directly.