Sign inSign up

phygrid/cuda-pytorch

By phygrid

โ€ขUpdated about 1 year ago

PyTorch base image for deep learning inference with GPU support and RTX 5090 optimizations

Image
0

1.6K

phygrid/cuda-pytorch repository overview

โ Phygrid CUDA PyTorch Image

Docker Hub Docker Image Version Build Status License

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.

โ ๐Ÿš€ Quick Start

# Pull the latest image
docker pull phygrid/cuda-pytorch:latest

# Use as base image in your Dockerfile
FROM phygrid/cuda-pytorch:1.0.0

โ ๐Ÿ“‹ What's Included

โ Base Layer

Built on phygrid/cuda-base:latest which includes:

  • Python 3.11 with optimized pip, setuptools, wheel
  • FastAPI, Uvicorn, Pydantic for web services
  • Common system dependencies and security features
โ PyTorch Ecosystem
  • PyTorch 2.8.0: Latest version with CUDA 12.8 support
  • Transformers: Hugging Face ecosystem (v4.36.2) with accelerate
  • Model Optimization: bitsandbytes, optimum for efficient inference
  • Hugging Face Hub: Model management and safetensors support
โ Computer Vision & Audio
  • Vision: OpenCV, torchvision for image processing
  • Audio: librosa, soundfile, torchaudio for audio processing
  • Scientific: scipy, scikit-learn, matplotlib, seaborn
โ RTX 5090 Optimizations
  • Memory Management: Optimized CUDA allocation settings
  • Architecture Support: CUDA compute capabilities 8.0-9.0
  • Environment Tuning: Pre-configured for high-end GPU performance

โ ๐Ÿณ Docker Hub

Repository: phygrid/cuda-pytorchโ 

โ Available Tags
  • latest - Latest stable release
  • 1.0.0, 1.0.1, etc. - Specific semantic versions
  • Multi-architecture support: linux/amd64, linux/arm64

โ ๐Ÿ“ฆ Usage Examples

โ As Base Image
FROM 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"]
โ Development Environment
# 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
โ Production Deployment
# 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
โ Hugging Face Model Inference
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)
โ Custom Training/Fine-tuning
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()

โ ๐Ÿ—๏ธ Building from Source

# 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 .

โ ๐Ÿ”„ Versioning

This project uses automated semantic versioning:

  • Automatic: Patch versions increment on main branch changes
  • Manual: Edit VERSION file for major/minor bumps
  • Tags: Git tags created automatically (e.g., v1.0.0)

โ ๐Ÿงช Health Check

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

โ โš™๏ธ Configuration

โ Environment Variables
VariableDefaultDescription
PYTORCH_CUDA_ALLOC_CONFmax_split_size_mb:128CUDA memory allocation
CUDA_LAUNCH_BLOCKING0Enable for debugging
TORCH_CUDA_ARCH_LIST8.0;8.6;8.9;9.0Supported compute capabilities
TRANSFORMERS_CACHE/app/cache/transformersHugging Face cache
HF_HOME/app/cache/huggingfaceHF Hub cache
TOKENIZERS_PARALLELISMtrueEnable tokenizer parallelism
โ Volume Mounts
PathPurpose
/app/pytorch_modelsPyTorch model storage
/app/cache/transformersHugging Face transformers cache
/app/cache/huggingfaceHugging Face Hub cache
/app/cache/torchPyTorch cache
/app/dataInput/output data
/app/logsApplication logs

โ ๐Ÿ”ง Performance Tuning

โ RTX 5090 Optimizations
# 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
โ Memory Management
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)
โ Model Loading Optimization
# Use memory mapping for large models
model = AutoModelForCausalLM.from_pretrained(
    "large-model",
    torch_dtype=torch.float16,
    device_map="auto",
    low_cpu_mem_usage=True
)

โ ๐Ÿค Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request
โ Development Setup
# 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

โ ๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSEโ  file for details.

โ ๐Ÿท๏ธ Labels

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"

โ ๐Ÿ†˜ Support

โ ๐Ÿ“ˆ Metrics

  • Image size: ~4.5GB compressed
  • Build time: ~15-25 minutes (with cache)
  • Architectures: AMD64, ARM64
  • PyTorch version: 2.8.0
  • CUDA support: 12.8
  • Base image: phygrid/cuda-base:latest

โ ๐ŸŽฏ Use Cases

  • Large Language Models: Run and fine-tune LLMs with Hugging Face
  • Computer Vision: Image classification, object detection, segmentation
  • Audio Processing: Speech recognition, audio generation
  • Research: Rapid prototyping with pre-installed ML stack
  • Production: High-performance inference services

Tag summary

Content type

Image

Digest

sha256:efaa15a61โ€ฆ

Size

4.6 GB

Last updated

about 1 year ago

docker pull phygrid/cuda-pytorch