Setting Up Pruna in a Docker Container

This tutorial will guide you through the process of setting up pruna in a docker container.

Prerequisites

This tutorial assumes that you have Docker installed on your system. If you don’t, please follow the instructions on the [Docker website](https://docs.docker.com/engine/installation/).

We also assume that if you want to use the gpu version of pruna, you have cuda installed on your system and it is visible to Docker. If you don’t, please follow the instructions on the [Nvidia website](https://developer.nvidia.com/cuda-downloads).

Building the docker image

First you need to build the following DockerFile:

# Start with a base image that includes Conda
FROM continuumio/miniconda3

# Install basic utilities
RUN apt-get update --fix-missing && \
    apt-get install -y wget bzip2 ca-certificates curl git && \
    apt-get clean

# Create the Conda environment
RUN conda create -n pruna python=3.9
SHELL ["conda", "run", "-n", "pruna", "/bin/bash", "-c"]

# Install CUDA Toolkit
RUN conda install -c nvidia/label/cuda-12.1.0 cuda

# Install PyTorch
RUN pip install torch packaging polygraphy platformdirs

RUN apt-get update && apt-get install -y  g++

For the gpu version, or

# Start with a base image that includes Conda
FROM continuumio/miniconda3

# Install basic utilities
RUN apt-get update --fix-missing && \
    apt-get install -y wget bzip2 ca-certificates curl git && \
    apt-get clean

# Create the Conda environment
RUN conda create -n pruna python=3.9
SHELL ["conda", "run", "-n", "pruna", "/bin/bash", "-c"]

RUN apt-get update && apt-get install -y  g++

For the cpu version.

Using the following command:

docker build -t pruna .

Running the docker image

To run the docker image in interactive mode, use the following command:

docker run -it --gpus all pruna

This will start a bash shell in the docker container.

Installing Pruna in the Docker container

Once you are in the docker container, you can install pruna using the following command:

pip install pruna[gpu] --extra-index-url https://pypi.nvidia.com --extra-index-url https://pypi.ngc.nvidia.com

for the gpu version, or

pip install pruna

for the cpu version.

Wrap up

You are now ready to use pruna in the docker container.