Skip to content

ENH: migrate to runs-on GPU instance #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/runs-on.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ images:
quantecon_ubuntu2204_ami:
platform: "linux"
arch: "x64"
ami: "ami-0d4c683ae7bde17e9"
ami: "ami-0d4c683ae7bde17e9"
19 changes: 14 additions & 5 deletions .github/workflows/cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@ on:
workflow_dispatch:
jobs:
cache:
runs-on: quantecon-gpu
container:
image: ghcr.io/quantecon/lecture-python-container:cuda-12.8.1-anaconda-2024-10-py312
options: --gpus all
runs-on: "runs-on=${{ github.run_id }}/family=g4dn.2xlarge/image=ubuntu24-gpu-x64/disk=large"
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Check nvidia drivers
- name: Setup Anaconda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
auto-activate-base: true
miniconda-version: 'latest'
python-version: "3.12"
environment-file: environment.yml
activate-environment: quantecon
- name: Install jax (and install checks for GPU)
shell: bash -l {0}
run: |
pip install -U "jax[cuda12]"
python --version
python scripts/test-jax-install.py
nvidia-smi
- name: Build HTML
shell: bash -l {0}
Expand Down
90 changes: 47 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,64 @@ name: Build Project [using jupyter-book]
on: [pull_request]
jobs:
preview:
runs-on: quantecon-gpu
container:
image: ghcr.io/quantecon/lecture-python-container:cuda-12.8.1-anaconda-2024-10-py312
options: --gpus all
runs-on: "runs-on=${{ github.run_id }}/family=g4dn.2xlarge/image=quantecon_ubuntu2204_ami/disk=large"
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
# Check nvidia drivers
- name: nvidia Drivers
shell: bash -l {0}
- name: Setup QuantEcon Environment (/runner/)
run: |
export PATH=$PATH:/opt/anaconda3/bin/
conda env create -f environment.yml -y
conda init bash && source ~/.bashrc
conda activate quantecon
- name: Display nvidia
run: nvidia-smi
- name: Display Conda Environment Versions
shell: bash -l {0}
run: conda list
- name: Display Pip Versions
shell: bash -l {0}
run: pip list
- name: Download "build" folder (cache)
uses: dawidd6/action-download-artifact@v9
with:
workflow: cache.yml
branch: main
name: build-cache
path: _build
# Build Assets (Download Notebooks and PDF via LaTeX)
- name: Build Download Notebooks (sphinx-tojupyter)
shell: bash -l {0}
run: |
jb build lectures -n -W --keep-going --path-output ./ --builder=custom --custom-builder=jupyter
mkdir -p _build/html/_notebooks
cp -u _build/jupyter/*.ipynb _build/html/_notebooks
- name: Upload Execution Reports (Download Notebooks)
uses: actions/upload-artifact@v4
if: failure()
with:
name: execution-reports
path: _build/jupyter/reports
- name: Build PDF from LaTeX
shell: bash -l {0}
run: |
jb build lectures --builder pdflatex --path-output ./ -W --keep-going
mkdir -p _build/html/_pdf
cp -u _build/latex/*.pdf _build/html/_pdf
- name: Upload Execution Reports (LaTeX)
uses: actions/upload-artifact@v4
if: failure()
with:
name: execution-reports
path: _build/latex/reports
export PATH=$PATH:/opt/anaconda3/bin/
conda list
# - name: Display Pip Versions
# run: pip list
# - name: Download "build" folder (cache)
# uses: dawidd6/action-download-artifact@v9
# with:
# workflow: cache.yml
# branch: main
# name: build-cache
# path: _build
# Build Assets (Download Notebooks and PDF via LaTeX)
# - name: Build Download Notebooks (sphinx-tojupyter)
# shell: bash -l {0}
# run: |
# jb build lectures -n -W --keep-going --path-output ./ --builder=custom --custom-builder=jupyter
# mkdir -p _build/html/_notebooks
# cp -u _build/jupyter/*.ipynb _build/html/_notebooks
# - name: Upload Execution Reports (Download Notebooks)
# uses: actions/upload-artifact@v4
# if: failure()
# with:
# name: execution-reports
# path: _build/jupyter/reports
# - name: Build PDF from LaTeX
# shell: bash -l {0}
# run: |
# jb build lectures --builder pdflatex --path-output ./ -W --keep-going
# mkdir -p _build/html/_pdf
# cp -u _build/latex/*.pdf _build/html/_pdf
# - name: Upload Execution Reports (LaTeX)
# uses: actions/upload-artifact@v4
# if: failure()
# with:
# name: execution-reports
# path: _build/latex/reports
# Final Build of HTML
- name: Build HTML
shell: bash -l {0}
run: |
export PATH=$PATH:/opt/anaconda3/bin/
conda init bash && source ~/.bashrc
conda activate quantecon
jb build lectures --path-output ./ -n -W --keep-going
- name: Upload Execution Reports (HTML)
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/collab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build Project on Google Collab (Execution)
on: [pull_request]
jobs:
execution-checks:
runs-on: quantecon-gpu
runs-on: "runs-on=${{ github.run_id }}/family=g4dn.2xlarge/image=ubuntu24-gpu-x64/disk=large"
container:
image: docker://us-docker.pkg.dev/colab-images/public/runtime
options: --gpus all
Expand Down
36 changes: 28 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,40 @@ on:
jobs:
publish:
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
runs-on: quantecon-gpu
container:
image: ghcr.io/quantecon/lecture-python-container:cuda-12.8.1-anaconda-2024-10-py312
options: --gpus all
runs-on: "runs-on=${{ github.run_id }}/family=g4dn.2xlarge/image=ubuntu24-gpu-x64/disk=large"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Git (required to commit notebooks)
shell: bash -l {0}
run: apt-get install -y git
- name: Check nvidia drivers
- name: Setup Anaconda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
auto-activate-base: true
miniconda-version: 'latest'
python-version: "3.12"
environment-file: environment.yml
activate-environment: quantecon
- name: Install jax (and install checks for GPU)
shell: bash -l {0}
run: |
pip install -U "jax[cuda12]"
python --version
python scripts/test-jax-install.py
nvidia-smi
- name: Install latex dependencies
shell: bash -l {0}
run: |
sudo apt-get -qq update
sudo apt-get install -y \
texlive-latex-recommended \
texlive-latex-extra \
texlive-fonts-recommended \
texlive-fonts-extra \
texlive-xetex \
latexmk \
xindy \
dvipng \
cm-super
- name: Display Conda Environment Versions
shell: bash -l {0}
run: conda list
Expand Down
21 changes: 21 additions & 0 deletions scripts/test-jax-install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import jax
import jax.numpy as jnp

devices = jax.devices()
print(f"The available devices are: {devices}")

@jax.jit
def matrix_multiply(a, b):
return jnp.dot(a, b)

# Example usage:
key = jax.random.PRNGKey(0)
x = jax.random.normal(key, (1000, 1000))
y = jax.random.normal(key, (1000, 1000))
z = matrix_multiply(x, y)

# Now the function is JIT compiled and will likely run on GPU (if available)
print(z)

devices = jax.devices()
print(f"The available devices are: {devices}")