IBM Analog Hardware Acceleration Kit

repository·master·Indexed 19 days ago

https://github.com/ibm/aihwkit

An open-source Python toolkit for simulating and training neural networks on analog in-memory computing hardware, such as PCM or RRAM crossbar arrays. It provides PyTorch integration with analog-aware modules and optimizers, a CUDA-capable C++ simulator for modeling material characteristics, and utilities for deploying hardware-aware trained networks to Fusion chips via the IBM Analog Composer.

Tokens
47.8K
Snippets
127
Records
172
Agent score
67%

What's inside aihwkit

  1. Overview of PyTorch integration in aihwkit

    master

    The aihwkit library integrates with PyTorch by providing analog primitives that fit into standard PyTorch workflows. Most high-level features are exposed as PyTorch modules or optimizers.

    Key integration modules:

    • aihwkit.nn: Provides Analog Modules (layers) and Functions.
    • aihwkit.optim: Provides Analog Optimizers.
  2. Overview of aihwkit components

    master

    The aihwkit toolkit is designed for exploring in-memory computing for AI and consists of two primary pillars:

    1. PyTorch Integration

    Provides primitives to integrate analog hardware simulation into the standard PyTorch workflow:

    • Analog Modules: Includes AnalogLinear, 1d/2d/3d convolution layers, LSTM layers, and sequential containers.
    • Analog Training: Supports analog-aware optimizers (like AnalogSGD) and in-situ training algorithms (like Tiki-Taka).
    • Hardware-Awareness: Includes statistical models of phase-change memory (PCM) and allows training with hardware non-idealities (noise, fluctuations) to improve inference robustness.

    2. Analog Devices Simulator

    A high-performance, CUDA-capable C++ simulator that models material characteristics and crossbar configurations. It supports:

    • Forward pass noise, device fluctuations, and ADC/DAC discretization.
    • Stochastic update pulse trains with finite weight update sizes.
    • Device-to-device systematic variations and cycle-to-cycle noise.
    • Dynamic input scaling and bound management.
  3. Overview of Analog AI Cloud Composer (AAICC)

    master
    The Analog AI Cloud Composer (AAICC) is a managed cloud platform that provides 'Analog AI as a service' (AAaaS). It leverages the open-source AIHWKit simulation platform to provide a no-code, interactive cloud experience for exploring, simulating, and creating Analog AI neural networks. Users can experiment with tuning analog devices to create accurate and sustainable AI models through a web application or a command-line interface (CLI).
  4. Overview of IBM Analog Hardware Acceleration Kit

    master

    The IBM Analog Hardware Acceleration Kit is an open-source Python toolkit designed for exploring and using in-memory computing devices for artificial intelligence. It provides tools to simulate analog hardware behavior within deep learning workflows, specifically focusing on training and inference on analog crossbar arrays.

    The toolkit is composed of two primary components:

    1. PyTorch Integration: Provides analog neural network modules (e.g., AnalogLinear, convolution layers), analog-aware optimizers (like AnalogSGD), and hardware-aware training capabilities that include non-idealities and noise in the forward pass.
    2. Analog Devices Simulator: A high-performance, CUDA-capable C++ simulator that models material characteristics, device fluctuations, noise, and stochastic update pulse trains for various analog devices and crossbar configurations.

    Additional features include a library of device presets calibrated to real hardware, an experiment execution module for high-level use cases, and integration with the AIHW Composer platform for cloud execution.

  5. What is Analog AI and In-Memory Computing?

    master

    Analog AI leverages in-memory computing to overcome the von Neumann bottleneck, where computation and memory are traditionally siloed. Instead of moving data between a CPU and memory, computation happens directly within memory devices (such as PCM, RRAM, or Flash) by using their physical properties (charge or conductance states).

    In deep learning, this is achieved using crossbar arrays. Each layer of a neural network is represented by a matrix of synaptic weights stored at the crosspoints of these arrays. Matrix multiplications are performed in-place in an analog manner, significantly reducing energy consumption and latency compared to conventional digital hardware.

  6. How aihwkit architecture works

    master

    The aihwkit library is designed as a multi-layered stack that integrates analog simulation capabilities into the PyTorch ecosystem.

    Users should primarily interact with the PyTorch layer, which provides high-level primitives like analog-aware layers and optimizers. This layer inherits from standard PyTorch classes and replaces default functionality with calls to a Tiles object in the simulator abstraction layer.

    The Four Layers of aihwkit:

    1. PyTorch layer: The high-level interface for users. It provides analog-aware modules and optimizers that integrate seamlessly with PyTorch.
      • Relevant modules: aihwkit.nn, aihwkit.optim.
    2. Python simulator abstraction layer: Provides Python objects that abstract away the complexities of the lower-level simulator. It maps structures and classes into an interface suitable for the PyTorch layer and handles serialization.
      • Relevant modules: aihwkit.simulator.tiles, aihwkit.simulator.configs, aihwkit.simulator.presets.
    3. Pybind Python layer: A bridge between C++ and Python using Pybind. It exposes selected C++ simulator classes and methods to Python with a near 1:1 mapping. While useful for direct simulator experimentation, users are encouraged to use the upper layers to avoid extra overhead and manual management.
      • Relevant modules: aihwkit.simulator.rpu_base.tiles, aihwkit.simulator.rpu_base.devices, aihwkit.simulator.rpu_base.parameters.
    4. C++ layer (rpucuda): The core engine where actual simulation operations over Tiles occur. This layer is not directly accessible from Python but can be used by other C++ programs via provided headers.
  7. How Analog Chips Implement Neural Networks

    master

    An analog in-memory computing chip consists of multiple crossbar arrays that communicate with each other.

    • Weight Storage: Weights are stored in the conductance or charge state of memory devices. Typically, two devices are used per weight to encode the positive and negative components separately.
    • Data Propagation: Input data is applied to the crossbar rows, and the resulting output is deciphered at the columns.
    • Non-linearity: The neuron's non-linear function is implemented at the crossbar periphery using analog or digital circuits.
    • Connectivity: For feed-forward networks (MLPs, CNNs), arrays communicate with the next layer's array. For recurrent networks (RNNs), the output of an array communicates back to its own input.
  8. Understand the CMO-ReRAM Statistical Model for Inference

    master

    The aihwkit includes a statistical model to simulate Conductive Metal Oxide/HfOx-ReRAM (CMO-ReRAM) behavior during inference. This model allows developers to evaluate how realistic hardware non-idealities and noise affect neural network inference accuracy.

    Key Characteristics:

    • Calibration: Based on measurements from actual IBM-fabricated CMO-ReRAM arrays.
    • Weight Mapping: Pre-trained software weights are normalized to a [-1, 1] range.
      • -1 maps to the High Resistance State (HRS), or $g_{min}$.
      • 1 maps to the Low Resistance State (LRS), or $g_{max}$.
    • Conductance Range: The model assumes a minimum conductance of $8 \mu S$ and a maximum of $90 \mu S$.
    • Usage Context: This model is intended for use during inference only, assuming weights have already been trained using algorithms like SGD or Tiki-Taka.
  9. Additional aihwkit features and utilities

    master

    Beyond core simulation, aihwkit provides:

    • Device Presets: A library of presets calibrated to real hardware data.
    • Experiment Module: A high-level module for executing neural network training experiments with minimal code.
    • Model Conversion Utility: Automatically converts pre-trained models (e.g., standard PyTorch models) to their equivalent analog models by replacing linear/conv layers with analog layers.
    • AIHW Composer Integration: Integration with a no-code web platform for executing experiments in the cloud.
  10. Simulate Conductance Drift in ReRAM

    master

    Drift simulates the conductance relaxation that occurs after programming. In CMO-ReRAM, this relaxation is modeled as a Gaussian distribution:

    $g_{drift} = \mathcal{N}(\mu_{drift}, \sigma_{drift})$

    Unlike other resistive memory devices, the drift in CMO-ReRAM is independent of the target conductance level. The time dependency is modeled using the logarithm of time ($t$):

    • Mean Drift: $\mu_{drift} = g_{prog} - 0.089 \log(t) [\mu S]$
    • Standard Deviation of Drift: $\sigma_{drift} = 0.042 \log(t) + 0.4118 [\mu S]$
  11. How analog layers and optimizers interact during training

    master

    In aihwkit, analog simulation is triggered through the interaction of analog-aware layers and specialized optimizers.

    When you define an AnalogLinear layer and an AnalogSGD optimizer, the following lifecycle occurs:

    1. Initialization:

      • AnalogLinear creates a FloatingPointTile (from the Python abstraction layer), which internally instantiates a FloatingPointTile from the Pybind layer, which finally creates the underlying C++ objects.
      • AnalogSGD inspects the AnalogLinear layer to identify which parameters require analog-specific handling during optimization.
    2. Forward and Backward Passes:

      • During the training loop, PyTorch calls aihwkit.nn.functions.AnalogFunction.
      • This function calls the forward() or backward() methods on the layer's FloatingPointTile.
      • These calls are delegated through the Pybind bindings down to the C++ methods.
    3. Optimization Step:

      • When opt.step() is called, AnalogSGD retrieves the reference to the FloatingPointTile and calls its update() function.
      • This call is delegated through the Pybind bindings to the C++ implementation to perform the update in the analog tile.
    model = AnalogLinear(2, 1)
    opt = AnalogSGD(model.parameters(), lr=0.5)
    ...
    
    for epoch in range(100):
        pred = model(x_b)
        loss = mse_loss(pred, y_b)
        loss.backward()
        opt.step()
  12. Use AnalogSequential to manage analog modules

    master

    When building complex models, standard PyTorch containers (like nn.Sequential) may not correctly propagate certain operations to the parameters and buffers of analog layers.

    To ensure operations like .cuda(), .eval(), or .program_analog_weights() are applied correctly to all children, use aihwkit.nn.AnalogSequential. This class acts as a compatible replacement for nn.Sequential and should be used as the superclass when defining custom analog modules.

    from aihwkit.nn import AnalogLinear, AnalogSequential
    
    # As a replacement for nn.Sequential
    model = AnalogSequential(
        AnalogLinear(10, 20)
    )
    model.cuda()
    model.eval()
    model.program_analog_weights()