@@ -2039,8 +2039,8 @@ std::string fs_get_cache_file(const std::string & filename) {
20392039//
20402040// Model utils
20412041//
2042-
2043- std::tuple< struct llama_model *, struct llama_context *> llama_init_from_gpt_params (gpt_params & params) {
2042+ struct llama_init_result llama_init_from_gpt_params (gpt_params & params) {
2043+ llama_init_result iparams;
20442044 auto mparams = llama_model_params_from_gpt_params (params);
20452045
20462046 llama_model * model = nullptr ;
@@ -2055,7 +2055,7 @@ std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_par
20552055
20562056 if (model == NULL ) {
20572057 fprintf (stderr, " %s: error: failed to load model '%s'\n " , __func__, params.model .c_str ());
2058- return std::make_tuple ( nullptr , nullptr ) ;
2058+ return iparams ;
20592059 }
20602060
20612061 auto cparams = llama_context_params_from_gpt_params (params);
@@ -2064,7 +2064,7 @@ std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_par
20642064 if (lctx == NULL ) {
20652065 fprintf (stderr, " %s: error: failed to create context with model '%s'\n " , __func__, params.model .c_str ());
20662066 llama_free_model (model);
2067- return std::make_tuple ( nullptr , nullptr ) ;
2067+ return iparams ;
20682068 }
20692069
20702070 if (!params.control_vectors .empty ()) {
@@ -2075,7 +2075,7 @@ std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_par
20752075 if (cvec.n_embd == -1 ) {
20762076 llama_free (lctx);
20772077 llama_free_model (model);
2078- return std::make_tuple ( nullptr , nullptr ) ;
2078+ return iparams ;
20792079 }
20802080
20812081 int err = llama_control_vector_apply (lctx,
@@ -2087,7 +2087,7 @@ std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_par
20872087 if (err) {
20882088 llama_free (lctx);
20892089 llama_free_model (model);
2090- return std::make_tuple ( nullptr , nullptr ) ;
2090+ return iparams ;
20912091 }
20922092 }
20932093
@@ -2099,7 +2099,7 @@ std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_par
20992099 fprintf (stderr, " %s: error: failed to apply lora adapter\n " , __func__);
21002100 llama_free (lctx);
21012101 llama_free_model (model);
2102- return std::make_tuple ( nullptr , nullptr ) ;
2102+ return iparams ;
21032103 }
21042104 llama_lora_adapter_set (lctx, adapter, lora_scale);
21052105 }
@@ -2135,7 +2135,9 @@ std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_par
21352135 llama_reset_timings (lctx);
21362136 }
21372137
2138- return std::make_tuple (model, lctx);
2138+ iparams.model = model;
2139+ iparams.context = lctx;
2140+ return iparams;
21392141}
21402142
21412143struct llama_model_params llama_model_params_from_gpt_params (const gpt_params & params) {
0 commit comments