From fe5bb77caf4d5d538317cbcbdeb18a0a907d5835 Mon Sep 17 00:00:00 2001 From: mzegla Date: Thu, 3 Sep 2026 10:44:14 +0200 Subject: [PATCH 1/2] init --- src/llm/servable_initializer.cpp | 21 +++++++++++++++------ src/test/llm/max_model_length_test.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/llm/servable_initializer.cpp b/src/llm/servable_initializer.cpp index 14eb27b29c..b87a4794fa 100644 --- a/src/llm/servable_initializer.cpp +++ b/src/llm/servable_initializer.cpp @@ -532,6 +532,16 @@ Status parseModelsPath(std::string& outPath, std::string modelsPath, std::string return StatusCode::LLM_NODE_PATH_DOES_NOT_EXIST_AND_NOT_GGUFFILE; } +static std::optional findMaxLengthField(const rapidjson::Value& config) { + static const std::vector maxLengthFields = {"max_position_embeddings", "n_positions", "seq_len", "seq_length", "n_ctx", "sliding_window"}; + for (const auto& field : maxLengthFields) { + if (config.HasMember(field.c_str()) && config[field.c_str()].IsUint()) { + return config[field.c_str()].GetUint(); + } + } + return std::nullopt; +} + std::optional parseMaxModelLength(std::string& modelsPath) { std::string configPath = FileSystem::appendSlash(modelsPath) + "config.json"; std::optional maxModelLength; @@ -546,12 +556,11 @@ std::optional parseMaxModelLength(std::string& modelsPath) { if (parseResult.Code()) { return maxModelLength; } - std::vector maxLengthFields = {"max_position_embeddings", "n_positions", "seq_len", "seq_length", "n_ctx", "sliding_window"}; - for (auto field : maxLengthFields) { - if (modelConfig.HasMember(field.c_str()) && modelConfig[field.c_str()].IsUint()) { - maxModelLength = modelConfig[field.c_str()].GetUint(); - break; - } + maxModelLength = findMaxLengthField(modelConfig); + // Composite VLM/omni configs (e.g. Qwen3.5-Omni) nest the language model's + // parameters under "text_config" instead of the top level. + if (!maxModelLength.has_value() && modelConfig.HasMember("text_config") && modelConfig["text_config"].IsObject()) { + maxModelLength = findMaxLengthField(modelConfig["text_config"]); } } return maxModelLength; diff --git a/src/test/llm/max_model_length_test.cpp b/src/test/llm/max_model_length_test.cpp index b48290c539..ba184455cb 100644 --- a/src/test/llm/max_model_length_test.cpp +++ b/src/test/llm/max_model_length_test.cpp @@ -142,3 +142,27 @@ TEST_F(MaxModelLengthTest, maxModelLength_parsingOrder) { ASSERT_TRUE(maxModelLength.has_value()); EXPECT_EQ(maxModelLength.value(), 5); } + +TEST_F(MaxModelLengthTest, maxModelLength_textConfig_VALID) { + // Composite VLM/omni configs (e.g. Qwen3.5-Omni) nest the field under "text_config". + std::string modelConfigContent = R"({"model_type" : "qwen3_5", "text_config" : {"max_position_embeddings" : 262144}})"; + createConfigFileWithContent(modelConfigContent, configFilePath); + auto maxModelLength = parseMaxModelLength(directoryPath); + ASSERT_TRUE(maxModelLength.has_value()); + EXPECT_EQ(maxModelLength.value(), 262144); +} + +TEST_F(MaxModelLengthTest, maxModelLength_topLevelTakesPriorityOverTextConfig) { + std::string modelConfigContent = R"({"max_position_embeddings" : 5, "text_config" : {"max_position_embeddings" : 262144}})"; + createConfigFileWithContent(modelConfigContent, configFilePath); + auto maxModelLength = parseMaxModelLength(directoryPath); + ASSERT_TRUE(maxModelLength.has_value()); + EXPECT_EQ(maxModelLength.value(), 5); +} + +TEST_F(MaxModelLengthTest, maxModelLength_textConfig_notAnObject) { + std::string modelConfigContent = R"({"text_config" : "INVALID"})"; + createConfigFileWithContent(modelConfigContent, configFilePath); + auto maxModelLength = parseMaxModelLength(directoryPath); + EXPECT_FALSE(maxModelLength.has_value()); +} From bfdbc3e9e4b93b83adaf9b301760a1144cfa36bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20=C5=BBeglarski?= Date: Thu, 3 Sep 2026 10:55:06 +0200 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/llm/servable_initializer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/llm/servable_initializer.cpp b/src/llm/servable_initializer.cpp index b87a4794fa..796a38b722 100644 --- a/src/llm/servable_initializer.cpp +++ b/src/llm/servable_initializer.cpp @@ -533,10 +533,14 @@ Status parseModelsPath(std::string& outPath, std::string modelsPath, std::string } static std::optional findMaxLengthField(const rapidjson::Value& config) { + if (!config.IsObject()) { + return std::nullopt; + } static const std::vector maxLengthFields = {"max_position_embeddings", "n_positions", "seq_len", "seq_length", "n_ctx", "sliding_window"}; for (const auto& field : maxLengthFields) { - if (config.HasMember(field.c_str()) && config[field.c_str()].IsUint()) { - return config[field.c_str()].GetUint(); + auto it = config.FindMember(field.c_str()); + if (it != config.MemberEnd() && it->value.IsUint()) { + return it->value.GetUint(); } } return std::nullopt;