"include/vscode:/vscode.git/clone" did not exist on "cc50b687353ebcd560812db3aaf74b79581de7d3"
Commit 32d7593d authored by Benjamin Fattori's avatar Benjamin Fattori
Browse files

partial support for document-level padding

parent a8d9a449
...@@ -157,19 +157,64 @@ class HFLM(LM): ...@@ -157,19 +157,64 @@ class HFLM(LM):
# TODO: Implement caching once we've confirmed the perplexity implementation # TODO: Implement caching once we've confirmed the perplexity implementation
# TODO: automatic batch size detection for vectorization # TODO: automatic batch size detection for vectorization
extra_pad = []
numpad_batches = 0
# balance token batches among iterators
if self.world_size > 1:
cumulative_batches = 0
# compute cumlative batches once -> could also just cache this can then use it later
for (string,) in tqdm([req.args for req in requests],disable=(self.rank != 0)):
rolling_token_windows = list(
map(
utils.make_disjoint_window,
utils.get_rolling_token_windows(
token_list=self.tok_encode(string),
prefix_token=self.eot_token_id,
max_seq_len=self.max_length,
context_len=1,
),
)
)
rolling_token_windows = [(None,) + x for x in rolling_token_windows]
cumulative_batches += len(rolling_token_windows)
cum_batches_ranks = torch.tensor(cumulative_batches, device = self.device)
gathered_item = self.accelerator.gather(cum_batches_ranks).cpu().detach().numpy().tolist()
# compute number of pseudobatches to pad with (FSDP/DDP require even batches among ranks)
numpad_batches = max(gathered_item) - gathered_item[self.rank]
extra_pad = [('pad',)] if numpad_batches > 0 else []
print(self.rank, numpad_batches)
loglikelihoods = [] loglikelihoods = []
for (string,) in tqdm([req.args for req in requests]): for (string,) in tqdm(extra_pad + [req.args for req in requests],disable=(self.rank != 0)):
rolling_token_windows = list( if numpad_batches > 0:
map( rolling_token_windows = list(
utils.make_disjoint_window, map(
utils.get_rolling_token_windows( utils.make_disjoint_window,
token_list=self.tok_encode(string), utils.get_rolling_token_windows(
prefix_token=self.eot_token_id, token_list=[self.eot_token_id]*self.max_length*numpad_batches,
max_seq_len=self.max_length, prefix_token=self.eot_token_id,
context_len=1, max_seq_len=self.max_length,
), context_len=1,
),
)
)
else:
rolling_token_windows = list(
map(
utils.make_disjoint_window,
utils.get_rolling_token_windows(
token_list=self.tok_encode(string),
prefix_token=self.eot_token_id,
max_seq_len=self.max_length,
context_len=1,
),
)
) )
)
rolling_token_windows = [(None,) + x for x in rolling_token_windows] rolling_token_windows = [(None,) + x for x in rolling_token_windows]
...@@ -179,11 +224,16 @@ class HFLM(LM): ...@@ -179,11 +224,16 @@ class HFLM(LM):
rolling_token_windows, disable_tqdm=True rolling_token_windows, disable_tqdm=True
) )
# discard is_greedy if numpad_batches > 0:
string_nll = [x[0] for x in string_nll] numpad_batches = 0
string_nll = sum(string_nll) else:
loglikelihoods.append(string_nll) # discard is_greedy
string_nll = [x[0] for x in string_nll]
string_nll = sum(string_nll)
loglikelihoods.append(string_nll)
return loglikelihoods return loglikelihoods
...@@ -205,7 +255,7 @@ class HFLM(LM): ...@@ -205,7 +255,7 @@ class HFLM(LM):
# TODO: automatic (variable) batch size detection for vectorization # TODO: automatic (variable) batch size detection for vectorization
re_ord = utils.Reorderer(requests, _collate) re_ord = utils.Reorderer(requests, _collate)
for chunk in utils.chunks( for chunk in utils.chunks(
tqdm(re_ord.get_reordered(), disable=(disable_tqdm or not (self.rank == 0))), self.batch_size tqdm(re_ord.get_reordered(), disable=(disable_tqdm or (self.rank != 0))), self.batch_size
): ):
inps = [] inps = []
cont_toks_list = [] cont_toks_list = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment