| 724 | } |
| 725 | |
| 726 | int main(int argc, char ** argv) { |
| 727 | ggml_time_init(); |
| 728 | |
| 729 | const int64_t t_main_start_us = ggml_time_us(); |
| 730 | |
| 731 | gpt_params params; |
| 732 | params.model = "models/gpt-2-117M/ggml-model.bin"; |
| 733 | |
| 734 | if (gpt_params_parse(argc, argv, params) == false) { |
| 735 | return 1; |
| 736 | } |
| 737 | |
| 738 | if (params.seed < 0) { |
| 739 | params.seed = time(NULL); |
| 740 | } |
| 741 | |
| 742 | printf("%s: seed = %d\n", __func__, params.seed); |
| 743 | |
| 744 | std::mt19937 rng(params.seed); |
| 745 | if (params.prompt.empty()) { |
| 746 | params.prompt = gpt_random_prompt(rng); |
| 747 | } |
| 748 | |
| 749 | int64_t t_load_us = 0; |
| 750 | |
| 751 | gpt_vocab vocab; |
| 752 | gpt2_model model; |
| 753 | |
| 754 | // load the model |
| 755 | { |
| 756 | const int64_t t_start_us = ggml_time_us(); |
| 757 | |
| 758 | if (!gpt2_model_load(params.model, model, vocab)) { |
| 759 | fprintf(stderr, "%s: failed to load model from '%s'\n", __func__, params.model.c_str()); |
| 760 | return 1; |
| 761 | } |
| 762 | |
| 763 | t_load_us = ggml_time_us() - t_start_us; |
| 764 | |
| 765 | test_gpt_tokenizer(vocab, params.token_test); |
| 766 | } |
| 767 | |
| 768 | ggml_gallocr_t allocr = NULL; |
| 769 | // allocate the compute buffer |
| 770 | { |
| 771 | allocr = ggml_gallocr_new(ggml_backend_cpu_buffer_type()); |
| 772 | |
| 773 | // create the worst case graph for memory usage estimation |
| 774 | int n_tokens = std::min(model.hparams.n_ctx, params.n_batch); |
| 775 | int n_past = model.hparams.n_ctx - n_tokens; |
| 776 | struct ggml_cgraph * gf = gpt2_graph(model, n_past, n_tokens); |
| 777 | |
| 778 | // pre-allocate the compute buffer for the worst case (optional) |
| 779 | ggml_gallocr_reserve(allocr, gf); |
| 780 | size_t mem_size = ggml_gallocr_get_buffer_size(allocr, 0); |
| 781 | fprintf(stderr, "%s: compute buffer size: %.2f MB\n", __func__, mem_size/1024.0/1024.0); |
| 782 | } |
| 783 |
nothing calls this directly
no test coverage detected