| 95 | } |
| 96 | |
| 97 | int main(int argc, char ** argv) { |
| 98 | std::setlocale(LC_NUMERIC, "C"); |
| 99 | |
| 100 | common_params params; |
| 101 | |
| 102 | common_init(); |
| 103 | |
| 104 | if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_EMBEDDING)) { |
| 105 | return 1; |
| 106 | } |
| 107 | |
| 108 | params.embedding = true; |
| 109 | |
| 110 | // get max number of sequences per batch |
| 111 | const int n_seq_max = llama_max_parallel_sequences(); |
| 112 | |
| 113 | // if the number of prompts that would be encoded is known in advance, it's more efficient to specify the |
| 114 | // --parallel argument accordingly. for convenience, if not specified, we fallback to unified KV cache |
| 115 | // in order to support any number of prompts |
| 116 | if (params.n_parallel == 1) { |
| 117 | LOG_INF("%s: n_parallel == 1 -> unified KV cache is enabled\n", __func__); |
| 118 | params.kv_unified = true; |
| 119 | params.n_parallel = n_seq_max; |
| 120 | } |
| 121 | |
| 122 | // utilize the full context |
| 123 | if (params.n_batch < params.n_ctx) { |
| 124 | LOG_WRN("%s: setting batch size to %d\n", __func__, params.n_ctx); |
| 125 | params.n_batch = params.n_ctx; |
| 126 | } |
| 127 | |
| 128 | // for non-causal models, batch size must be equal to ubatch size |
| 129 | if (params.attention_type != LLAMA_ATTENTION_TYPE_CAUSAL) { |
| 130 | params.n_ubatch = params.n_batch; |
| 131 | } |
| 132 | |
| 133 | llama_backend_init(); |
| 134 | llama_numa_init(params.numa); |
| 135 | |
| 136 | // load the model |
| 137 | auto llama_init = common_init_from_params(params); |
| 138 | |
| 139 | auto * model = llama_init->model(); |
| 140 | auto * ctx = llama_init->context(); |
| 141 | |
| 142 | if (model == NULL) { |
| 143 | LOG_ERR("%s: unable to load model\n", __func__); |
| 144 | return 1; |
| 145 | } |
| 146 | |
| 147 | const llama_vocab * vocab = llama_model_get_vocab(model); |
| 148 | |
| 149 | const int n_ctx_train = llama_model_n_ctx_train(model); |
| 150 | const int n_ctx = llama_n_ctx(ctx); |
| 151 | |
| 152 | const enum llama_pooling_type pooling_type = llama_pooling_type(ctx); |
| 153 | |
| 154 | if (llama_model_has_encoder(model) && llama_model_has_decoder(model)) { |
nothing calls this directly
no test coverage detected