feat: add configurable conditioning cache for all models (#2034)

This commit is contained in:
leejet authored and GitHub committed 2026-09-23 22:25:42 +08:00
1 parent 241518b35d
commit e6281b6318
12 files changed
+172 -51

No files matched your search

-31
View File
@@ -137,7 +137,6 @@ struct ConditionerParams {
const std::vector<sd::Tensor<float>>* ref_images = nullptr; // for qwen image edit
const std::vector<MiniMaxH3PresentationItem>* minimax_h3_references = nullptr;
RefImageParams ref_image_params;
bool allow_cache = false;
};
struct Conditioner {
@@ -1955,10 +1954,6 @@ struct LLMEmbedder : public Conditioner {
std::shared_ptr<LLM::LLMRunner> llm;
std::shared_ptr<T5Runner> byt5;
bool h3_text_cache_valid = false;
std::string h3_text_cache_text;
SDCondition h3_text_cache;
LLMEmbedder(ggml_backend_t backend,
const String2TensorStorage& tensor_storage_map = {},
SDVersion version = VERSION_QWEN_IMAGE,
@@ -2303,25 +2298,6 @@ struct LLMEmbedder : public Conditioner {
SDCondition get_learned_condition(int n_threads,
const ConditionerParams& conditioner_params) override {
const bool h3_text_cacheable =
sd_version_is_minimax_h3(version) &&
conditioner_params.allow_cache &&
(conditioner_params.minimax_h3_references == nullptr ||
conditioner_params.minimax_h3_references->empty()) &&
(conditioner_params.ref_images == nullptr ||
conditioner_params.ref_images->empty());
if (sd_version_is_minimax_h3(version) && !h3_text_cacheable) {
h3_text_cache_valid = false;
}
if (h3_text_cacheable &&
h3_text_cache_valid &&
h3_text_cache_text == conditioner_params.text) {
LOG_INFO("H3 conditioning cache hit");
return h3_text_cache;
}
std::string prompt;
std::pair<int, int> prompt_attn_range;
std::vector<std::string> extra_prompts;
@@ -3191,13 +3167,6 @@ struct LLMEmbedder : public Conditioner {
result.c_token_types = sd::Tensor<int32_t>({tag_count}, std::move(tags));
}
if (h3_text_cacheable) {
h3_text_cache_text = conditioner_params.text;
h3_text_cache = result;
h3_text_cache_valid = true;
LOG_INFO("H3 conditioning cache stored");
}
return result;
}
};