embd-input-test.cpp 952 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "embd-input.h"
  2. #include <stdlib.h>
  3. #include <random>
  4. #include <string.h>
  5. int main(int argc, char** argv) {
  6. auto mymodel = create_mymodel(argc, argv);
  7. int N = 10;
  8. int max_tgt_len = 500;
  9. int n_embd = llama_n_embd(mymodel->ctx);
  10. // add random float embd to test evaluation
  11. float * data = new float[N*n_embd];
  12. std::default_random_engine e;
  13. std::uniform_real_distribution<float> u(0,1);
  14. for (int i=0;i<N*n_embd;i++) {
  15. data[i] = u(e);
  16. }
  17. eval_string(mymodel, "user: what is the color of the flag of UN?");
  18. eval_float(mymodel, data, N);
  19. eval_string(mymodel, "assistant:");
  20. eval_string(mymodel, mymodel->params.prompt.c_str());
  21. const char* tmp;
  22. for (int i=0; i<max_tgt_len; i++) {
  23. tmp = sampling(mymodel);
  24. if (strcmp(tmp, "</s>")==0) break;
  25. printf("%s", tmp);
  26. fflush(stdout);
  27. }
  28. printf("\n");
  29. free_mymodel(mymodel);
  30. return 0;
  31. }