Skip to content

Commit 84fc544

Browse files
authored
fix: skip empty prompt segments around attention range (#1429)
1 parent 1b4e9be commit 84fc544

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/conditioner.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,14 +1673,18 @@ struct LLMEmbedder : public Conditioner {
16731673
size_t max_length = 100000000) {
16741674
std::vector<std::pair<std::string, float>> parsed_attention;
16751675
if (attn_range.first >= 0 && attn_range.second > 0) {
1676-
parsed_attention.emplace_back(text.substr(0, attn_range.first), 1.f);
1676+
if (attn_range.first > 0) {
1677+
parsed_attention.emplace_back(text.substr(0, attn_range.first), 1.f);
1678+
}
16771679
if (attn_range.second - attn_range.first > 0) {
16781680
auto new_parsed_attention = parse_prompt_attention(text.substr(attn_range.first, attn_range.second - attn_range.first));
16791681
parsed_attention.insert(parsed_attention.end(),
16801682
new_parsed_attention.begin(),
16811683
new_parsed_attention.end());
16821684
}
1683-
parsed_attention.emplace_back(text.substr(attn_range.second), 1.f);
1685+
if (attn_range.second < text.size()) {
1686+
parsed_attention.emplace_back(text.substr(attn_range.second), 1.f);
1687+
}
16841688
} else {
16851689
parsed_attention.emplace_back(text, 1.f);
16861690
}

0 commit comments

Comments
 (0)