docker-pytorch

Docker | PyTorch

https://github.com/scape-agency/docker-pytorch

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.1%) to scientific vocabulary

Keywords

docker python pytorch scape-agency scapeagency
Last synced: 9 months ago · JSON representation ·

Repository

Docker | PyTorch

Basic Info
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • Open Issues: 1
  • Releases: 0
Topics
docker python pytorch scape-agency scapeagency
Created almost 2 years ago · Last pushed over 1 year ago
Metadata Files
Readme Contributing Funding License Code of conduct Citation Codeowners Security Authors

README.md

Docker | PyTorch

When setting up a Docker image for PyTorch that supports both CPU and GPU, you'll need to include the necessary dependencies and configurations for both processing types. Here’s a basic setup you can use to create a Docker image that supports PyTorch on both CPU and GPU:

  1. Base Image: Start with an official PyTorch image from the NVIDIA container repository, which comes with CUDA and cuDNN pre-installed, ensuring GPU support.

  2. Requirements: Install any additional packages you need for your specific project.

  3. Environment: Set up the correct environment variables and ensure that the container can dynamically switch between CPU and GPU based on the available hardware.

Here is a simple example of a Dockerfile:

```dockerfile

Use an official PyTorch image as a parent image

FROM pytorch/pytorch:1.12.0-cuda11.3-cudnn8-runtime

Install any needed packages specified in requirements.txt

COPY requirements.txt /tmp/ RUN pip install --requirement /tmp/requirements.txt

Run the application

CMD ["python", "./src/my_script.py"] ```

Key Notes:

  • PyTorch Version: Replace 1.12.0-cuda11.3-cudnn8-runtime with the version of PyTorch that matches your requirements.
  • CUDA/cuDNN: The CUDA and cuDNN versions need to match the ones required by the specific PyTorch version.
  • requirements.txt: This file should contain all the Python packages you need. Copy this into your Docker image and install them.

To build and run the Docker container:

  • Build the Image: docker build -t my-pytorch-app .
  • Run the Container:
    • On CPU: docker run my-pytorch-app
    • On GPU: docker run --gpus all my-pytorch-app

This setup ensures that your Docker container can utilize GPU resources when available, falling back to CPU when GPUs are not accessibl


To set up a Docker image based on Ubuntu for PyTorch that supports both CPU and GPU usage, you'll start with an Ubuntu base image and manually install the necessary components like Python, PyTorch, CUDA, and cuDNN. This approach gives you more control over the versions and the setup.

Here’s a detailed Dockerfile to achieve this:

```dockerfile

Use an Ubuntu base image

FROM ubuntu:20.04

Avoid prompts during package installation

ARG DEBIAN_FRONTEND=noninteractive

Install basic utilities

RUN apt-get update && apt-get install -y \ wget \ curl \ git \ python3-pip \ python3-dev \ build-essential

Link python3 to python

RUN ln -s /usr/bin/python3 /usr/bin/python

Upgrade pip

RUN pip3 install --upgrade pip

Install PyTorch with CUDA support

RUN pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113

Copy the requirements file and install Python dependencies

COPY requirements.txt /tmp/ RUN pip3 install -r /tmp/requirements.txt

Set the working directory

WORKDIR /app

Copy the rest of your application's code

COPY . /app

Command to run on container start

CMD ["python", "app.py"] ```

Explanation:

  1. Base Image: Starts with Ubuntu 20.04.
  2. Utilities: Installs essential packages like wget, curl, git, and Python-related tools.
  3. Python Link: Makes python command available by linking python3 to python.
  4. Python and PyTorch: Installs Python packages and PyTorch with CUDA 11.3 support.
  5. Requirements: Installs additional Python dependencies from a requirements.txt file.
  6. Working Directory and Application Code: Sets the working directory and copies your application code into the image.

Building and Running the Docker Container:

  • Build the Image: docker build -t my-pytorch-app .
  • Run the Container:
    • On CPU: docker run my-pytorch-app
    • On GPU: docker run --gpus all my-pytorch-app

This Dockerfile ensures that the application can utilize GPU acceleration when available, and will work on CPUs otherwise. Adjust the CUDA version in the PyTorch installation command according to the CUDA version compatible with your GPU drivers.

Owner

  • Name: Scape Agency
  • Login: scape-agency
  • Kind: organization
  • Email: info@scape.agency
  • Location: Amsterdam, Netherlands

Future Horizons into View Today

Citation (CITATION.cff)

cff-version: 1.2.0
title: Scape Agency - Docker Images - PyTorch
version: 0.0.1
date-released: 2024-07-01
url: "https://github.com/scape-agency/docker-pytorch"
message: >-
  If you use this software, please cite it using
  the metadata from this file.
type: software
authors:
  - given-names: Lars Bastiaan
    family-names: van Vianen
    email: lars@scape.agency
    affiliation: Scape Agency
    orcid: 'https://orcid.org/0000-0002-8790-8630'

GitHub Events

Total
  • Push event: 2
Last Year
  • Push event: 2

Dependencies

.github/workflows/docker_publish.yml actions
  • actions/checkout v3 composite
  • docker/bake-action v2 composite
  • docker/login-action v2 composite
  • docker/metadata-action v4 composite
  • docker/setup-buildx-action v2 composite
  • docker/setup-qemu-action v2 composite
.devcontainer/Dockerfile docker
  • ubuntu 24.04 build
.devcontainer/docker-compose.yml docker
bin/docker-compose.yml docker
src/.devcontainer/Dockerfile docker
  • scapeagency/swing-devcontainer latest build
src/.devcontainer/docker-compose.yml docker
src/pytorch/Dockerfile docker
  • ubuntu 20.04 build
src/pytorch/etc/pyproject.toml pypi
  • pytest ^6.2 develop
  • matplotlib ^3.4
  • numpy ^1.21
  • pandas ^1.3
  • python ^3.8
  • torch *
  • torchaudio *
  • torchvision *
src/pytorch/etc/requirements.txt pypi