AlphaChip: An open-source framework for generating chip floorplans with distributed deep reinforcement learning.
For my own usage, here is a tutorial for how to get the smoke-test running that should work for almost everyone, however I'm using an m3 macbook air.
Casual technical presentation on model architecture: https://www.canva.com/design/DAGjvjNkv3Q/IsjFnwWxU_1YI2Y3RQzgcQ/edit?utm_content=DAGjvjNkv3Q&utm_campaign=designshare&utm_medium=link2&utm_source=sharebutton
--
This document outlines the steps to set up and run the circuit_training smoke test on a cloud GPU instance (initially a Lambda Labs A100). It also provides instructions for quickly restarting the environment on a new instance. The goal is to verify the environment and core functionality using a personal fork named DeepRune.
- A GitHub account
- An SSH client (e.g., Terminal on macOS/Linux, PuTTY on Windows)
- Access to a GPU cloud instance provider (e.g., Lambda Labs, RunPod)
- Docker Hub account (Optional, but recommended for saving built images)
- Basic familiarity with the command line
These steps detail the process for the first remote cloud instance via SSH.
Connect to your provisioned cloud instance using SSH:
ssh user@<instance_ip_address> -p <port_if_needed>
Verify Docker is installed and working:
docker run hello-world
Clone a personal fork to allow for modifications and pull requests:
# Install git if necessary
# sudo apt update && sudo apt install git -y
# Clone your fork
git clone https://github.com/WillForEternity/DeepRune.git DeepRune
# Navigate into the cloned directory
cd DeepRune
# Add the original repository as 'upstream'
git remote add upstream https://github.com/google-research/circuit_training.git
# Fetch the stable tag/branch (r0.0.4)
git fetch upstream r0.0.4:r0.0.4
# Checkout the fetched stable branch
git checkout r0.0.4
Define environment variables needed for the Docker build process:
# Version of Circuit Training being used
export CT_VERSION=0.0.4
# Python version used in the stable Dockerfile
export PYTHON_VERSION=python3.9
# Specific DREAMPlace binary pattern
export DREAMPLACE_PATTERN=dreamplace_20231214_c5a83e5_${PYTHON_VERSION}.tar.gz
# Specific TF-Agents version compatible with CT v0.0.4
export TF_AGENTS_PIP_VERSION=tf-agents[reverb]~=0.19.0
# Path to the repository root
export REPO_ROOT=$(pwd)
# Base CUDA image
export GPU_BASE_IMAGE=nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
Two Docker images need to be built:
# Build the CORE (CPU) image
docker build --pull --no-cache --tag circuit_training:core \
--build-arg tf_agents_version="${TF_AGENTS_PIP_VERSION}" \
--build-arg dreamplace_version="${DREAMPLACE_PATTERN}" \
--build-arg placement_cost_binary="plc_wrapper_main_${CT_VERSION}" \
-f "${REPO_ROOT}"/tools/docker/ubuntu_circuit_training ${REPO_ROOT}/tools/docker/
# Build the GPU image
docker build --pull --no-cache --tag circuit_training:gpu \
--build-arg base_image=${GPU_BASE_IMAGE} \
--build-arg tf_agents_version="${TF_AGENTS_PIP_VERSION}" \
--build-arg dreamplace_version="${DREAMPLACE_PATTERN}" \
--build-arg placement_cost_binary="plc_wrapper_main_${CT_VERSION}" \
-f "${REPO_ROOT}"/tools/docker/ubuntu_circuit_training ${REPO_ROOT}/tools/docker/
Save the built images for reuse:
# Login to Docker Hub
docker login
# Tag the images with your Docker Hub username
docker tag circuit_training:core yourdockerhubusername/deeprune:core-v0.0.4
docker tag circuit_training:gpu yourdockerhubusername/deeprune:gpu-v0.0.4
# Example used:
# docker tag circuit_training:core willforeternity/circuit_training:core-v0.0.4
# docker tag circuit_training:gpu willforeternity/circuit_training:gpu-v0.0.4
# Push the images
docker push yourdockerhubusername/deeprune:core-v0.0.4
docker push yourdockerhubusername/deeprune:gpu-v0.0.4
# Example used:
# docker push willforeternity/circuit_training:core-v0.0.4
# docker push willforeternity/circuit_training:gpu-v0.0.4
Replace yourdockerhubusername/deeprune with your Docker Hub repository name.
Verify the core training loop using the built Docker environment:
# Ensure you are in the DeepRune directory
cd ~/DeepRune
# Create the logs directory
mkdir -p ${REPO_ROOT}/logs
# Execute the Smoke Test Script inside the GPU container
docker run \
--rm \
--gpus all \
-v ${REPO_ROOT}:/workspace \
--workdir /workspace \
circuit_training:gpu \
bash tools/e2e_smoke_test.sh --root_dir /workspace/logs
The smoke test should complete in approximately 14 minutes without errors, confirming the setup works.
To stop incurring charges and save the state for a quick restart:
- Backup Data (Optional): Download any critical generated data from the instance
- Stop Running Containers:
docker stop $(docker ps -q)
- Terminate Instance: Use your cloud provider's dashboard to terminate the instance
These steps allow you to quickly get the environment running again on a newly launched cloud instance:
- Provision a new GPU instance from your chosen provider
- Select an OS image that includes Docker and appropriate NVIDIA drivers/CUDA toolkit
ssh user@<new_instance_ip_address>
# Check if git is installed
git --version
# If not installed
sudo apt update && sudo apt install git -y
git clone https://github.com/WillForEternity/DeepRune.git DeepRune
cd DeepRune
# Optional: Checkout a specific branch/tag if needed
# git checkout r0.0.4
# Login to Docker Hub
docker login
# Pull the GPU image
docker pull yourdockerhubusername/deeprune:gpu-v0.0.4
# Example: docker pull willforeternity/circuit_training:gpu-v0.0.4
# Pull the CPU image if needed
docker pull yourdockerhubusername/deeprune:core-v0.0.4
# Example: docker pull willforeternity/circuit_training:core-v0.0.4
docker tag yourdockerhubusername/deeprune:gpu-v0.0.4 circuit_training:gpu
docker tag yourdockerhubusername/deeprune:core-v0.0.4 circuit_training:core
# Example:
# docker tag willforeternity/circuit_training:gpu-v0.0.4 circuit_training:gpu
# docker tag willforeternity/circuit_training:core-v0.0.4 circuit_training:core
# Ensure you are in the ~/DeepRune directory
export REPO_ROOT=$(pwd)
# Set any other runtime variables needed
Verify by re-running the smoke test:
mkdir -p ${REPO_ROOT}/logs
docker run --rm --gpus all -v ${REPO_ROOT}:/workspace --workdir /workspace circuit_training:gpu \
bash tools/e2e_smoke_test.sh --root_dir /workspace/logs
This restart process should only take a few minutes (dominated by instance boot time and image pulling) compared to the initial setup involving lengthy Docker builds.
AlphaChip is an open-source framework for generating chip floorplans with distributed deep reinforcement learning. This framework reproduces the methodology published in the Nature 2021 paper:
A graph placement methodology for fast chip design. Azalia Mirhoseini, Anna Goldie, Mustafa Yazgan, Joe Wenjie Jiang, Ebrahim Songhori, Shen Wang, Young-Joon Lee, Eric Johnson, Omkar Pathak, Azade Nazi, Jiwoo Pak, Andy Tong, Kavya Srinivasa, William Hang, Emre Tuncer, Quoc V. Le, James Laudon, Richard Ho, Roger Carpenter & Jeff Dean, 2021. Nature, 594(7862), pp.207-212. [PDF]
AlphaChip--one of the first reinforcement learning approaches used to solve a real-world engineering problem--has led to a proliferation of research in AI for chips over the past few years. It is now used to design layouts for chips across Alphabet and outside, and has been extended to various stages of the design process, including logic synthesis, macro selection, timing optimization, and more! We hope that researchers will continue building on top of AlphaChip methodologies and open-source framework. Please see our blogpost for more information.
AlphaChip is built on top of TF-Agents and TensorFlow 2.x with support for eager execution, distributed training across multiple GPUs, and distributed data collection scaling to 100s of actors.
Features
Installation
Quick start
Testing
Releases
Pre-Trained Model Checkpoint
How to use the checkpoint
Results
FAQ
How to contribute
AI Principles
Contributors
How to cite
Disclaimer
- Places netlists with hundreds of macros and millions of stdcells (in clustered format).
- Computes both macro location and orientation (flipping).
- Optimizes multiple objectives including wirelength, congestion, and density.
- Supports alignment of blocks to the grid, to model clock strap or macro blockage.
- Supports macro-to-macro, macro-to-boundary spacing constraints.
- Supports fixed macros.
- Supports DREAMPlace as the stdcell placer.
- Allows users to specify their own technology parameters, e.g. and routing resources (in routes per micron) and macro routing allocation.
- Generates clustered netlists.
- TILOS-AI-Institute has created a script to convert LEF/DEF and Bookshelf to the Netlist Protocol Buffer used as the input for AlphaChip.
⚠️ AlphaChip only supports Linux based OSes.
⚠️ AlphaChip requires Python 3.9 or greater.
AlphaChip is a research project. We are not currently creating PyPi builds. Stable in this instance is relative to HEAD and means that the code was tested at this point in time and branched. With upstream libraires constantly changing; older branches may end up rotting faster than expected.
The steps below install the most recent branch and the archive is in the releases section. There are two methods for installing; but before doing either one you need to run the preliminary setup](#preliminary-setup).
- Use the docker (Highly Recommended)
- Install locally
Before following the instructions set the following variables and clone the repo:
$ export CT_VERSION=0.0.4
# Currently supports python3.9, python3.10, and python3.11
# The docker is python3.9 only.
$ export PYTHON_VERSION=python3.9
$ export DREAMPLACE_PATTERN=dreamplace_20231214_c5a83e5_${PYTHON_VERSION}.tar.gz
# If the verson of TF-Agents in the table is not current, change this command to
# match the version tf-agenst that matches the branch of AlphaChip used.
$ export TF_AGENTS_PIP_VERSION=tf-agents[reverb]
# Clone the Repo and checkout the desired branch.
$ git clone https://github.com/google-research/circuit_training.git
$ git -C $(pwd)/circuit_training checkout r${CT_VERSION}
Do not forget to do the prelimary setup. The cleanest way to use AlphaChip is to use the docker, these commands will create a docker with all the dependencies needed:
$ export REPO_ROOT=$(pwd)/circuit_training
# Build the docker image.
$ docker build --pull --no-cache --tag circuit_training:core \
--build-arg tf_agents_version="${TF_AGENTS_PIP_VERSION}" \
--build-arg dreamplace_version="${DREAMPLACE_PATTERN}" \
--build-arg placement_cost_binary="plc_wrapper_main_${CT_VERSION}" \
-f "${REPO_ROOT}"/tools/docker/ubuntu_circuit_training ${REPO_ROOT}/tools/docker/
# Run the end2end smoke test using the image. Takes 10-20 minutes.
$ mkdir -p ${REPO_ROOT}/logs
$ docker run --rm -v ${REPO_ROOT}:/workspace --workdir /workspace circuit_training:core \
bash tools/e2e_smoke_test.sh --root_dir /workspace/logs
Do not forget to do the prelimary setup.
AlphaChip installation steps:
- Install our DREAMPlace binary.
- Install TF-Agents and The Placement Cost Binary
- Run a test
Follow the instructions for DREAMPlace but do not change the ENV VARS that you already exported previously.
These commands install TF-Agents and the placement cost binary.
# Installs TF-Agents with stable versions of Reverb and TensorFlow 2.x.
$ pip install $TF_AGENTS_PIP_VERSION
$ pip install tf-keras
# Using keras-2
$ export TF_USE_LEGACY_KERAS=1
# Copies the placement cost binary to /usr/local/bin and makes it executable.
$ sudo curl https://storage.googleapis.com/rl-infra-public/circuit-training/placement_cost/plc_wrapper_main_${CT_VERSION} \
-o /usr/local/bin/plc_wrapper_main
$ sudo chmod 555 /usr/local/bin/plc_wrapper_main
These commands run a basic unit test; if the current stable tf-agents is not the
version you installed, then edit the tox.ini file and change tf-agents[reverb]
to tf-agents[reverb]~=<version you want>
tox -e py39-stable -- circuit_training/grouping/grouping_test.py