PyTorch base image for deep learning inference with GPU support and RTX 5090 optimizations
1.6K
A multi-architecture Docker image optimized for PyTorch deep learning inference with GPU acceleration, built on the Phygrid CUDA base image and featuring RTX 5090 optimizations.
# Pull the latest image
docker pull phygrid/cuda-pytorch:latest
# Use as base image in your Dockerfile
FROM phygrid/cuda-pytorch:1.0.0
Built on phygrid/cuda-base:latest which includes:
Repository: phygrid/cuda-pytorchโ
latest - Latest stable release1.0.0, 1.0.1, etc. - Specific semantic versionslinux/amd64, linux/arm64FROM phygrid/cuda-pytorch:1.0.0
# Copy your models and code
COPY models/ /app/pytorch_models/
COPY src/ /app/src/
# Install additional dependencies
RUN pip install -r requirements.txt
# Override default command
CMD ["python", "inference_server.py"]
# Run interactive container with GPU support
docker run -it --rm \
--gpus all \
-v $(pwd):/app/workspace \
-v $(pwd)/models:/app/pytorch_models \
-v ~/.cache/huggingface:/app/cache/huggingface \
-p 8000:8000 \
phygrid/cuda-pytorch:latest \
bash
# Run PyTorch inference service
docker run -d \
--name pytorch-inference \
--gpus all \
-p 8000:8000 \
-v /data/models:/app/pytorch_models \
-v /data/cache:/app/cache \
-e PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512 \
phygrid/cuda-pytorch:latest
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load model with GPU support
model_name = "microsoft/DialoGPT-medium"
tokenizer = AutoTokenizer.from_pretrained(model_name, cache_dir="/app/cache/transformers")
model = AutoModelForCausalLM.from_pretrained(model_name, cache_dir="/app/cache/transformers")
# Move to GPU if available
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
# Inference example
inputs = tokenizer.encode("Hello, how are you?", return_tensors="pt").to(device)
outputs = model.generate(inputs, max_length=50, num_return_sequences=1)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
import torch
import torch.nn as nn
from torch.utils.data import DataLoader
# Configure for RTX 5090
torch.backends.cudnn.benchmark = True
torch.backends.cuda.matmul.allow_tf32 = True
# Your training code here
model = nn.Sequential(...)
optimizer = torch.optim.AdamW(model.parameters())
# Enable mixed precision training
scaler = torch.cuda.amp.GradScaler()
# Clone repository
git clone https://github.com/phygrid/cuda-pytorch.git
cd cuda-pytorch
# Build image
docker build -t phygrid/cuda-pytorch:custom .
# Build for multiple architectures
docker buildx build --platform linux/amd64,linux/arm64 -t phygrid/cuda-pytorch:custom .
This project uses automated semantic versioning:
VERSION file for major/minor bumpsv1.0.0)The image includes a comprehensive health check:
# Test PyTorch setup
docker run --rm phygrid/cuda-pytorch:latest python /app/pytorch_test.py
# Expected output (with GPU):
# PyTorch version: 2.8.0
# Transformers version: 4.36.2
# โ
CUDA available: NVIDIA GeForce RTX 5090
# CUDA version: 12.8
# GPU memory: 32.0 GB
# โ
Basic tensor operations: OK
# PyTorch setup: OK
| Variable | Default | Description |
|---|---|---|
PYTORCH_CUDA_ALLOC_CONF | max_split_size_mb:128 | CUDA memory allocation |
CUDA_LAUNCH_BLOCKING | 0 | Enable for debugging |
TORCH_CUDA_ARCH_LIST | 8.0;8.6;8.9;9.0 | Supported compute capabilities |
TRANSFORMERS_CACHE | /app/cache/transformers | Hugging Face cache |
HF_HOME | /app/cache/huggingface | HF Hub cache |
TOKENIZERS_PARALLELISM | true | Enable tokenizer parallelism |
| Path | Purpose |
|---|---|
/app/pytorch_models | PyTorch model storage |
/app/cache/transformers | Hugging Face transformers cache |
/app/cache/huggingface | Hugging Face Hub cache |
/app/cache/torch | PyTorch cache |
/app/data | Input/output data |
/app/logs | Application logs |
# Enable optimal memory allocation
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512
# Enable TensorFloat-32 for faster training
export TORCH_ALLOW_TF32_CUBLAS_OVERRIDE=1
# Configure for maximum performance
export CUDA_LAUNCH_BLOCKING=0
import torch
# Clear cache periodically
torch.cuda.empty_cache()
# Use gradient checkpointing for large models
model.gradient_checkpointing_enable()
# Enable mixed precision
with torch.cuda.amp.autocast():
outputs = model(inputs)
# Use memory mapping for large models
model = AutoModelForCausalLM.from_pretrained(
"large-model",
torch_dtype=torch.float16,
device_map="auto",
low_cpu_mem_usage=True
)
We welcome contributions! Please:
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)# Clone and setup
git clone https://github.com/phygrid/cuda-pytorch.git
cd cuda-pytorch
# Test build locally
docker build -t phygrid/cuda-pytorch:test .
docker run --rm --gpus all phygrid/cuda-pytorch:test python /app/pytorch_test.py
This project is licensed under the MIT License - see the LICENSEโ file for details.
The image includes standard OCI labels:
LABEL org.opencontainers.image.title="Phygrid CUDA PyTorch"
LABEL org.opencontainers.image.description="PyTorch base image for deep learning inference with GPU support"
LABEL org.opencontainers.image.vendor="Phygrid"
LABEL inference.engine="pytorch"
LABEL inference.runtime="pytorch-2.8.0"
LABEL cuda.version="12.8"
Content type
Image
Digest
sha256:efaa15a61โฆ
Size
4.6 GB
Last updated
about 1 year ago
docker pull phygrid/cuda-pytorch