mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-26 23:29:53 +00:00
fix: restore Qwen Image 2.1 prefix caching in DGL (#2405)
This commit is contained in:
parent
5b80e1f2d5
commit
91ed00931f
3 changed files with 9 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef __SD_DGL_MODELS_DIFFUSION_PREDICTION_H__
|
||||
#define __SD_DGL_MODELS_DIFFUSION_PREDICTION_H__
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
|
|
@ -64,6 +65,7 @@ namespace sd::dgl::models {
|
|||
const AttentionProcessor* attn2_processor = nullptr;
|
||||
const FluxImageBlockProcessor* flux_image_processor = nullptr;
|
||||
const UNetBlockProcessor* unet_block_processor = nullptr;
|
||||
uint64_t qwen_prefix_id = 0;
|
||||
|
||||
void blend_mask(Tensor<float>& latent) const {
|
||||
if (!mask.empty())
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ namespace sd::dgl::models {
|
|||
} else if (version() == VERSION_FLUX3) {
|
||||
params.extra = Flux3DiffusionExtra{present(target_time)};
|
||||
} else if (version() == VERSION_QWEN_IMAGE_2_1) {
|
||||
params.extra = QwenImage21DiffusionExtra{&condition.c_token_types};
|
||||
params.extra = QwenImage21DiffusionExtra{&condition.c_token_types, step.qwen_prefix_id};
|
||||
} else if (sd_version_is_anima(version())) {
|
||||
params.extra = AnimaDiffusionExtra{present(condition.c_t5_ids), present(condition.c_t5_weights)};
|
||||
} else if (sd_version_is_wan(version())) {
|
||||
|
|
|
|||
|
|
@ -167,6 +167,7 @@ namespace sd::dgl::ops {
|
|||
const PredictionExecutionOptions options;
|
||||
std::map<models::Model*, PreparedModel> prepared;
|
||||
std::map<const ModelPredictor*, ConditioningWindows> windows;
|
||||
std::map<const ModelPredictor*, uint64_t> qwen_prefix_ids;
|
||||
std::map<const models::DenoisingParameterization*, sd_sample::ConditionCacheRuntime> caches;
|
||||
std::map<const ModelPredictor*, ActiveConditioning> previous_conditioning;
|
||||
IPAdapterCache ip_adapter_cache;
|
||||
|
|
@ -227,6 +228,9 @@ namespace sd::dgl::ops {
|
|||
resources.add_windows(model->controls, windows.controls);
|
||||
resources.add_windows(model->ip_adapters, windows.ip_adapters);
|
||||
resources.add_windows(model->pulid, windows.pulid);
|
||||
} else if (model->dit().version() == VERSION_QWEN_IMAGE_2_1) {
|
||||
// This leaf's text, image slots and references are fixed for the sample.
|
||||
resources.qwen_prefix_ids.emplace(model, resources.qwen_prefix_ids.size() + 1);
|
||||
}
|
||||
} else if (const auto* branches = guidance_branches(predictor)) {
|
||||
self(self, *branches->positive);
|
||||
|
|
@ -449,6 +453,8 @@ namespace sd::dgl::ops {
|
|||
PuLIDAttention pulid(active_pulid, pulid_cache);
|
||||
if (!active_pulid.empty())
|
||||
step.flux_image_processor = &pulid;
|
||||
const auto prefix = qwen_prefix_ids.find(&leaf);
|
||||
step.qwen_prefix_id = prefix == qwen_prefix_ids.end() ? 0 : prefix->second;
|
||||
sd::ParallelScope tensor_scope(engine.tensor_executor.get());
|
||||
auto prediction = engine.predict_diffusion(x, leaf.resolved_parameterization(), sigma, leaf.condition, leaf.references,
|
||||
leaf.options, step);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue