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

Fix continued generation #66

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions src/genesys/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,25 @@ def _prepare_batch(self, batch: dict, dataset: str) -> tuple:
batch_messages = [
[
{"role": "user", "content": b["prompt"]},
{"role": "assistant", "content": "<think>/n" + b["llm_response"]},
{"role": "assistant", "content": "<think>\n" + b["llm_response_first_time"]},
{"role": "assistant", "content": ""}, # this message needs to be here so hf templating works, we're stripping it out again below
]
for b in batch
]
batch_inputs = self.tokenizer.apply_chat_template(
batch_messages,
tokenize=False,
continue_final_message=True
)
unwanted_suffix = "<|end▁of▁sentence|><|Assistant|><|end▁of▁sentence|>" # strip out last message
for i, inp in enumerate(batch_inputs):
if inp.endswith(unwanted_suffix):
batch_inputs[i] = inp[: -len(unwanted_suffix)]
else:
batch_messages = [
[{"role": "user", "content": b["prompt"]}, {"role": "assistant", "content": "<think>/n"}] for b in batch
]

batch_inputs = self.tokenizer.apply_chat_template(batch_messages, tokenize=False, continue_final_message=True)
batch_inputs = self.tokenizer.apply_chat_template(batch_messages, tokenize=False, continue_final_message=True)

return batch_inputs, batch

Expand Down
5 changes: 4 additions & 1 deletion src/genesys/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ def main(config: GenerateConfig):

# Initialize components
log("[cyan] Configuring output path and gcp bucket...[/]")
if config.gcp_bucket is not None:
gcp_credentials = os.environ.get("GCP_CREDENTIALS_BASE64")
assert gcp_credentials is not None, "the GCP_CREDENTIALS_BASE64 environment variable is not set"
if not os.path.exists(config.path_output):
os.makedirs(config.path_output)
gcp_bucket = (
GcpBucket(config.gcp_bucket, os.environ.get("GCP_CREDENTIALS_BASE64"))
GcpBucket(config.gcp_bucket, gcp_credentials)
if config.gcp_bucket is not None
else None
)
Expand Down