Skip to content

Commit 50f3419

Browse files
Fix/max context length (#1370)
* fix/mistral-nemo-chat-template * Fix: set max context length to 8192 * Fix: CI build window * Fix: CI build window * Fix: log download and CI build window * Fix: CI build window * Fix: CI build window * Fix: download log for model and engines
1 parent 5c2cae1 commit 50f3419

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

engine/config/gguf_parser.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <algorithm>
12
#include <cstdint>
23
#include <cstring>
34
#include <ctime>
@@ -12,6 +13,7 @@
1213
#ifdef _WIN32
1314
#include <io.h>
1415
#include <windows.h>
16+
#include <limits>
1517
#else
1618
#include <sys/mman.h> // For memory-mapped file
1719
#include <unistd.h> // For file descriptors
@@ -25,6 +27,9 @@
2527
#include "trantor/utils/Logger.h"
2628

2729
namespace config {
30+
#define NOMINMAX
31+
constexpr int kDefaultMaxContextLength = 8192;
32+
2833
void GGUFHandler::OpenFile(const std::string& file_path) {
2934
#ifdef _WIN32
3035
HANDLE file_handle_ = INVALID_HANDLE_VALUE;
@@ -582,8 +587,8 @@ void GGUFHandler::ModelConfigFromMetadata() {
582587
model_config_.model = name;
583588
model_config_.id = name;
584589
model_config_.version = std::to_string(version);
585-
model_config_.max_tokens = max_tokens;
586-
model_config_.ctx_len = max_tokens;
590+
model_config_.max_tokens = std::min<int>(kDefaultMaxContextLength, max_tokens);
591+
model_config_.ctx_len = std::min<int>(kDefaultMaxContextLength, max_tokens);
587592
model_config_.ngl = ngl;
588593
}
589594

engine/services/download_service.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ cpp::result<void, std::string> DownloadService::AddDownloadTask(
7474
}
7575
}
7676
if (dl_err_msg.has_value()) {
77-
CTL_ERR(dl_err_msg.value());
77+
// CTL_ERR(dl_err_msg.value());
7878
return cpp::fail(dl_err_msg.value());
7979
}
8080

@@ -183,7 +183,7 @@ cpp::result<void, std::string> DownloadService::Download(
183183
CLI_LOG("Resuming download..");
184184
} else {
185185
CLI_LOG("Start over..");
186-
return {};
186+
return cpp::fail("Cancelled Resume download!");
187187
}
188188
} else {
189189
CLI_LOG(download_item.localPath.filename().string()
@@ -195,7 +195,7 @@ cpp::result<void, std::string> DownloadService::Download(
195195
if (answer == "Y" || answer == "y" || answer.empty()) {
196196
CLI_LOG("Re-downloading..");
197197
} else {
198-
return {};
198+
return cpp::fail("Cancelled Re-download!");
199199
}
200200
}
201201
}
@@ -232,7 +232,6 @@ cpp::result<void, std::string> DownloadService::Download(
232232

233233
fclose(file);
234234
curl_easy_cleanup(curl);
235-
CLI_LOG("Model " << download_id << " downloaded successfully!")
236235
return {};
237236
}
238237

engine/services/download_service.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ class DownloadService {
7777
cpp::result<void, std::string> VerifyDownloadTask(
7878
DownloadTask& task) const noexcept;
7979

80-
cpp::result<void, std::string> Download(const std::string& download_id,
81-
const DownloadItem& download_item,
82-
bool allow_resume) noexcept;
80+
cpp::result<void, std::string> Download(
81+
const std::string& download_id, const DownloadItem& download_item,
82+
bool allow_resume) noexcept;
8383

8484
curl_off_t GetLocalFileSize(const std::filesystem::path& path) const;
8585
};

engine/services/model_service.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,10 @@ cpp::result<std::string, std::string> ModelService::HandleUrl(
239239
} else {
240240
auto result = download_service_.AddDownloadTask(downloadTask, on_finished);
241241
if (result.has_error()) {
242-
CTL_ERR(result.error());
242+
// CTL_ERR(result.error());
243243
return cpp::fail(result.error());
244+
} else {
245+
CLI_LOG("Model " << model_id << " downloaded successfully!")
244246
}
245247
return unique_model_id;
246248
}
@@ -292,6 +294,8 @@ cpp::result<std::string, std::string> ModelService::DownloadModelFromCortexso(
292294

293295
if (result.has_error()) {
294296
return cpp::fail(result.error());
297+
} else {
298+
CLI_LOG("Model " << model_id << " downloaded successfully!")
295299
}
296300

297301
return model_id;

0 commit comments

Comments
 (0)