Skip to content

Bugfix: batch_size_warmup_scheduler was taking too long #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions src/sequence_packer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,19 @@ def __init__(
else:
self.warmup_tokens = warmup_tokens
self.warmup_tokens = math.ceil(self.warmup_tokens / world_size)
self._step_thresholds = self._calculate_step_thresholds()

def _calculate_step_thresholds(self):
total_batch_sizes = sum(range(self.min_batch_size, self.max_batch_size))
steps_per_unit = self.warmup_tokens / total_batch_sizes

thresholds = []
cumsum = 0
for batch_size in range(self.min_batch_size, self.max_batch_size):
cumsum += batch_size
steps = math.ceil(steps_per_unit * cumsum)
thresholds.append(steps)
return thresholds

def __call__(self, current_step: int) -> int:
if current_step >= self.warmup_tokens:
self.tokens_per_batch_size = self._calculate_tokens_per_batch_size()

def _calculate_tokens_per_batch_size(self):
total_batch_sizes = (self.max_batch_size-1)*(self.max_batch_size)/2 - (self.min_batch_size-1)*(self.min_batch_size)/2
tokens_per_batch_size = self.warmup_tokens / total_batch_sizes
return tokens_per_batch_size

def __call__(self, current_token_count: int) -> int:
if current_token_count >= self.warmup_tokens:
return self.max_batch_size

for i, threshold in enumerate(self._step_thresholds):
if current_step < threshold:
return self.min_batch_size + i

# should never hit this, but just in case
return self.max_batch_size
how_many_batch_sizes = (current_token_count) // self.tokens_per_batch_size
return self.min_batch_size + how_many_batch_sizes


class SequencePackerBatchOutputTuple(NamedTuple):
Expand Down