diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..4bd322f90e --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,27 @@ +{ + "name": "TorchServe Dev Environment", + "build": { + "dockerfile": "../docker/Dockerfile", + "context": "..", + "args": { + "BASE_IMAGE": "ubuntu:20.04", + "PYTHON_VERSION": "3.9", + "BRANCH_NAME": "master", + "REPO_URL": "https://github.com/pytorch/serve.git", + "CUDA_VERSION": "" + } + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python" + ] + } + }, + "runArgs": [ + // ACTION NEEDED: uncomment the next line if your local machine has GPUs available +// "--gpus", "all", + // Enable the docker container to access system resources + "--ipc", "host" + ] +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a25e754761..e863abb319 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -81,6 +81,10 @@ Refer to the documentation [here](docs/torchserve_on_win_native.md). For information about the model archiver, see [detailed documentation](model-archiver/README.md). +### Using Visual Studio Code Dev Containers + +You can also set up a development environment for TorchServe using Visual Studio Code Dev Containers. This approach provides a fully-isolated, Docker-based environment that simplifies setup and ensures consistency across different development machines. Follow the guide in the [Development Environment with VS Code Dev Containers](docker/README.md#development-environment-with-vs-code-dev-containers) section of the Docker README for setup instructions and customization options. + ### What to Contribute? ### A good first issue diff --git a/docker/README.md b/docker/README.md index beb0604e10..f22d2d8c41 100644 --- a/docker/README.md +++ b/docker/README.md @@ -12,6 +12,7 @@ TorchServe now enforces token authorization enabled and model API control disabl * [Create TorchServe docker image](#create-torchserve-docker-image) * [Create torch-model-archiver from container](#create-torch-model-archiver-from-container) * [Running TorchServe docker image in production](#running-torchserve-in-a-production-docker-environment) +* [Development Environment with VS Code Dev Containers](#development-environment-with-vs-code-dev-containers) # Prerequisites @@ -304,6 +305,54 @@ docker run --rm --shm-size=1g \ --mount type=bind,source=/path/to/model/store,target=/tmp/models torchserve --model-store=/tmp/models ``` +# Development Environment with VS Code Dev Containers + +This section provides a guide on setting up a development environment for TorchServe using Visual Studio Code Dev Containers. + +## Setup Instructions + +1. **Install the Dev Containers Extension** + In Visual Studio Code, search for "Dev Containers" in the Extensions marketplace and install it. + + ![Dev Containers Extension Installation](https://github.com/user-attachments/assets/16e1fd10-b20e-4ef4-a16f-0f544d233ba6) + +2. **Open in Container** + After installation, you will see a pop-up similar to the one in the screenshot. Click the "Reopen in Container" button to start the development environment inside a Docker container. + + ![Reopen in Container](https://github.com/user-attachments/assets/31c3c090-2808-4e55-8d2e-89d4ab40649f) + +## Customizing the Development Environment + +To use a GPU-based container or make other modifications, update the `.devcontainer/devcontainer.json` file. Here’s an example configuration for a GPU-enabled environment: + +```json +{ + "name": "TorchServe Dev Environment", + "build": { + "dockerfile": "../docker/Dockerfile", + "context": "..", + "args": { + "BASE_IMAGE": "nvidia/cuda:12.1.1-base-ubuntu20.04", + "PYTHON_VERSION": "3.9", + "BRANCH_NAME": "master", + "REPO_URL": "https://github.com/pytorch/serve.git", + "CUDA_VERSION": "cu121" + } + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python" + ] + } + }, + "runArgs": [ + "--gpus", "all", + "--ipc", "host" + ] +} +``` + # Example showing serving model using Docker container [This](../examples/image_classifier/mnist/Docker.md) is an example showing serving MNIST model using Docker.