@@ -1179,6 +1179,7 @@ int main(int argc, char ** argv) {
1179
1179
1180
1180
int n_examples = 128 ;
1181
1181
int n_tokens = model.hparams .n_ctx ;
1182
+ int n_vocab = model.hparams .n_vocab ;
1182
1183
1183
1184
for (int ex=0 ; ex<n_examples; ++ex) {
1184
1185
struct ggml_init_params params = {
@@ -1190,18 +1191,18 @@ int main(int argc, char ** argv) {
1190
1191
struct ggml_context * ctx0 = ggml_init (params);
1191
1192
1192
1193
1193
- // struct ggml_tensor * before_opt_best_samples = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, n_tokens);
1194
- // struct ggml_tensor * before_opt_probs = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, model.hparams. n_vocab, n_tokens);
1194
+ struct ggml_tensor * before_opt_best_samples = ggml_new_tensor_1d (ctx0, GGML_TYPE_I32, n_tokens);
1195
+ struct ggml_tensor * before_opt_probs = ggml_new_tensor_2d (ctx0, GGML_TYPE_F32, n_vocab, n_tokens);
1195
1196
struct ggml_tensor * after_opt_best_samples = ggml_new_tensor_1d (ctx0, GGML_TYPE_I32, n_tokens);
1196
- struct ggml_tensor * after_opt_probs = ggml_new_tensor_2d (ctx0, GGML_TYPE_F32, model. hparams . n_vocab , n_tokens);
1197
+ struct ggml_tensor * after_opt_probs = ggml_new_tensor_2d (ctx0, GGML_TYPE_F32, n_vocab, n_tokens);
1197
1198
struct ggml_tensor * tokens_input1 = ggml_new_tensor_1d (ctx0, GGML_TYPE_I32, n_tokens);
1198
1199
struct ggml_tensor * tokens_input2 = ggml_new_tensor_1d (ctx0, GGML_TYPE_I32, n_tokens);
1199
1200
// struct ggml_tensor * tokens_input3 = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, n_tokens);
1200
1201
// struct ggml_tensor * tokens_input4 = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, n_tokens);
1201
- struct ggml_tensor * targets1 = ggml_new_tensor_2d (ctx0, GGML_TYPE_F32, model. hparams . n_vocab , n_tokens);
1202
- struct ggml_tensor * targets2 = ggml_new_tensor_2d (ctx0, GGML_TYPE_F32, model. hparams . n_vocab , n_tokens);
1203
- // struct ggml_tensor * targets3 = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, model.hparams. n_vocab, n_tokens);
1204
- // struct ggml_tensor * targets4 = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, model.hparams. n_vocab, n_tokens);
1202
+ struct ggml_tensor * targets1 = ggml_new_tensor_2d (ctx0, GGML_TYPE_F32, n_vocab, n_tokens);
1203
+ struct ggml_tensor * targets2 = ggml_new_tensor_2d (ctx0, GGML_TYPE_F32, n_vocab, n_tokens);
1204
+ // struct ggml_tensor * targets3 = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, n_vocab, n_tokens);
1205
+ // struct ggml_tensor * targets4 = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, n_vocab, n_tokens);
1205
1206
1206
1207
int n_past = 0 ;
1207
1208
@@ -1213,7 +1214,7 @@ int main(int argc, char ** argv) {
1213
1214
// get_example_targets(64*ex+32, tokens_input3, targets3);
1214
1215
// get_example_targets(64*ex+48, tokens_input4, targets4);
1215
1216
// print_probs(targets);
1216
- // print_tokens(tokens_input, model.hparams. n_vocab);
1217
+ // print_tokens(tokens_input, n_vocab);
1217
1218
1218
1219
struct ggml_tensor * logits1 = forward (&model, &kv_self, ctx0, &gf, tokens_input1, n_tokens, n_past);
1219
1220
struct ggml_tensor * logits2 = forward (&model, &kv_self, ctx0, &gf, tokens_input2, n_tokens, n_past);
@@ -1246,7 +1247,7 @@ int main(int argc, char ** argv) {
1246
1247
// printf("probabilities before optimization:\n");
1247
1248
// print_probs(before_opt_probs);
1248
1249
// printf("best samples before optimization:\n");
1249
- // print_tokens(before_opt_best_samples, model.hparams. n_vocab);
1250
+ // print_tokens(before_opt_best_samples, n_vocab);
1250
1251
1251
1252
struct ggml_opt_params opt_params_adam = ggml_opt_default_params (GGML_OPT_ADAM);
1252
1253
struct ggml_opt_params opt_params_lbfgs = ggml_opt_default_params (GGML_OPT_LBFGS);
@@ -1276,28 +1277,28 @@ int main(int argc, char ** argv) {
1276
1277
// printf("probabilities after optimization:\n");
1277
1278
// print_probs(after_opt_probs);
1278
1279
printf (" best samples after optimization:\n " );
1279
- print_tokens (after_opt_best_samples, model. hparams . n_vocab );
1280
+ print_tokens (after_opt_best_samples, n_vocab);
1280
1281
}
1281
1282
1282
1283
ggml_free (ctx0);
1283
1284
}
1284
1285
1285
1286
{
1286
- int n_gen = 64 ;
1287
- int sample_ctx = n_tokens/2 ;
1287
+ int n_gen = 128 ;
1288
+ int sample_ctx = n_tokens/2 -n_tokens/ 16 ;
1288
1289
1289
1290
printf (" Generating %d tokens.\n " , n_gen);
1290
1291
1291
1292
struct ggml_tensor * tokens_input = ggml_new_tensor_1d (model.ctx , GGML_TYPE_I32, n_tokens);
1292
- struct ggml_tensor * targets = ggml_new_tensor_2d (model.ctx , GGML_TYPE_F32, model. hparams . n_vocab , n_tokens);
1293
+ struct ggml_tensor * targets = ggml_new_tensor_2d (model.ctx , GGML_TYPE_F32, n_vocab, n_tokens);
1293
1294
1294
1295
get_example_targets (137 , tokens_input, targets);
1295
1296
for (int i=sample_ctx; i<n_tokens; ++i) {
1296
- ggml_set_i32_1d (tokens_input, i, model. hparams . n_vocab /2 );
1297
+ ggml_set_i32_1d (tokens_input, i, n_vocab/2 );
1297
1298
}
1298
1299
1299
1300
for (int i=0 ; i<sample_ctx-1 ; ++i) {
1300
- print_token (ggml_get_i32_1d (tokens_input, i), model. hparams . n_vocab );
1301
+ print_token (ggml_get_i32_1d (tokens_input, i), n_vocab);
1301
1302
}
1302
1303
printf (" ---\n " );
1303
1304
for (int i=0 ; i<n_gen; ++i) {
@@ -1318,15 +1319,15 @@ int main(int argc, char ** argv) {
1318
1319
ggml_graph_compute (ctx0, &gf);
1319
1320
1320
1321
struct ggml_tensor * best_samples = ggml_new_tensor_1d (ctx0, GGML_TYPE_I32, sample_ctx);
1321
- struct ggml_tensor * probs = ggml_new_tensor_2d (ctx0, GGML_TYPE_F32, model. hparams . n_vocab , sample_ctx);
1322
+ struct ggml_tensor * probs = ggml_new_tensor_2d (ctx0, GGML_TYPE_F32, n_vocab, sample_ctx);
1322
1323
1323
1324
sample_softmax (logits, probs, best_samples);
1324
1325
1325
1326
// int sample_at = n_tokens-1;
1326
1327
int token = ggml_get_i32_1d (best_samples, sample_ctx-1 );
1327
1328
1328
1329
// print_probs1(probs, sample_at);
1329
- print_token (token, model. hparams . n_vocab );
1330
+ print_token (token, n_vocab);
1330
1331
1331
1332
lshift_examples (tokens_input, targets, 1 );
1332
1333
ggml_set_i32_1d (tokens_input, 0 , 0 );
0 commit comments