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

Enhance input validation in sampling script #47

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
7 changes: 7 additions & 0 deletions examples/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from gemma import transformer as transformer_lib

import sentencepiece as spm
import os

_PATH_CHECKPOINT = flags.DEFINE_string(
"path_checkpoint", None, required=True, help="Path to checkpoint."
Expand Down Expand Up @@ -69,6 +70,11 @@ def _load_and_sample(
total_generation_steps: int,
) -> None:
"""Loads and samples a string from a checkpoint."""
if not os.path.isfile(path_checkpoint):
raise ValueError(f"Checkpoint file not found: {path_checkpoint}")
if not os.path.isfile(path_tokenizer):
raise ValueError(f"Tokenizer file not found: {path_tokenizer}")

print(f"Loading the parameters from {path_checkpoint}")
parameters = params_lib.load_and_format_params(path_checkpoint)
print("Parameters loaded.")
Expand Down Expand Up @@ -110,3 +116,4 @@ def main(argv: Sequence[str]) -> None:

if __name__ == "__main__":
app.run(main)