Skip to content

Commit

Permalink
Spread layers more uniformly when using partition_uniform (#4053)
Browse files Browse the repository at this point in the history
* update partition_uniform util function

* formatting

---------

Co-authored-by: Olatunji Ruwase <olruwase@microsoft.com>
  • Loading branch information
marcobellagente93 and tjruwase authored Aug 3, 2023
1 parent 1ba4098 commit e831863
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions deepspeed/runtime/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import psutil
import gc
from math import sqrt
from math import floor
from bisect import bisect_left
from packaging import version as pkg_version

Expand Down Expand Up @@ -552,17 +551,23 @@ def prefix_sum_inc(weights):


def partition_uniform(num_items, num_parts):
import numpy
parts = [0] * (num_parts + 1)
# First check for the trivial edge case
if num_items <= num_parts:
for p in range(num_parts + 1):
parts[p] = min(p, num_items)
return parts

chunksize = floor(num_items / num_parts)
for p in range(num_parts):
parts[p] = min(chunksize * p, num_items)
parts[num_parts] = num_items
chunksize = num_items // num_parts
residual = num_items - (chunksize * num_parts)

parts = numpy.arange(0, (num_parts + 1) * chunksize, chunksize)

for i in range(residual):
parts[i + 1:] += 1
parts = parts.tolist()

return parts


Expand Down

0 comments on commit e831863

Please sign in to comment.