diff --git a/src/core/util.cpp b/src/core/util.cpp index ff53c65fc..ce97546c9 100644 --- a/src/core/util.cpp +++ b/src/core/util.cpp @@ -801,7 +801,11 @@ std::vector> parse_prompt_attention(const std::str float round_bracket_multiplier = 1.1f; float square_bracket_multiplier = 1 / 1.1f; - std::regex re_attention(R"(\\\(|\\\)|\\\[|\\\]|\\\\|\\|\(|\[|:([+-]?[.\d]+)\)|\)|\]|\bBREAK\b|[^\\()\[\]:B]+|:|\bB)"); + // libstdc++ std::regex recurses per matched character; unbounded runs overflow + // the stack. Split runs are merged back by the equal-weight pass below. + const int max_plain_text_run = 1024; + std::regex re_attention(R"(\\\(|\\\)|\\\[|\\\]|\\\\|\\|\(|\[|:([+-]?[.\d]+)\)|\)|\]|\bBREAK\b|[^\\()\[\]:B]{1,)" + + std::to_string(max_plain_text_run) + R"(}|:|\bB)"); std::regex re_break(R"(\s*\bBREAK\b\s*)"); auto multiply_range = [&](int start_position, float multiplier) {