Skip to content

Commit 88b044b

Browse files
authored
fix: mark graph cuts with both a prefix and a suffix (#1883)
1 parent 1706b32 commit 88b044b

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/core/ggml_graph_cut.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,12 @@ namespace sd::ggml_graph_cut {
453453
if (tensor == nullptr || tensor->name[0] == '\0') {
454454
return false;
455455
}
456-
return std::strncmp(tensor->name, GGML_RUNNER_CUT_PREFIX, std::strlen(GGML_RUNNER_CUT_PREFIX)) == 0;
456+
return starts_with(tensor->name, GGML_RUNNER_CUT_PREFIX) &&
457+
ends_with(tensor->name, GGML_RUNNER_CUT_SUFFIX);
457458
}
458459

459460
std::string make_graph_cut_name(const std::string& group, const std::string& output) {
460-
return std::string(GGML_RUNNER_CUT_PREFIX) + group + "|" + output;
461+
return std::string(GGML_RUNNER_CUT_PREFIX) + group + "|" + output + GGML_RUNNER_CUT_SUFFIX;
461462
}
462463

463464
void mark_graph_cut(ggml_tensor* tensor, const std::string& group, const std::string& output) {
@@ -783,7 +784,9 @@ namespace sd::ggml_graph_cut {
783784

784785
plan.has_cuts = true;
785786
std::string full_name(node->name);
786-
std::string payload = full_name.substr(std::strlen(GGML_RUNNER_CUT_PREFIX));
787+
size_t prefix_len = std::strlen(GGML_RUNNER_CUT_PREFIX);
788+
size_t suffix_len = std::strlen(GGML_RUNNER_CUT_SUFFIX);
789+
std::string payload = full_name.substr(prefix_len, full_name.size() - prefix_len - suffix_len);
787790
size_t sep = payload.find('|');
788791
std::string group = sep == std::string::npos ? payload : payload.substr(0, sep);
789792

src/core/ggml_graph_cut.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace sd::ggml_graph_cut {
6868
};
6969

7070
static constexpr const char* GGML_RUNNER_CUT_PREFIX = "ggml_runner_cut:";
71+
static constexpr const char* GGML_RUNNER_CUT_SUFFIX = "|";
7172

7273
struct MaxVramAssignment {
7374
float default_gib = 0.f;

0 commit comments

Comments
 (0)