Skip to content

Commit

Permalink
CPU option in Docker file (#98)
Browse files Browse the repository at this point in the history
* CPU option in Docker

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* updated docker

* Update environment_cpu.yml

Co-authored-by: Jacob Bieker <[email protected]>

* Update environment_cuda.yml

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jacob Bieker <[email protected]>
  • Loading branch information
3 people authored Apr 2, 2024
1 parent 084c5ab commit c80ca5b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
17 changes: 12 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
FROM ubuntu:latest


ENV CONDA_ENV_NAME=graph
ENV PYTHON_VERSION=3.10

ENV PYTHON_VERSION=3.12

# Basic setup
RUN apt update && apt install -y bash \
Expand All @@ -24,7 +22,15 @@ ENV PATH="/conda/bin:${PATH}"

RUN git clone https://github.com/openclimatefix/graph_weather.git && mv graph_weather/ gw/ && cd gw/ && mv * .. && rm -rf gw/

RUN conda update -n base -c defaults conda && conda env create -f environment.yml
# Copy the appropriate environment file based on CUDA availability
COPY environment_cpu.yml /tmp/environment_cpu.yml
COPY environment_cuda.yml /tmp/environment_cuda.yml

RUN conda update -n base -c defaults conda

# Check if CUDA is available and accordingly choose env
RUN cuda=$(command -v nvcc > /dev/null && echo "true" || echo "false") \
&& if [ "$cuda" == "true" ]; then conda env create -f /tmp/environment_cuda.yml; else conda env create -f /tmp/environment_cpu.yml; fi

# Switch to bash shell
SHELL ["/bin/bash", "-c"]
Expand All @@ -35,8 +41,9 @@ RUN echo "source activate ${CONDA_ENV_NAME}" >> ~/.bashrc
# Cp in the development directory and install
RUN source activate ${CONDA_ENV_NAME} && pip install -e .


# Make RUN commands use the new environment:
SHELL ["conda", "run", "-n", "graph", "/bin/bash", "-c"]

# Example commnad that can be used, need to set API_KEY, API_SECRET and SAVE_DIR
# Example command that can be used, need to set API_KEY, API_SECRET and SAVE_DIR
CMD ["conda", "run", "-n", "graph", "python", "-u", "train/pl_graph_weather.py", "--gpus", "16", "--hidden", "64", "--num-blocks", "3", "--batch", "16"]
35 changes: 35 additions & 0 deletions environment_cpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: graph
channels:
- pytorch
- pyg
- conda-forge
- defaults
dependencies:
- numcodecs
- pandas
- pip
- pyg
- python=3.12
- pytorch
- cpuonly
- pytorch-cluster
- pytorch-scatter
- pytorch-sparse
- pytorch-spline-conv
- scikit-learn
- scipy
- torchvision
- tqdm
- xarray
- zarr
- h3-py
- numpy
- pip:
- datasets
- einops
- fsspec
- torch-geometric-temporal
- huggingface-hub
- pysolar
- pytorch-lightning
- click
4 changes: 3 additions & 1 deletion environment.yml → environment_cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- pandas
- pip
- pyg
- python=3.11
- python=3.12
- pytorch
- pytorch-cluster
- pytorch-scatter
Expand All @@ -24,6 +24,7 @@ dependencies:
- xarray
- zarr
- h3-py
- numpy
- pip:
- datasets
- einops
Expand All @@ -32,3 +33,4 @@ dependencies:
- huggingface-hub
- pysolar
- pytorch-lightning
- click

0 comments on commit c80ca5b

Please sign in to comment.