TensorTonic
Study Plans
Study Plan
Account for ZeRO Memory by Stage
Distributed Computing
Easy

Calculate persistent model-state bytes per rank for replicated data parallelism (DDP) and ZeRO stages 1 through 3. Use this pooled-byte model: PPP, GGG, and OOO are the supplied parameter, gradient, and optimizer-state byte counts, and RRR is the number of ranks. Each MMM denotes the largest per-rank allocation under that model; ceiling brackets round up to an integer.

MDDP=P+G+O.M_{\mathrm{DDP}}=P+G+O.MDDP​=P+G+O. MZeRO1=P+G+⌈OR⌉.M_{\mathrm{ZeRO1}}=P+G+\left\lceil\frac{O}{R}\right\rceil.MZeRO1​=P+G+⌈RO​⌉. MZeRO2=P+⌈G+OR⌉.M_{\mathrm{ZeRO2}}=P+\left\lceil\frac{G+O}{R}\right\rceil.MZeRO2​=P+⌈RG+O​⌉. MZeRO3=⌈P+G+OR⌉.M_{\mathrm{ZeRO3}}=\left\lceil\frac{P+G+O}{R}\right\rceil.MZeRO3​=⌈RP+G+O​⌉.

The sharded categories in each numerator form one byte pool. Activations, transient gathered buffers, and allocator padding are excluded. Return a Python dictionary with ddp, zero1, zero2, and zero3, each an exact Python integer byte count.

Loading visualization...

Examples

Input: parameter_bytes = 400, gradient_bytes = 400, optimizer_bytes = 800, world_size = 4

Output: {"ddp":1600,"zero1":1000,"zero2":700,"zero3":400}

Explanation: DDP replicates all 1600 bytes. The ZeRO stages progressively shard optimizer, gradient, and parameter state across four ranks.

Input: parameter_bytes = 5, gradient_bytes = 7, optimizer_bytes = 11, world_size = 3

Output: {"ddp":23,"zero1":16,"zero2":11,"zero3":8}

Input: parameter_bytes = 100, gradient_bytes = 50, optimizer_bytes = 200, world_size = 1

Output: {"ddp":350,"zero1":350,"zero2":350,"zero3":350}

Hint 1

divmod returns an integer quotient and remainder.

Hint 2

Python integers support exact arithmetic without a fixed-width overflow.

Requirements

  • Follow the stated pooled-byte memory model.
  • Preserve exact integer byte counts, including uneven divisions.

Constraints

  • parameter_bytes, gradient_bytes, and optimizer_bytes are nonnegative Python integers.
  • Their sum is at most 9,007,199,254,740,991.
  • world_size is a positive Python integer no greater than 9,007,199,254,740,991.
  • Activations and transient gathered buffers are excluded.
Try Similar Problems
Measure Pipeline Bubble UtilizationMediumChoose a Topology-Aware Parallel PlanHardCalculate Collective Effective BandwidthEasySynchronize Data-Parallel GradientsMediumSimulate Distributed CollectivesMediumReconstruct a Column-Parallel MLP LayerMediumShared-Memory Bank Conflict AnalyzerEasyOrthogonalize a Muon Momentum UpdateEasyEstimate Model Memory and Minimum GPU CountEasyCalculate Tensor Parallel Communication CostHardSimulate Disaggregated Prefill and Decode ServingHardImplement Expert Parallel Routing Across GPUsHard

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.

Account for ZeRO Memory by Stage

Distributed Computing
Easy

Calculate persistent model-state bytes per rank for replicated data parallelism (DDP) and ZeRO stages 1 through 3. Use this pooled-byte model: PPP, GGG, and OOO are the supplied parameter, gradient, and optimizer-state byte counts, and RRR is the number of ranks. Each MMM denotes the largest per-rank allocation under that model; ceiling brackets round up to an integer.

MDDP=P+G+O.M_{\mathrm{DDP}}=P+G+O.MDDP​=P+G+O. MZeRO1=P+G+⌈OR⌉.M_{\mathrm{ZeRO1}}=P+G+\left\lceil\frac{O}{R}\right\rceil.MZeRO1​=P+G+⌈RO​⌉. MZeRO2=P+⌈G+OR⌉.M_{\mathrm{ZeRO2}}=P+\left\lceil\frac{G+O}{R}\right\rceil.MZeRO2​=P+⌈RG+O​⌉. MZeRO3=⌈P+G+OR⌉.M_{\mathrm{ZeRO3}}=\left\lceil\frac{P+G+O}{R}\right\rceil.MZeRO3​=⌈RP+G+O​⌉.

The sharded categories in each numerator form one byte pool. Activations, transient gathered buffers, and allocator padding are excluded. Return a Python dictionary with ddp, zero1, zero2, and zero3, each an exact Python integer byte count.

Loading visualization...

Examples

Input: parameter_bytes = 400, gradient_bytes = 400, optimizer_bytes = 800, world_size = 4

Output: {"ddp":1600,"zero1":1000,"zero2":700,"zero3":400}

Explanation: DDP replicates all 1600 bytes. The ZeRO stages progressively shard optimizer, gradient, and parameter state across four ranks.

Input: parameter_bytes = 5, gradient_bytes = 7, optimizer_bytes = 11, world_size = 3

Output: {"ddp":23,"zero1":16,"zero2":11,"zero3":8}

Input: parameter_bytes = 100, gradient_bytes = 50, optimizer_bytes = 200, world_size = 1

Output: {"ddp":350,"zero1":350,"zero2":350,"zero3":350}

Hint 1

divmod returns an integer quotient and remainder.

Hint 2

Python integers support exact arithmetic without a fixed-width overflow.

Requirements

  • Follow the stated pooled-byte memory model.
  • Preserve exact integer byte counts, including uneven divisions.

Constraints

  • parameter_bytes, gradient_bytes, and optimizer_bytes are nonnegative Python integers.
  • Their sum is at most 9,007,199,254,740,991.
  • world_size is a positive Python integer no greater than 9,007,199,254,740,991.
  • Activations and transient gathered buffers are excluded.
Try Similar Problems
Measure Pipeline Bubble UtilizationMediumChoose a Topology-Aware Parallel PlanHardCalculate Collective Effective BandwidthEasySynchronize Data-Parallel GradientsMediumSimulate Distributed CollectivesMediumReconstruct a Column-Parallel MLP LayerMediumShared-Memory Bank Conflict AnalyzerEasyOrthogonalize a Muon Momentum UpdateEasyEstimate Model Memory and Minimum GPU CountEasyCalculate Tensor Parallel Communication CostHardSimulate Disaggregated Prefill and Decode ServingHardImplement Expert Parallel Routing Across GPUsHard

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.