| 71 | } |
| 72 | |
| 73 | int main(int argc, char ** argv) { |
| 74 | common_params params; |
| 75 | |
| 76 | if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_EMBEDDING)) { |
| 77 | return 1; |
| 78 | } |
| 79 | |
| 80 | common_init(); |
| 81 | |
| 82 | params.embedding = true; |
| 83 | |
| 84 | // utilize the full context |
| 85 | if (params.n_batch < params.n_ctx) { |
| 86 | LOG_WRN("%s: setting batch size to %d\n", __func__, params.n_ctx); |
| 87 | params.n_batch = params.n_ctx; |
| 88 | } |
| 89 | |
| 90 | // For non-causal models, batch size must be equal to ubatch size |
| 91 | params.n_ubatch = params.n_batch; |
| 92 | |
| 93 | llama_backend_init(); |
| 94 | llama_numa_init(params.numa); |
| 95 | |
| 96 | // load the model |
| 97 | common_init_result llama_init = common_init_from_params(params); |
| 98 | |
| 99 | llama_model * model = llama_init.model.get(); |
| 100 | llama_context * ctx = llama_init.context.get(); |
| 101 | |
| 102 | if (model == NULL) { |
| 103 | LOG_ERR("%s: unable to load model\n", __func__); |
| 104 | return 1; |
| 105 | } |
| 106 | |
| 107 | const llama_vocab * vocab = llama_model_get_vocab(model); |
| 108 | |
| 109 | const int n_ctx_train = llama_model_n_ctx_train(model); |
| 110 | const int n_ctx = llama_n_ctx(ctx); |
| 111 | |
| 112 | const enum llama_pooling_type pooling_type = llama_pooling_type(ctx); |
| 113 | |
| 114 | if (llama_model_has_encoder(model) && llama_model_has_decoder(model)) { |
| 115 | LOG_ERR("%s: computing embeddings in encoder-decoder models is not supported\n", __func__); |
| 116 | return 1; |
| 117 | } |
| 118 | |
| 119 | if (n_ctx > n_ctx_train) { |
| 120 | LOG_WRN("%s: warning: model was trained on only %d context tokens (%d specified)\n", |
| 121 | __func__, n_ctx_train, n_ctx); |
| 122 | } |
| 123 | |
| 124 | // print system information |
| 125 | { |
| 126 | LOG_INF("\n"); |
| 127 | LOG_INF("%s\n", common_params_get_system_info(params).c_str()); |
| 128 | } |
| 129 | |
| 130 | // split the prompt into lines |
nothing calls this directly
no test coverage detected