diff --git a/examples/baby-llama/baby-llama.cpp b/examples/baby-llama/baby-llama.cpp index ad5817c86..3b02a383e 100644 --- a/examples/baby-llama/baby-llama.cpp +++ b/examples/baby-llama/baby-llama.cpp @@ -3,6 +3,11 @@ #include #include +#undef MIN +#undef MAX +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) + float frand() { return (float)rand()/(float)RAND_MAX; } @@ -576,15 +581,18 @@ void get_example_targets(int example_id, struct ggml_tensor * tokens_input, stru int n_vocab = targets->ne[0]; float randomness = 0.0f; ggml_set_zero(targets); - for (int i=0; i 1.0f) ? 1.0f : z; // clamp to [0..1] - int token = (int)(z*(float)(n_vocab-1)); - ggml_set_f32_1d(targets, i*n_vocab + token, +1.0f); - ggml_set_i32_1d(tokens_input, i, token); + int token = MAX(1,MIN(1+(int)(z*(float)(n_vocab-1)), n_vocab-1)); + ggml_set_f32_1d(targets, (i-1)*n_vocab + token, +1.0f); + if (i