From c80ca5b400e0b612c63c0abd2a74bff449e091bc Mon Sep 17 00:00:00 2001 From: Rahul Maurya <98907006+rahul-maurya11b@users.noreply.github.com> Date: Tue, 2 Apr 2024 15:13:50 +0530 Subject: [PATCH] CPU option in Docker file (#98) * 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 * 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 --- Dockerfile | 17 ++++++++---- environment_cpu.yml | 35 +++++++++++++++++++++++++ environment.yml => environment_cuda.yml | 4 ++- 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 environment_cpu.yml rename environment.yml => environment_cuda.yml (92%) diff --git a/Dockerfile b/Dockerfile index 3f58873a..82b493d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ @@ -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"] @@ -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"] diff --git a/environment_cpu.yml b/environment_cpu.yml new file mode 100644 index 00000000..db087fc2 --- /dev/null +++ b/environment_cpu.yml @@ -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 diff --git a/environment.yml b/environment_cuda.yml similarity index 92% rename from environment.yml rename to environment_cuda.yml index f2b6478a..9b9de3b4 100644 --- a/environment.yml +++ b/environment_cuda.yml @@ -11,7 +11,7 @@ dependencies: - pandas - pip - pyg - - python=3.11 + - python=3.12 - pytorch - pytorch-cluster - pytorch-scatter @@ -24,6 +24,7 @@ dependencies: - xarray - zarr - h3-py + - numpy - pip: - datasets - einops @@ -32,3 +33,4 @@ dependencies: - huggingface-hub - pysolar - pytorch-lightning + - click