This repository provides a flexible and scalable template for deep learning model training using PyTorch. It is designed for seamless setup and deployment using Docker, Docker Compose, and Visual Studio Code's DevContainer, making it an ideal starting point for machine learning engineers, data scientists, and AI researchers.
pytorch_template/
├── .gitignore
├── docker-compose.yaml
├── main.py
├── README.md
├── requirements.txt
├── start_jupyter.sh
├── .devcontainer/
│ ├── devcontainer.json
│ └── docker-compose.yml
├── docker/
│ ├── container.py
│ └── Dockerfile
├── experiments/
│ └── exp1.yaml
├── scripts/
│ ├── download_data.sh
│ ├── start_tensorboard.sh
│ └── start_training.sh
└── src/
└── __init__.py
- Docker and Docker Compose for isolated, reproducible training environments
- Visual Studio Code DevContainer support for seamless development
- Easy-to-use scripts for data preparation, training, and experiment tracking
- YAML-based experiment configuration for flexibility and reproducibility
- Python-based container management with
docker/container.py
-
VS Code Extensions:
- Remote - Containers
- Python
-
Clone the Repository
git clone https://github.com/bfortuno/Pytorch-DL-Template.git cd pytorch_template -
Build Docker Image
docker-compose build
-
Launch DevContainer (optional, for VS Code users)
- Open the repository in VS Code
- Use the
Remote - Containersextension to reopen the folder in the container
The .devcontainer/ directory provides pre-configured settings for developing inside a Docker container using VS Code. This setup ensures a consistent development environment across different systems, including:
- Environment Configuration (
devcontainer.json): Specifies the base image, extensions, and workspace settings for the container. - Docker Compose Integration (
docker-compose.yml): Links the VS Code workspace to the services defined in your Docker Compose file, ensuring the code and data are accessible within the container.
Key Features:
- Simplified development environment setup
- Consistent dependency management
- Integrated terminal and debugger
Example Workflow:
- Open the repository in VS Code.
- Reopen the folder in the container (Command Palette:
Remote-Containers: Reopen in Container). - Use the integrated terminal for running training scripts, starting Jupyter notebooks, or debugging.
Ensure that the Docker Compose service names match those used in docker-compose.yml to avoid connection issues.
-
Install Python Dependencies (if running locally without Docker)
pip install -r requirements.txt
./start_jupyter.sh./scripts/start_training.sh./scripts/start_tensorboard.shThe docker/container.py script provides a simple command-line interface for managing your Docker Compose environment. It supports the following commands:
Start Container (start)
- Starts the Docker Compose environment in detached mode.
./docker/container.py startEquivalent to:
docker compose up -dEnter Container (enter)
- Opens an interactive shell session inside the specified service container (default:
ai).
./docker/container.py enter --service aiEquivalent to:
docker compose exec ai bashStop Container (stop)
- Stops and removes the running Docker Compose environment.
./docker/container.py stopEquivalent to:
docker compose downThe script uses the subprocess.run() method with check=True to ensure that errors in the underlying Docker commands result in immediate termination, providing clear error messages if a command fails.
Ensure to adjust the container name and settings in the Dockerfile and docker-compose.yml for your specific project needs.
- Add new datasets to the
data/directory (create this folder if missing) - Update
experiments/exp1.yamlfor new training configurations - Extend the
src/directory for custom models, data loaders, or utilities
- Container Build Fails: Check for missing dependencies in
requirements.txt - DevContainer Not Starting: Verify Docker and Docker Compose are correctly installed
- Port Conflicts: Modify exposed ports in
docker-compose.yml
Feel free to open issues or submit pull requests for improvements. Ensure your code is well-documented and follows the project's style.
This project is licensed under the MIT License. See the LICENSE file for details.
- Add support for distributed training
- Integrate MLFlow for experiment tracking
- Include automated testing for better reliability
For questions or support, feel free to reach out via GitHub issues or discussions.