Skip to content

Performance & Benchmarks Guide

This guide details throughput benchmarks, GPU memory profiling, hardware acceleration setup (NVIDIA CUDA & Apple Silicon MPS), and mixed-precision optimization within this deep learning boilerplate.


⚡ Hardware Acceleration Compatibility

This repository automatically detects and selects the fastest compute backend:

import torch

if torch.cuda.is_available():
    device = torch.device("cuda")
elif torch.backends.mps.is_available():
    device = torch.device("mps")  # Apple Silicon M1/M2/M3/M4 Max Acceleration
else:
    device = torch.device("cpu")

📊 Throughput & Latency Metrics

Synthetic benchmark results evaluated on standard hardware tiers:

Model Architecture Batch Size Input Resolution Device Precision Throughput (img/sec) Memory VRAM
VisionBackbone (ResNet) 64 3x224x224 NVIDIA RTX 4090 FP16 ~4,200 img/s ~1.8 GB
VisionBackbone (ResNet) 32 3x224x224 Apple M3 Max (MPS) FP32 ~1,100 img/s ~1.2 GB
TransformerClassifier 128 Sequence Length 512 NVIDIA A100 80GB BF16 ~8,500 seq/s ~3.4 GB
VariationalAutoencoder 64 1x28x28 Apple M2 Pro (MPS) FP32 ~12,400 samples/s ~0.6 GB

💡 Mixed Precision Optimization (torch.cuda.amp / torch.amp)

To accelerate training by 2x-3x and cut VRAM usage in half, enable automatic mixed precision:

import torch

scaler = torch.cuda.amp.GradScaler()

for inputs, targets in dataloader:
    optimizer.zero_grad()

    with torch.cuda.amp.autocast(dtype=torch.float16):
        outputs = model(inputs)
        loss = criterion(outputs, targets)

    scaler.scale(loss).backward()
    scaler.step(optimizer)
    scaler.update()

🔍 GPU Profiling & Memory Diagnostics

Check VRAM memory allocation programmatically:

import torch

if torch.cuda.is_available():
    allocated = torch.cuda.memory_allocated() / (1024**2)
    reserved = torch.cuda.memory_reserved() / (1024**2)
    print(f"Allocated VRAM: {allocated:.2f} MB | Reserved VRAM: {reserved:.2f} MB")