NumPy allowed · plain Python earns 10 bonus points
Implement a real, back-of-envelope GPU memory estimator MLOps engineers actually use to pick a batch size before a training run OOMs.
Implement estimate_batch_memory_gb(num_params, batch_size, seq_len, hidden_dim, bytes_per_param=4.0). Model weight memory (with Adam's 2 extra moment buffers, i.e. 3x weights total) is num_params * bytes_per_param * 3. Activation memory (a common simplified estimate) is batch_size * seq_len * hidden_dim * bytes_per_param * 2 (forward + backward). Return (weight_memory + activation_memory) / (1024**3) (bytes to GB).
estimate_batch_memory_gb(num_params: int, batch_size: int, seq_len: int, hidden_dim: int, bytes_per_param: float = 4.0) -> float