Skip to content
Open
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
13 changes: 10 additions & 3 deletions xllm/models/dit/pipelines/pipeline_flux.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class FluxPipelineImpl : public FluxPipelineBaseImpl {
"pos_embed",
FluxPosEmbed(ROPE_SCALE_BASE,
context.get_model_args("transformer").axes_dims_rope()));
transformer_ = FluxDiTModel(context.get_model_context("transformer"));
transformer_ = FluxDiTModel(context.get_model_context("transformer"),
context.get_parallel_args());
t5_ = T5EncoderModel(context.get_model_context("text_encoder_2"));
clip_text_model_ = CLIPTextModel(context.get_model_context("text_encoder"));
scheduler_ =
Expand Down Expand Up @@ -275,6 +276,10 @@ class FluxPipelineImpl : public FluxPipelineBaseImpl {
torch::Tensor image_rotary_emb =
torch::stack({rot_emb1, rot_emb2}, 0).to(options_.dtype());

DiTCache::get_instance().set_context(
{/*infer_steps=*/static_cast<int64_t>(timesteps.numel()),
/*num_blocks=*/transformer_->num_blocks()});

for (int64_t i = 0; i < timesteps.numel(); ++i) {
torch::Tensor t = timesteps[i].unsqueeze(0);
timestep.fill_(t.item<float>())
Expand All @@ -287,7 +292,8 @@ class FluxPipelineImpl : public FluxPipelineBaseImpl {
timestep,
image_rotary_emb,
guidance,
step_id);
step_id,
/*use_cfg=*/false);
if (do_true_cfg) {
torch::Tensor negative_noise_pred =
transformer_->forward(prepared_latents,
Expand All @@ -296,7 +302,8 @@ class FluxPipelineImpl : public FluxPipelineBaseImpl {
timestep,
image_rotary_emb,
guidance,
step_id);
step_id,
/*use_cfg=*/true);
noise_pred =
noise_pred + (noise_pred - negative_noise_pred) * true_cfg_scale;
negative_noise_pred.reset();
Expand Down
6 changes: 5 additions & 1 deletion xllm/models/dit/pipelines/pipeline_flux_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class FluxControlPipelineImpl : public FluxPipelineBaseImpl {
"pos_embed",
FluxPosEmbed(ROPE_SCALE_BASE,
context.get_model_args("transformer").axes_dims_rope()));
transformer_ = FluxDiTModel(context.get_model_context("transformer"));
transformer_ = FluxDiTModel(context.get_model_context("transformer"),
context.get_parallel_args());
t5_ = T5EncoderModel(context.get_model_context("text_encoder_2"));
clip_text_model_ = CLIPTextModel(context.get_model_context("text_encoder"));
scheduler_ =
Expand Down Expand Up @@ -298,6 +299,9 @@ class FluxControlPipelineImpl : public FluxPipelineBaseImpl {
width / (vae_scale_factor_ * 2));
torch::Tensor image_rotary_emb =
torch::stack({rot_emb1, rot_emb2}, 0).to(options_.dtype());
DiTCache::get_instance().set_context(
{/*infer_steps=*/static_cast<int64_t>(timesteps.numel()),
/*num_blocks=*/transformer_->num_blocks()});
for (int64_t i = 0; i < timesteps.numel(); ++i) {
torch::Tensor t = timesteps[i].unsqueeze(0);
timestep.fill_(t.item<float>())
Expand Down
7 changes: 6 additions & 1 deletion xllm/models/dit/pipelines/pipeline_flux_fill.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class FluxFillPipelineImpl : public FluxPipelineBaseImpl {
"pos_embed",
FluxPosEmbed(ROPE_SCALE_BASE,
context.get_model_args("transformer").axes_dims_rope()));
transformer_ = FluxDiTModel(context.get_model_context("transformer"));
transformer_ = FluxDiTModel(context.get_model_context("transformer"),
context.get_parallel_args());
t5_ = T5EncoderModel(context.get_model_context("text_encoder_2"));
clip_text_model_ = CLIPTextModel(context.get_model_context("text_encoder"));
scheduler_ =
Expand Down Expand Up @@ -378,6 +379,10 @@ class FluxFillPipelineImpl : public FluxPipelineBaseImpl {
torch::Tensor image_rotary_emb =
torch::stack({rot_emb1, rot_emb2}, 0).to(options_.dtype());

DiTCache::get_instance().set_context(
{/*infer_steps=*/static_cast<int64_t>(timesteps.size(0)),
/*num_blocks=*/transformer_->num_blocks()});

for (int64_t i = 0; i < timesteps.size(0); ++i) {
torch::Tensor t = timesteps[i];
torch::Tensor timestep =
Expand Down
Loading
Loading