Skip to content

Commit

Permalink
Gordeeva_1_test
Browse files Browse the repository at this point in the history
new

first commit

Vary parameters

test_2

Update test.c
  • Loading branch information
TayaGordeeva authored and dkurt committed Feb 6, 2024
1 parent 95dc38c commit ce1d508
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ testc:
VERBOSITY ?= 0
.PHONY: testcc
testcc:
$(CC) -DVERBOSITY=$(VERBOSITY) -O3 -march=rv64gcv0p7 -mabi=lp64d -o testc test.c -lm
$(CC) -DVERBOSITY=$(VERBOSITY) -O3 -march=rv64gcv0p7 -mabi=lp64d -o testc test.c -lm -Wno-unused-result

.PHONY: clean
clean:
Expand Down
66 changes: 66 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,74 @@ int test_rvv()
return (int)vfmv_f_s_f32m1_f32(val);
}



void test_generate(char* prompt, char* checkpoint_path, float temperature, int steps, float topp, const char* expected){
char *tokenizer_path = "tokenizer.bin";
unsigned long long rng_seed = 124; // seed rng with time by default

// parameter validation/overrides
if (temperature < 0.0) temperature = 0.0;
if (topp < 0.0 || 1.0 < topp) topp = 0.9;
if (steps < 0) steps = 0;

// build the Transformer via the model .bin file
Transformer transformer;
build_transformer(&transformer, checkpoint_path);
if (steps == 0 || steps > transformer.config.seq_len) steps = transformer.config.seq_len; // ovrerride to ~max length

// build the Tokenizer via the tokenizer .bin file
Tokenizer tokenizer;
build_tokenizer(&tokenizer, tokenizer_path, transformer.config.vocab_size);

// build the Sampler
Sampler sampler;
build_sampler(&sampler, transformer.config.vocab_size, temperature, topp, rng_seed);

// run!

freopen("output.txt", "wt", stdout); // redirect output
generate(&transformer, &tokenizer, &sampler, prompt, steps);
freopen("/dev/tty", "w", stdout); // resume

// memory and file handles cleanup
free_sampler(&sampler);
free_tokenizer(&tokenizer);
free_transformer(&transformer);

// Check
FILE* f = fopen("output.txt", "rt");
fseek(f, 0, SEEK_END);
const size_t sz = ftell(f);
fseek(f, 0, SEEK_SET);
char output[sz];
fread(output, sizeof(char), sz, f);
output[sz - 1] = '\0';
fclose(f);

int res = strcmp(expected, output);
if (res != 0) {
printf("Expected: %s\n\nGenerated: %s\n", expected, output);
}
assert_eq(res, 0);
}

int main(int argc, char *argv[]) {
test_prompt_encodings();
test_rvv();

const char* expected = "That was the darkest day of the year. The stars were shining bright in the sky and the birds were singing.\n\
\"Mommy, why is it so dark?\" asked the little girl, pointing out her finger.\n\
\"Well, the sun is setting and it will be a beautiful night,\" replied her mom.\n\
The little girl looked up at the sky and smiled. \"I like it when the sun sets,\" she said.\n\
\"I know, sweetie. The";
test_generate("That was the darkest day of the year.", "/tmp/stories15M.bin", 0.7f, 100, 0.9f, expected);

const char* expected2="It was dark and cold around. The little girl was feeling scared. She looked around and saw a big, dark room. She wanted to go in, but she was too scared.\n\
Suddenly, she heard a noise. It was coming from the corner of the room. She slowly walked over and saw a big, black cat. It was meowing and seemed to be trying to get her attention.\n\
The little girl was still scared, but she was also curious. She";

test_generate ("It was dark and cold around.", "/tmp/stories110M.bin", 0.3f, 103, 0.6f, expected2);
printf("ALL OK\n");

}

0 comments on commit ce1d508

Please sign in to comment.