Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dgl/models/diffusion_prediction.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef __SD_DGL_MODELS_DIFFUSION_PREDICTION_H__
#define __SD_DGL_MODELS_DIFFUSION_PREDICTION_H__

#include <cstdint>
#include <functional>
#include <limits>

Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/dgl/models/dit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down
6 changes: 6 additions & 0 deletions src/dgl/ops/predictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading