The NuTorch logo: a green nautilus shell with a flame

GPU tensors from your shell

Run PyTorch-style tensor operations from bash, zsh, fish, or Nushell. NuTorch keeps tensors on the GPU and passes lightweight handles through ordinary shell pipelines. For macOS.

a=$(torch tensor '[1,2,3]')
b=$(torch tensor '[4,5,6]')
torch add $a $b | torch value
# [5.0,7.0,9.0]   computed on the GPU
let a = (torch tensor [1 2 3])
let b = (torch tensor [4 5 6])
torch add $a $b | torch value
# [5.0, 7.0, 9.0] — a native list, on the GPU

Powered by LibTorch on Metal. Requires an Apple-silicon Mac. For Nu or ahsh, complete the module setup before using the Nushell example.

Installation

Install with Homebrew on an Apple-silicon Mac. Homebrew builds from source and may install build dependencies; allow a few minutes for installation.

brew tap astrohackerlabs/nutorch
brew trust astrohackerlabs/nutorch
brew install astrohackerlabs/nutorch/nutorch

Shell-native tensors

Each command sends one operation to the daemon. Results come back as handles, so tensor operations compose naturally in pipelines.

Using Nushell or ahsh? Follow the Nushell setup instructions to configure module discovery before running the Nu example.

bash

m=$(torch randn '[3,3]')
torch mm $m $m | torch mean | torch value
# matrix product, then mean — one pipeline

nushell

use nutorch.nu *
let t = ([[1 2] [3 4]] | torch tensor)
$t | torch mm $t | torch value
# native table out

Autograd

w=$(torch randn '[3]' --requires_grad)
loss=$(torch mul $w $w | torch sum)
torch backward $loss
torch grad $w | torch value

Apple-silicon GPU

NuTorch runs tensors on Metal through LibTorch. There is no CPU mode and no device flag.

Works in any shell

Handles are plain strings, so bash, zsh, fish, scripts, and pipelines all work naturally. Nushell gets structured commands too.

PyTorch-style API

Operation names, arguments, defaults, broadcasting, autograd, modules, and optimizers follow PyTorch wherever possible.

Daemon-backed tensors

A background daemon owns the tensors, GPU memory, and computation graph. Commands stay small; tensor data stays out of the shell.