Description
Shumai is a differentiable tensor library designed for JavaScript and TypeScript, leveraging the speed of Bun and the power of Flashlight. It aims to make data manipulation, model training, and advanced inference logic more accessible and efficient for developers within the JavaScript ecosystem. By utilizing native typed arrays and Bun's Just-In-Time (JIT) compiler, Shumai offers a performant solution for tasks ranging from dataset creation to training small machine learning models.
The library provides core tensor operations, automatic differentiation for gradient computation, and seamless conversion to and from JavaScript native arrays. This allows developers to work with data directly in JavaScript, prepare it for GPU-compatible arrays, and then train models without leaving the environment. Shumai's architecture is built to minimize overhead, allowing JavaScript to get out of the way during training and inference, especially for smaller models.
Key capabilities include standard array utilities, tensor creation, mathematical operations, and gradient tracking. Users can enable gradient computation for tensors, perform operations, and then access the computed gradients. The library also offers features for memory management tuning, allowing users to adjust garbage collection parameters to optimize performance based on hardware capabilities. Furthermore, Shumai includes a statistics gathering system that can log operation performance to the console or over HTTP, with options for scoped profiling and stack trace collection.
Shumai is particularly beneficial for software engineers and researchers who are already working within the JavaScript ecosystem and want to incorporate machine learning capabilities without a steep learning curve associated with other languages or frameworks. Its performance benchmarks show significant advantages over libraries like TensorFlow.js in various operations, especially on Apple M1 Pro and Nvidia GPUs. The project is experimental, and contributions are welcomed to improve its functionality and stability.
Shumai's Core Features
Fast, differentiable tensor library for JavaScript and TypeScript
Built with Bun and Flashlight for high performance
Supports automatic differentiation for gradient computation
Seamless conversion between tensors and JavaScript native arrays
Optimized for training small models and advanced inference logic
Leverages native typed arrays and JIT compilation
Memory usage tuning for performance optimization
Built-in statistics gathering for operation profiling
Scoped statistics collection for isolated profiling
Experimental software with active development
Supports GPU computation via ArrayFire backends (CUDA on Linux, CPU on macOS)
Extensible statistics logging with Console and HTTP options
Getting Started with Shumai
Install Bun and ArrayFire: Follow platform-specific instructions for macOS and Linux.
Install Shumai: Run `bun install @shumai/shumai`.
Import Shumai: Use `import * as sm from '@shumai/shumai'` in your TypeScript/JavaScript code.
Create Tensors: Utilize functions like `sm.randn()` or `sm.tensor()` to create tensors.
Perform Operations: Apply mathematical operations such as `matmul()`, `mul()`, and `sum()`.
Enable Gradients: Set `tensor.requires_grad = true` for tensors that need gradient tracking.
Compute Gradients: Call `.backward()` on the loss tensor to populate gradients.
Tune Memory: Adjust memory options using `util.memoryOptions()` for performance.
Shumai's Use Cases
- Dataset Creation
- Model Training
- Inference Logic
- Data Preprocessing
- Research Prototyping
- Application Development








