Skip to content

Commit 043bcf8

Browse files
The gemma.cpp Authorscopybara-github
authored andcommitted
Added prompts with difference length.
PiperOrigin-RevId: 655310563
1 parent 9661b81 commit 043bcf8

File tree

3 files changed

+157
-7
lines changed

3 files changed

+157
-7
lines changed

BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ cc_binary(
382382

383383
cc_binary(
384384
name = "benchmarks",
385-
srcs = ["evals/benchmarks.cc"],
385+
srcs = [
386+
"evals/benchmarks.cc",
387+
"evals/prompts.h",
388+
],
386389
deps = [
387390
":benchmark_helper",
388391
"@benchmark//:benchmark",

evals/benchmarks.cc

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "benchmark/benchmark.h"
2222
#include "evals/benchmark_helper.h"
23+
#include "evals/prompts.h"
2324

2425
namespace gcpp {
2526

@@ -42,26 +43,53 @@ void RunPrompt(const std::string& original_prompt, benchmark::State& state) {
4243
state.SetItemsProcessed(total_tokens);
4344
}
4445

46+
void RunPromptWithName(const std::string& original_prompt,
47+
benchmark::State& state) {
48+
size_t total_tokens = 0;
49+
for (auto s : state) {
50+
std::string prompt = original_prompt; // reset from original
51+
auto [response, n] = s_env->QueryModel(prompt);
52+
if (s_env->Verbosity() != 0) {
53+
fprintf(stdout, "|%s|\n", response.c_str());
54+
}
55+
total_tokens += n;
56+
}
57+
58+
state.SetItemsProcessed(total_tokens);
59+
}
60+
4561
} // namespace gcpp
4662

4763
static void BM_short_prompt(benchmark::State& state) {
48-
gcpp::RunPrompt("What is the capital of Spain?", state);
64+
gcpp::RunPrompt(ShortPrompt(), state);
4965
}
5066

5167
static void BM_factuality_prompt(benchmark::State& state) {
52-
gcpp::RunPrompt("How does an inkjet printer work?", state);
68+
gcpp::RunPrompt(FactualityPrompt(), state);
5369
}
5470

5571
static void BM_creative_prompt(benchmark::State& state) {
56-
gcpp::RunPrompt("Tell me a story about a magical bunny and their TRS-80.",
57-
state);
72+
gcpp::RunPrompt(CreativePrompt(), state);
5873
}
5974

6075
static void BM_coding_prompt(benchmark::State& state) {
61-
gcpp::RunPrompt("Write a python program to generate a fibonacci sequence.",
62-
state);
76+
gcpp::RunPrompt(CodingPrompt(), state);
6377
}
6478

79+
static void BM_diff_length_prompt(benchmark::State& state) {
80+
gcpp::RunPrompt(GetPrompt(state.range(0)), state);
81+
}
82+
83+
BENCHMARK(BM_diff_length_prompt)
84+
->Repetitions(3)
85+
->Arg(32)
86+
->Arg(64)
87+
->Arg(128)
88+
->Arg(256)
89+
->Arg(512)
90+
->Unit(benchmark::kMillisecond)
91+
->UseRealTime();
92+
6593
BENCHMARK(BM_short_prompt)
6694
->Iterations(3)
6795
->Unit(benchmark::kMillisecond)

evals/prompts.h

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#ifndef PROMPTS_H // Include guard to prevent multiple inclusions
2+
#define PROMPTS_H
3+
4+
// Prompts for different tasks
5+
static const char* ShortPrompt() { return "What is the capital of Spain?"; }
6+
7+
static const char* FactualityPrompt() {
8+
return "How does an inkjet printer work?";
9+
}
10+
11+
static const char* CreativePrompt() {
12+
return "Tell me a story about a magical bunny and their TRS-80.";
13+
}
14+
15+
static const char* CodingPrompt() {
16+
return "Write a python program to generate a fibonacci sequence.";
17+
}
18+
19+
// The input prompts, each named by its token length.
20+
21+
static const char* Prompt32() {
22+
return "Once upon a time, there existed a little girl who liked to have "
23+
"adventures. She wanted to go to places and";
24+
}
25+
26+
static const char* Prompt64() {
27+
return "It is done, and submitted. You can play 'Survival of the Tastiest' "
28+
"on Android, and on the web. Playing on the web works, but you have "
29+
"to simulate multiple touch for table moving and that can be a bit "
30+
"confusing. There is a lot ";
31+
}
32+
33+
static const char* Prompt128() {
34+
return "It's done, and submitted. You can play 'Survival of the Tastiest' on "
35+
"Android, and on the web. Playing on the web works, but you have to "
36+
"simulate multiple touch for table moving and that can be a bit "
37+
"confusing. There is a lot I'd like to talk about. I will go through"
38+
" every topic, insted of making the typical what went right/wrong list"
39+
". Concept Working over the theme was probably one of the hardest "
40+
"tasks which I had to face. Originally, I had an idea of what kind of "
41+
"game I wanted to develop, gamep";
42+
}
43+
44+
static const char* Prompt256() {
45+
return "It is done, and submitted. You can play 'Survival of the Tastiest' on"
46+
" Android, and on the web. Playing on the web works, but you have to "
47+
"simulate multiple touch for table moving and that can be a bit "
48+
"confusing. There is a lot I'd like to talk about. I will go through "
49+
"every topic, insted of making the typical what went right/wrong list."
50+
" Concept Working over the theme was probably one of the hardest tasks"
51+
" which I had to face. Originally, I had an idea of what kind of game "
52+
"I wanted to develop, gameplay wise - something with a lot of "
53+
"enemies/actors, simple graphics, maybe set in space, controlled from "
54+
"a top-down view. I was confident that I could fit any theme around "
55+
"it. In the end, the problem with a theme like 'Evolution' in a game "
56+
"is that evolution is unassisted. It happens through several seemingly"
57+
" random mutations over time, with the most apt permutation surviving."
58+
" This genetic car simulator is, in my opinion, a great example of "
59+
"actual evolution of a species facing a challenge. But is it a game? "
60+
"In a game, you need to control something to reach an objective. This "
61+
"could be a character, a ";
62+
}
63+
64+
static const char* Prompt512() {
65+
return "It is done, and submitted. You can play 'Survival of the Tastiest'"
66+
" on Android, and on the web. Playing on the web works, but you have to"
67+
" simulate multiple touch for table moving and that can be a bit"
68+
" confusing. There is a lot I'd like to talk about. I will go through"
69+
" every topic, instead of making the typical what went right/wrong list."
70+
" Concept Working over the theme was probably one of the hardest tasks"
71+
" which I had to face. Originally, I had an idea of what kind of game I"
72+
" wanted to develop, gameplay wise - something with a lot of"
73+
" enemies/actors, simple graphics, maybe set in space, controlled from"
74+
" a top-down view. I was confident that I could fit any theme around"
75+
" it. In the end, the problem with a theme like 'Evolution' in a game"
76+
" is that evolution is unassisted. It happens through several seemingly"
77+
" random mutations over time, with the most apt permutation surviving."
78+
" This genetic car simulator is, in my opinion, a great example of"
79+
" actual evolution of a species facing a challenge. But is it a game?"
80+
" In a game, you need to control something to reach an objective. That"
81+
" control goes against what evolution is supposed to be like. If you"
82+
" allow the user to pick how to evolve something, it's not evolution"
83+
" anymore - it's the equivalent of intelligent design, the fable"
84+
" invented by creationists to combat the idea of evolution. Being"
85+
" agnostic and a Pastafarian, that's not something that rubbed me the"
86+
" right way. Hence, my biggest dillema when deciding what to create was"
87+
" not with what I wanted to create, but with what I did not. I didn't"
88+
" want to create an 'intelligent design' simulator and wrongly call it"
89+
" evolution. This is a problem, of course, every other contestant also"
90+
" had to face. And judging by the entries submitted, not many managed"
91+
" to work around it. I'd say the only real solution was through the use"
92+
" of artificial selection, somehow. So far, I have not seen any entry"
93+
" using this at its core gameplay. Alas, this is just a fun competition"
94+
" and after a while I decided not to be as strict with the game idea,"
95+
" and allowed myself to pick whatever I thought would work out. My"
96+
" initial idea was to create something where humanity tried to evolve"
97+
" to a next level but had some kind of foe trying to stop them from"
98+
" doing so. I kind of had this image of human souls flying in space"
99+
" towards ";
100+
}
101+
102+
static const char* GetPrompt(int length) {
103+
switch (length) {
104+
case 32:
105+
return Prompt32();
106+
case 64:
107+
return Prompt64();
108+
case 128:
109+
return Prompt128();
110+
case 256:
111+
return Prompt256();
112+
case 512:
113+
return Prompt512();
114+
default:
115+
return ShortPrompt();
116+
}
117+
}
118+
119+
#endif

0 commit comments

Comments
 (0)