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

Data Types: Strings, Integers, and the Memory Matrix

Data Types: Strings, Integers, and the Memory Matrix

25 min read Series: Logic & Legacy Day 1 / 30 Level: Foundation

To master Python, you have to look under the hood. Today, we’re breaking down how Python actually "thinks" about your data and how we can use that knowledge to write superior code.

1. The String (str): More than just Text

A string is a sequence of Unicode characters. In Python, you have three ways to define them:

  • Single/Double Quotes: 'Hello' or "Hello" (Standard)
  • Triple Quotes: """ ... """ or ''' ... ''' (Used for multi-line strings and documentation).

The str() Function

This is the "Translator." It forces any data type into a string format so it can be printed or stored as text.

String Conversion
age = 25
print("I am " + str(age)) # Necessary because you can't add int to str

Memory Management: String Interning

Python is smart. If you create two different variables with identical short strings, Python doesn't waste space. String Interning ensures only one copy exists in memory. Both variables point to the same address.

💡 NOTE: The input() function always returns a str. If you type 10, val is "10", not 10.

2. The Integer (int): The Infinite Container

Integers in Python are whole numbers. Unlike C++ or Java, Python 3 integers have arbitrary precision—they can grow as large as your RAM allows.

3. The Boolean (bool) & Float (float)

Booleans represent the binary truth (True/False). Floats handle the precision of decimal numbers, following the IEEE 754 standard.

🚀 Key Takeaways

  • Strings are Immutable: Once created, they cannot be changed. Python uses "Interning" to save memory.
  • Ints have No Limits: Python handles large numbers by grabbing more memory automatically.
  • Truthiness: In Python, empty objects ("", [], 0) are False. Everything else is True.
  • Float Trap: Avoid using floats for financial data due to rounding inaccuracies (IEEE 754).

⚔️ The Forge: Practice Project

The "Warrior Profile" Generator

Prove your mastery of variables and types by building a simple profile script:

  1. Use input() to get a name (String).
  2. Get an age and convert it to an int.
  3. Get a "Power Level" and convert it to a float.
  4. Check if the warrior is "Active" using a bool comparison (e.g., age > 18).
  5. Print a formatted summary that combines all these types into one string.
# Hint: Remember that input() always returns a string!
age = int(input("Enter age: "))

Comments