IBM Analog Hardware Acceleration Kit is an open source Python toolkit for exploring and using the capabilities of in-memory computing devices in the context of artificial intelligence.
:warning: This library is currently in beta and under active development. Please be mindful of potential issues and keep an eye for improvements, new features and bug fixes in upcoming versions.
The toolkit consists of two main components:
A series of primitives and features that allow using the toolkit within
PyTorch:
A high-performant (CUDA-capable) C++ simulator that allows for simulating a wide range of analog devices and crossbar configurations by using abstract functional models of material characteristics with adjustable parameters. Features include:
Along with the two main components, the toolkit includes other functionalities such as:
In case you are using the IBM Analog Hardware Acceleration Kit for your research, please cite the AICAS21 paper that describes the toolkit:
Malte J. Rasch, Diego Moreda, Tayfun Gokmen, Manuel Le Gallo, Fabio Carta, Cindy Goldberg, Kaoutar El Maghraoui, Abu Sebastian, Vijay Narayanan. "A flexible and fast PyTorch toolkit for simulating training and inference on analog crossbar arrays" (2021 IEEE 3rd International Conference on Artificial Intelligence Circuits and Systems)
from torch import Tensor
from torch.nn.functional import mse_loss
# Import the aihwkit constructs.
from aihwkit.nn import AnalogLinear
from aihwkit.optim import AnalogSGD
x = Tensor([[0.1, 0.2, 0.4, 0.3], [0.2, 0.1, 0.1, 0.3]])
y = Tensor([[1.0, 0.5], [0.7, 0.3]])
# Define a network using a single Analog layer.
model = AnalogLinear(4, 2)
# Use the analog-aware stochastic gradient descent optimizer.
opt = AnalogSGD(model.parameters(), lr=0.1)
opt.regroup_param_groups(model)
# Train the network.
for epoch in range(10):
pred = model(x)
loss = mse_loss(pred, y)
loss.backward()
opt.step()
print('Loss error: {:.16f}'.format(loss))
You can find more examples in the examples/ folder of the project, and
more information about the library in the documentation. Please note that
the examples have some additional dependencies - you can install them via
pip install -r requirements-examples.txt.
You can find interactive notebooks and tutorials in the notebooks/ directory.
We also recommend to take a look at the tutorial article that describes the usage of the toolkit that can be found here:
Manuel Le Gallo, Corey Lammie, Julian Buechel, Fabio Carta, Omobayode Fagbohungbe, Charles Mackin, Hsinyu Tsai, Vijay Narayanan, Abu Sebastian, Kaoutar El Maghraoui, Malte J. Rasch. "Using the IBM Analog In-Memory Hardware Acceleration Kit for Neural Network Training and Inference" (APL Machine Learning Journal:1(4) 2023)
In traditional hardware architecture, computation and memory are siloed in different locations. Information is moved back and forth between computation and memory units every time an operation is performed, creating a limitation called the von Neumann bottleneck.
Analog AI delivers radical performance improvements by combining compute and memory in a single device, eliminating the von Neumann bottleneck. By leveraging the physical properties of memory devices, computation happens at the same place where the data is stored. Such in-memory computing hardware increases the speed and energy efficiency needed for next-generation AI workloads.
An in-memory computing chip typically consists of multiple arrays of memory devices that communicate with each other. Many types of memory devices such as phase-change memory (PCM), resistive random-access memory (RRAM), and Flash memory can be used for in-memory computing.
Memory devices have the ability to store synaptic weights in their analog charge (Flash) or conductance (PCM, RRAM) state. When these devices are arranged in a crossbar configuration, it allows to perform an analog matrix-vector multiplication in a single time step, exploiting the advantages of analog storage capability and Kirchhoff’s circuits laws. You can learn more about it in our online demo.
In deep learning, data propagation through multiple layers of a neural network involves a sequence of matrix multiplications, as each layer can be represented as a matrix of synaptic weights. The devices are arranged in multiple crossbar arrays, creating an artificial neural network where all matrix multiplications are performed in-place in an analog manner. This structure allows to run deep learning models at reduced energy consumption.
This repository contains a custom CUDA-enabled build of AIHWKit with LR-TT (Low-Rank Tensor Train) support. For installation instructions for this specific build, see the LR-TT Installation Guide section below.
The preferred way to install the standard package is by using the Python package index:
pip install aihwkit
There is a conda package for aihwkit available in conda-forge. It can be installed in a conda environment running on a Linux or WSL in a Windows system.
CPU
conda install -c conda-forge aihwkit
GPU
conda install -c conda-forge aihwkit-gpu
If you encounter any issues during download or want to compile the package
for your environment, please take a look at the advanced installation guide.
That section describes the additional libraries and tools required for
compiling the sources using a build system based on cmake.
For GPU support, you can also build a docker container following the CUDA Dockerfile instructions. You can then run a GPU enabled docker container using the follwing command from your peoject dircetory
docker run --rm -it --gpus all -v $(pwd):$HOME --name aihwkit aihwkit:cuda bash
This repository contains a custom CUDA-enabled build of AIHWKit with LR-TT (Low-Rank Tensor Train) support specifically built for CUDA 12.1 and Python 3.10.
Download and install the wheel directly from the GitHub release:
# Download the wheel
curl -L -o aihwkit-lrtt.whl https://github.com/Siguros/test_move/releases/download/v1.0.0-lrtt/aihwkit-0.9.0-cp310-cp310-linux_x86_64.whl
# Install with no dependencies (recommended)
pip install --no-deps ./aihwkit-lrtt.whl
If you have a GitHub token with access to private repositories:
# Set your GitHub token
export GITHUB_TOKEN="your_github_token_here"
# Download via asset ID (avoids filename encoding issues)
curl -L -H "Authorization: token ${GITHUB_TOKEN}" \
-H "Accept: application/octet-stream" \
"https://api.github.com/repos/Siguros/test_move/releases/assets/285490233" \
-o aihwkit-lrtt.whl
# Install with no dependencies
pip install --no-deps ./aihwkit-lrtt.whl
After installation, verify that CUDA support and LR-TT functionality work:
import aihwkit
from aihwkit.simulator.rpu_base import cuda
import torch
print("AIHWKit version:", aihwkit.__version__)
print("CUDA compiled:", cuda.is_compiled())
# Test LR-TT functionality
from aihwkit.nn import AnalogLinear
from aihwkit.simulator.presets.lrtt import lrtt_idealized
# Create LR-TT configuration
cfg = lrtt_idealized(rank=16)
cfg.device.forward_inject = True
cfg.device.lora_alpha = 8.0
# Create analog layer
layer = AnalogLinear(32, 16, bias=False, rpu_config=cfg)
# Move to CUDA if available
if torch.cuda.is_available():
layer = layer.cuda()
x = torch.randn(4, 32, device='cuda')
print("✓ Using CUDA device")
else:
x = torch.randn(4, 32)
print("! Using CPU device")
# Test forward and backward pass
y = layer(x)
loss = y.sum()
loss.backward()
print("✓ LR-TT forward/backward pass successful")
print("Output shape:", y.shape)
This wheel was built with:
If cuda.is_compiled() returns False:
import torch
print("PyTorch CUDA available:", torch.cuda.is_available())
print("PyTorch CUDA version:", torch.version.cuda)
For installation issues:
--no-deps flag to avoid dependency conflictsIBM Research has developed IBM Analog Hardware Acceleration Kit, with Malte Rasch, Diego Moreda, Fabio Carta, Julian Büchel, Corey Lammie, Charles Mackin, Kim Tran, Tayfun Gokmen, Manuel Le Gallo-Bourdeau, and Kaoutar El Maghraoui as the initial core authors, along with many contributors.
You can contact us by opening a new issue in the repository or alternatively
at the aihwkit@us.ibm.com email address.
This project is licensed under [MIT License].
Jupyter Notebook
32.9%
Python
30.1%
C++
23.1%
Cuda
13.2%
IBM Analog Hardware Acceleration Kit is an open source Python toolkit for exploring and using the capabilities of in-memory computing devices in the context of artificial intelligence.
:warning: This library is currently in beta and under active development. Please be mindful of potential issues and keep an eye for improvements, new features and bug fixes in upcoming versions.
The toolkit consists of two main components:
A series of primitives and features that allow using the toolkit within
PyTorch:
A high-performant (CUDA-capable) C++ simulator that allows for simulating a wide range of analog devices and crossbar configurations by using abstract functional models of material characteristics with adjustable parameters. Features include:
Along with the two main components, the toolkit includes other functionalities such as:
In case you are using the IBM Analog Hardware Acceleration Kit for your research, please cite the AICAS21 paper that describes the toolkit:
Malte J. Rasch, Diego Moreda, Tayfun Gokmen, Manuel Le Gallo, Fabio Carta, Cindy Goldberg, Kaoutar El Maghraoui, Abu Sebastian, Vijay Narayanan. "A flexible and fast PyTorch toolkit for simulating training and inference on analog crossbar arrays" (2021 IEEE 3rd International Conference on Artificial Intelligence Circuits and Systems)
from torch import Tensor
from torch.nn.functional import mse_loss
# Import the aihwkit constructs.
from aihwkit.nn import AnalogLinear
from aihwkit.optim import AnalogSGD
x = Tensor([[0.1, 0.2, 0.4, 0.3], [0.2, 0.1, 0.1, 0.3]])
y = Tensor([[1.0, 0.5], [0.7, 0.3]])
# Define a network using a single Analog layer.
model = AnalogLinear(4, 2)
# Use the analog-aware stochastic gradient descent optimizer.
opt = AnalogSGD(model.parameters(), lr=0.1)
opt.regroup_param_groups(model)
# Train the network.
for epoch in range(10):
pred = model(x)
loss = mse_loss(pred, y)
loss.backward()
opt.step()
print('Loss error: {:.16f}'.format(loss))
You can find more examples in the examples/ folder of the project, and
more information about the library in the documentation. Please note that
the examples have some additional dependencies - you can install them via
pip install -r requirements-examples.txt.
You can find interactive notebooks and tutorials in the notebooks/ directory.
We also recommend to take a look at the tutorial article that describes the usage of the toolkit that can be found here:
Manuel Le Gallo, Corey Lammie, Julian Buechel, Fabio Carta, Omobayode Fagbohungbe, Charles Mackin, Hsinyu Tsai, Vijay Narayanan, Abu Sebastian, Kaoutar El Maghraoui, Malte J. Rasch. "Using the IBM Analog In-Memory Hardware Acceleration Kit for Neural Network Training and Inference" (APL Machine Learning Journal:1(4) 2023)
In traditional hardware architecture, computation and memory are siloed in different locations. Information is moved back and forth between computation and memory units every time an operation is performed, creating a limitation called the von Neumann bottleneck.
Analog AI delivers radical performance improvements by combining compute and memory in a single device, eliminating the von Neumann bottleneck. By leveraging the physical properties of memory devices, computation happens at the same place where the data is stored. Such in-memory computing hardware increases the speed and energy efficiency needed for next-generation AI workloads.
An in-memory computing chip typically consists of multiple arrays of memory devices that communicate with each other. Many types of memory devices such as phase-change memory (PCM), resistive random-access memory (RRAM), and Flash memory can be used for in-memory computing.
Memory devices have the ability to store synaptic weights in their analog charge (Flash) or conductance (PCM, RRAM) state. When these devices are arranged in a crossbar configuration, it allows to perform an analog matrix-vector multiplication in a single time step, exploiting the advantages of analog storage capability and Kirchhoff’s circuits laws. You can learn more about it in our online demo.
In deep learning, data propagation through multiple layers of a neural network involves a sequence of matrix multiplications, as each layer can be represented as a matrix of synaptic weights. The devices are arranged in multiple crossbar arrays, creating an artificial neural network where all matrix multiplications are performed in-place in an analog manner. This structure allows to run deep learning models at reduced energy consumption.
This repository contains a custom CUDA-enabled build of AIHWKit with LR-TT (Low-Rank Tensor Train) support. For installation instructions for this specific build, see the LR-TT Installation Guide section below.
The preferred way to install the standard package is by using the Python package index:
pip install aihwkit
There is a conda package for aihwkit available in conda-forge. It can be installed in a conda environment running on a Linux or WSL in a Windows system.
CPU
conda install -c conda-forge aihwkit
GPU
conda install -c conda-forge aihwkit-gpu
If you encounter any issues during download or want to compile the package
for your environment, please take a look at the advanced installation guide.
That section describes the additional libraries and tools required for
compiling the sources using a build system based on cmake.
For GPU support, you can also build a docker container following the CUDA Dockerfile instructions. You can then run a GPU enabled docker container using the follwing command from your peoject dircetory
docker run --rm -it --gpus all -v $(pwd):$HOME --name aihwkit aihwkit:cuda bash
This repository contains a custom CUDA-enabled build of AIHWKit with LR-TT (Low-Rank Tensor Train) support specifically built for CUDA 12.1 and Python 3.10.
Download and install the wheel directly from the GitHub release:
# Download the wheel
curl -L -o aihwkit-lrtt.whl https://github.com/Siguros/test_move/releases/download/v1.0.0-lrtt/aihwkit-0.9.0-cp310-cp310-linux_x86_64.whl
# Install with no dependencies (recommended)
pip install --no-deps ./aihwkit-lrtt.whl
If you have a GitHub token with access to private repositories:
# Set your GitHub token
export GITHUB_TOKEN="your_github_token_here"
# Download via asset ID (avoids filename encoding issues)
curl -L -H "Authorization: token ${GITHUB_TOKEN}" \
-H "Accept: application/octet-stream" \
"https://api.github.com/repos/Siguros/test_move/releases/assets/285490233" \
-o aihwkit-lrtt.whl
# Install with no dependencies
pip install --no-deps ./aihwkit-lrtt.whl
After installation, verify that CUDA support and LR-TT functionality work:
import aihwkit
from aihwkit.simulator.rpu_base import cuda
import torch
print("AIHWKit version:", aihwkit.__version__)
print("CUDA compiled:", cuda.is_compiled())
# Test LR-TT functionality
from aihwkit.nn import AnalogLinear
from aihwkit.simulator.presets.lrtt import lrtt_idealized
# Create LR-TT configuration
cfg = lrtt_idealized(rank=16)
cfg.device.forward_inject = True
cfg.device.lora_alpha = 8.0
# Create analog layer
layer = AnalogLinear(32, 16, bias=False, rpu_config=cfg)
# Move to CUDA if available
if torch.cuda.is_available():
layer = layer.cuda()
x = torch.randn(4, 32, device='cuda')
print("✓ Using CUDA device")
else:
x = torch.randn(4, 32)
print("! Using CPU device")
# Test forward and backward pass
y = layer(x)
loss = y.sum()
loss.backward()
print("✓ LR-TT forward/backward pass successful")
print("Output shape:", y.shape)
This wheel was built with:
If cuda.is_compiled() returns False:
import torch
print("PyTorch CUDA available:", torch.cuda.is_available())
print("PyTorch CUDA version:", torch.version.cuda)
For installation issues:
--no-deps flag to avoid dependency conflictsIBM Research has developed IBM Analog Hardware Acceleration Kit, with Malte Rasch, Diego Moreda, Fabio Carta, Julian Büchel, Corey Lammie, Charles Mackin, Kim Tran, Tayfun Gokmen, Manuel Le Gallo-Bourdeau, and Kaoutar El Maghraoui as the initial core authors, along with many contributors.
You can contact us by opening a new issue in the repository or alternatively
at the aihwkit@us.ibm.com email address.
This project is licensed under [MIT License].
Jupyter Notebook
32.9%
Python
30.1%
C++
23.1%
Cuda
13.2%