@@ -706,11 +706,17 @@ bool fs_validate_filename(const std::string & filename) {
706706 // disable C++17 deprecation warning for std::codecvt_utf8
707707# pragma clang diagnostic push
708708# pragma clang diagnostic ignored "-Wdeprecated-declarations"
709+ #elif defined(__GNUC__)
710+ # pragma GCC diagnostic push
711+ # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
709712#endif
713+
710714 std::wstring_convert<std::codecvt_utf8<char32_t >, char32_t > converter;
711715
712716#if defined(__clang__)
713717# pragma clang diagnostic pop
718+ #elif defined(__GNUC__)
719+ # pragma GCC diagnostic pop
714720#endif
715721
716722 filename_utf32 = converter.from_bytes (filename);
@@ -767,6 +773,9 @@ bool fs_validate_filename(const std::string & filename) {
767773 return true ;
768774}
769775
776+ #include < iostream>
777+
778+
770779// returns true if successful, false otherwise
771780bool fs_create_directory_with_parents (const std::string & path) {
772781#ifdef _WIN32
@@ -784,9 +793,16 @@ bool fs_create_directory_with_parents(const std::string & path) {
784793 // process path from front to back, procedurally creating directories
785794 while ((pos_slash = path.find (' \\ ' , pos_slash)) != std::string::npos) {
786795 const std::wstring subpath = wpath.substr (0 , pos_slash);
787- const wchar_t * test = subpath.c_str ();
788796
789- const bool success = CreateDirectoryW (test, NULL );
797+ pos_slash += 1 ;
798+
799+ // skip the drive letter, in some systems it can return an access denied error
800+ if (subpath.length () == 2 && subpath[1 ] == ' :' ) {
801+ continue ;
802+ }
803+
804+ const bool success = CreateDirectoryW (subpath.c_str (), NULL );
805+
790806 if (!success) {
791807 const DWORD error = GetLastError ();
792808
@@ -800,8 +816,6 @@ bool fs_create_directory_with_parents(const std::string & path) {
800816 return false ;
801817 }
802818 }
803-
804- pos_slash += 1 ;
805819 }
806820
807821 return true ;
@@ -897,34 +911,6 @@ struct common_init_result common_init_from_params(common_params & params) {
897911
898912 const llama_vocab * vocab = llama_model_get_vocab (model);
899913
900- if (params.reranking ) {
901- bool ok = true ;
902-
903- if (llama_vocab_bos (vocab) == LLAMA_TOKEN_NULL) {
904- LOG_WRN (" %s: warning: vocab does not have a BOS token, reranking will not work\n " , __func__);
905- ok = false ;
906- }
907-
908- bool has_eos = llama_vocab_eos (vocab) != LLAMA_TOKEN_NULL;
909- bool has_sep = llama_vocab_sep (vocab) != LLAMA_TOKEN_NULL;
910-
911- if (!has_eos && !has_sep) {
912- LOG_WRN (" %s: warning: vocab does not have an EOS token or SEP token, reranking will not work\n " , __func__);
913- ok = false ;
914- } else if (!has_eos) {
915- LOG_WRN (" %s: warning: vocab does not have an EOS token, using SEP token as fallback\n " , __func__);
916- } else if (!has_sep) {
917- LOG_WRN (" %s: warning: vocab does not have a SEP token, reranking will not work\n " , __func__);
918- ok = false ;
919- }
920-
921- if (!ok) {
922- llama_model_free (model);
923-
924- return iparams;
925- }
926- }
927-
928914 auto cparams = common_context_params_to_llama (params);
929915
930916 llama_context * lctx = llama_init_from_model (model, cparams);
@@ -966,6 +952,35 @@ struct common_init_result common_init_from_params(common_params & params) {
966952 }
967953 }
968954
955+ if (llama_pooling_type (lctx) == LLAMA_POOLING_TYPE_RANK) {
956+ bool ok = true ;
957+
958+ if (llama_vocab_bos (vocab) == LLAMA_TOKEN_NULL) {
959+ LOG_WRN (" %s: warning: vocab does not have a BOS token, reranking will not work\n " , __func__);
960+ ok = false ;
961+ }
962+
963+ bool has_eos = llama_vocab_eos (vocab) != LLAMA_TOKEN_NULL;
964+ bool has_sep = llama_vocab_sep (vocab) != LLAMA_TOKEN_NULL;
965+
966+ if (!has_eos && !has_sep) {
967+ LOG_WRN (" %s: warning: vocab does not have an EOS token or SEP token, reranking will not work\n " , __func__);
968+ ok = false ;
969+ } else if (!has_eos) {
970+ LOG_WRN (" %s: warning: vocab does not have an EOS token, using SEP token as fallback\n " , __func__);
971+ } else if (!has_sep) {
972+ LOG_WRN (" %s: warning: vocab does not have a SEP token, reranking will not work\n " , __func__);
973+ ok = false ;
974+ }
975+
976+ if (!ok) {
977+ llama_free (lctx);
978+ llama_model_free (model);
979+
980+ return iparams;
981+ }
982+ }
983+
969984 // load and optionally apply lora adapters
970985 for (auto & la : params.lora_adapters ) {
971986 llama_adapter_lora_ptr lora;
@@ -1143,11 +1158,6 @@ struct llama_context_params common_context_params_to_llama(const common_params &
11431158 cparams.op_offload = !params.no_op_offload ;
11441159 cparams.swa_full = params.swa_full ;
11451160
1146- if (params.reranking ) {
1147- cparams.embeddings = true ;
1148- cparams.pooling_type = LLAMA_POOLING_TYPE_RANK;
1149- }
1150-
11511161 cparams.type_k = params.cache_type_k ;
11521162 cparams.type_v = params.cache_type_v ;
11531163
@@ -1280,6 +1290,9 @@ std::vector<llama_token> common_tokenize(
12801290 int n_tokens = text.length () + 2 * add_special;
12811291 std::vector<llama_token> result (n_tokens);
12821292 n_tokens = llama_tokenize (vocab, text.data (), text.length (), result.data (), result.size (), add_special, parse_special);
1293+ if (n_tokens == std::numeric_limits<int32_t >::min ()) {
1294+ throw std::runtime_error (" Tokenization failed: input text too large, tokenization result exceeds int32_t limit" );
1295+ }
12831296 if (n_tokens < 0 ) {
12841297 result.resize (-n_tokens);
12851298 int check = llama_tokenize (vocab, text.data (), text.length (), result.data (), result.size (), add_special, parse_special);
0 commit comments