Skip to content
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

remove pad tokens added by the accelerator.pad_across_processes #216

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
9 changes: 9 additions & 0 deletions bigcode_eval/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import math
import re
import warnings
import numpy as np
from collections import defaultdict
from typing import List, Optional

Expand Down Expand Up @@ -220,6 +221,13 @@ def _parse_instruction(code, instruction_tokens):
shift = len("```python")
return code[idx + shift :]

def _remove_rightpad_tokens(generated_tokens, pad_token):
for i in range(len(generated_tokens)-1, -1, -1):
if generated_tokens[i] == pad_token:
generated_tokens = np.delete(generated_tokens, i)
else:
break
return generated_tokens

def complete_code(
task,
Expand Down Expand Up @@ -315,6 +323,7 @@ def complete_code(
generated_tasks = generated_tasks.cpu().numpy()

for sample, generated_tokens in zip(generated_tasks, generated_tokens):
generated_tokens = _remove_rightpad_tokens(generated_tokens, tokenizer.pad_token_id)
gen_token_dict[sample].append(generated_tokens)

if save_every_k_tasks >= 1 and (step + 1) % save_every_k_tasks == 0:
Expand Down