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

Add pre-generated prompts option for benchmark #1091

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions benchmark/python/benchmark_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@
generator.generate_next_token()
return tokenizer.decode(generator.get_sequence(0))

# Use prompt length to get pre-defined prompt
def get_prompt_by_length(prompt_length):
json_path = "prompts.json"
f = open(json_path)

Check warning

Code scanning / CodeQL

File is not always closed Warning test

File is opened but is not closed.
data = json.load(f)

return data[f"{prompt_length}"]

def get_target_pip_package_version(target_pip_package_name_list):
# get package name and version
import pkg_resources
Expand Down Expand Up @@ -219,7 +227,7 @@
num_repetitions = args.repetitions
temperature = 1.0

# Get tokenizer, and model

Check warning

Code scanning / CodeQL

Variable defined multiple times Warning test

This assignment to 'tokens' is unnecessary as it is
redefined
before this value is used.
This assignment to 'tokens' is unnecessary as it is
redefined
before this value is used.

Check warning

Code scanning / CodeQL

Variable defined multiple times Warning test

This assignment to 'prompt' is unnecessary as it is
redefined
before this value is used.
This assignment to 'prompt' is unnecessary as it is
redefined
before this value is used.
if args.verbose: print("Loading model... ")
model=og.Model(f'{args.input_folder}')
if args.verbose: print("Model loaded")
Expand All @@ -232,6 +240,9 @@
# use random tokens instead of generating a prompt using the model and then tokenizing it
tokens = np.random.randint(100, size=(batch_size, prompt_length))
prompt = [tokenizer.decode(tokens[0])] * batch_size
elif args.use_prompt_set:
prompt = get_prompt_by_length(prompt_length)
tokens = tokenizer.encode_batch(prompt)
else:
prompt = [generate_prompt(model, tokenizer, prompt_length, args.use_graph_capture)] * batch_size
tokens = tokenizer.encode_batch(prompt)
Expand Down Expand Up @@ -424,6 +435,7 @@
parser.add_argument('-mn', '--model_name', type=str, default='model_name', help='Model name defined by users')
parser.add_argument('-pr', '--precision', type=str, default='fp16', help='Model precision for metrics info')
parser.add_argument('--use_random_tokens', action='store_true', help='Use random tokens instead of generating a prompt')
parser.add_argument('--use_prompt_set', action='store_true', help='Use pre-generated prompt set instead of generating a prompt')
args = parser.parse_args()

# check max_lengths
Expand Down
7 changes: 7 additions & 0 deletions benchmark/python/prompts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"16": "How are astronauts launched into space quickly on those rockets? ",
"64": "",
"256": "",
"1024": "",
"2048": ""
}
Loading