shumai is a fast, network-connected, differentiable tensor library designed for TypeScript (and JavaScript), built by Facebook Research on top of Bun + Flashlight. It is aimed at software engineers and researchers. Note: this is experimental software.
Main capabilities:
- Provides standard array utilities and supports conversion to and from native JavaScript arrays.
- Supports differentiable tensor operations; for the specific supported operators, refer to the relevant documentation.
- Prioritizes the attached GPU or accelerator; CPU computation uses ArrayFire's CPU backend, but is not highly optimized.
How to use: Installation steps (still being improved):
- Install Bun (https://bun.sh)和 ArrayFire.
- macOS: install ArrayFire using Homebrew (brew install arrayfire). Linux: you can install ArrayFire using a package manager (such as apt), or build it from source.
- Install the package and underlying libraries using bun: bun install @shumai/shumai.
Building from source:
- The dependency libraries that need to be built from source include libflashlight and libflashlight_binding. You can use npm pack to generate the @shumai/shumai_*.tgz package, then install it via npm install.
- macOS: install the ArrayFire CPU backend, build and install Flashlight, and build the Shumai bindings.
- Linux: install ArrayFire, using the CUDA backend by default; you can also build the CPU backend (OpenCL support is coming soon), and build the Shumai bindings.
Supported platforms: only macOS and Linux. Windows is not officially supported, but it can be used via Docker + WSL2 + Linux, including CUDA support.
Performance and statistics:
- FFI bindings in Bun are extremely fast (about 3ns), making it suitable for quickly training small models.
- Provides memory management tuning options, such as upperBoundThreshold, which can affect garbage collection behavior.
- Supports collecting statistics using StatsLoggerConsole, and StatsLoggerHttp can be used to collect statistics across threads, processes, or hosts. Stack traces are disabled by default (they can be enabled, but this adds more than 50% overhead). Supports scoped statistics.
Applicable scenarios:
- Creating datasets: leverage JavaScript's native typed arrays and JIT compiler to conveniently process data and convert it into large flat arrays compatible with the GPU.
- Quickly training small models: FFI bindings are fast, and JS will not become the bottleneck.
- Advanced/fine-grained training/inference logic: Bun uses the JSC JIT compiler, allowing you to write complex training logic without needing a native C++ implementation.
- Building applications: the JavaScript ecosystem is large, making application development easier.
Limitations:
- Experimental software; the installation process may haveThere are issues; if you encounter problems, you need to submit an issue.
- Only macOS and Linux are supported; Windows is not officially supported.
- CPU computation uses the ArrayFire CPU backend and is not well optimized.
- The OpenCL backend and other non-ArrayFire tensor backends are not yet supported.
License: MIT.