Skip to main content

Featured

GPU Memory Sharding with FSDP

GPU Memory Sharding with FSDP

DISTRIBUTED DEEP LEARNING — PART 1/5 Day 1: Demystifying GPU Memory & The ZeRO Revolution — DeepSpeed, FSDP & State Sharding 25 min read Series: The Dharma of Development Distributed DL (Day 1 / 5) Level: Principal / Systems AI Engineer 💥 Context: You attempt to fine-tune or pretrain a 13-billion parameter dense transformer on an 80GB NVIDIA H100 or A100 GPU using standard PyTorch. You set your batch size to 1. You press enter. Within three seconds, your terminal explodes with the most dreaded error in artificial intelligence: torch.cuda.OutOfMemoryError: CUDA out of memory . How is this possible? In 16-bit precision, 13 billion parameters occupy only ~26 GB of disk space. Why can't an 80 GB state-of-the-art GPU train a 26 GB model? Because the naive mental model of machine learning memory is deeply flawed. Today, we demystify the true $16\Phi$ memory footprint of neural networks and master the architecture that made modern large language models possi...

Infrastructure as Code — Terraform Modules, State Locking & GitOps Workflows 15 min rea

BACKEND SERIES

Day 38: Infrastructure as Code — Terraform Modules, State Locking & GitOps Workflows

Series: Logic & Legacy
Day 38 / 50
Level: Senior / Cloud Architect

⏳ Context: As backend applications transition from single servers to distributed cloud microservices, managing cloud resources (VPCs, database clusters, load balancers, and Redis instances) manually through a web console is a recipe for disaster. Manual clicks cause configuration drift, unrepeatable environments, and high MTTR during disaster recovery. **Infrastructure as Code (IaC)** allows developers to declare cloud architecture as version-controlled code. Today, we master Terraform: HCL module design, remote state locking, and GitOps integration.




1. The Declarative IaC Paradigm & State Management

Unlike imperative scripts (Bash, Python Boto3) that specify how to construct resources step-by-step, Terraform uses a **declarative paradigm** in HashiCorp Configuration Language (HCL). You declare the desired end-state, and Terraform's dependency graph calculates the minimal delta required to transform existing infrastructure into the target state.

Remote State Backend Configuration with S3 & DynamoDB Lock
# backend.tf - Configures encrypted remote state storage with concurrency locking
terraform {
  required_version = ">= 1.5.0"
  
  backend "s3" {
    bucket         = "company-tf-state-production"
    key            = "backend-service/terraform.tfstate"
    region         = "us-east-1"
    encrypt        = true
    dynamodb_table = "terraform-state-locks" # Prevents concurrent applies!
  }
}

2. Structuring Modular HCL Configurations

Clean IaC architecture follows strict modularity, separating environments (Staging vs. Production) while reusing core resource definitions:

Reusable Production Database Module Snippet (main.tf)
module "postgres_database" {
  source = "./modules/rds_postgres"

  environment     = var.environment
  db_name         = "logic_legacy_db"
  instance_class  = var.db_instance_class
  allocated_storage = 100
  multi_az        = true # High-Availability multi-AZ deployment
  
  subnet_ids      = module.vpc.private_subnets
  security_groups = [aws_security_group.db_sg.id]
}

output "database_endpoint" {
  value       = module.postgres_database.endpoint
  sensitive   = true
}

3. GitOps Automation via GitHub Actions

In a **GitOps workflow**, developers never run `terraform apply` from local laptops. All infrastructure changes are proposed via Pull Requests where automated CI runs `terraform plan` and posts execution diffs as PR comments before merging.

The Shareable Quote: "Treat your infrastructure with the same rigor as application code: version-controlled, code-reviewed, and deployed via automated pipelines."

🛠️ Day 38 Project: Build a Modular Terraform Infrastructure

Design a modular Terraform project provisioning an AWS VPC, Redis ElastiCache cluster, and S3/DynamoDB remote state backend.

  • Create a remote S3 backend configuration with DynamoDB state locking.
  • Write a reusable Redis caching module accepting environment variables.
  • Configure a GitHub Actions workflow to run automated `terraform plan` validation on Pull Requests.
🔥 PRO UPGRADE / TEASER

Tomorrow, we step into advanced observability and telemetry: Day 39: Distributed Tracing — OpenTelemetry, Jaeger Tracing, and Context Propagation in Microservices.

Architectural Consulting

If you are building high-concurrency Python backends or microservices and need senior architectural guidance, I am available for direct contracting.

Explore Enterprise Engagements →

Comments