@@ -125,15 +125,16 @@ def forward(
125125 elif self .text_encoder :
126126 # if a text encoder is provided, e.g. Qwen-Image-Edit
127127 # 1. neg prompt embeds
128- neg_image_processor_kwargs = (
129- server_args .pipeline_config .prepare_image_processor_kwargs (
130- batch , neg = True
128+ if batch .do_classifier_free_guidance :
129+ neg_image_processor_kwargs = (
130+ server_args .pipeline_config .prepare_image_processor_kwargs (
131+ batch , neg = True
132+ )
131133 )
132- )
133134
134- neg_image_inputs = self .image_processor (
135- images = image , return_tensors = "pt" , ** neg_image_processor_kwargs
136- ).to (cuda_device )
135+ neg_image_inputs = self .image_processor (
136+ images = image , return_tensors = "pt" , ** neg_image_processor_kwargs
137+ ).to (cuda_device )
137138
138139 with set_forward_context (current_timestep = 0 , attn_metadata = None ):
139140 outputs = self .text_encoder (
@@ -143,20 +144,22 @@ def forward(
143144 image_grid_thw = image_inputs .image_grid_thw ,
144145 output_hidden_states = True ,
145146 )
146- neg_outputs = self .text_encoder (
147- input_ids = neg_image_inputs .input_ids ,
148- attention_mask = neg_image_inputs .attention_mask ,
149- pixel_values = neg_image_inputs .pixel_values ,
150- image_grid_thw = neg_image_inputs .image_grid_thw ,
151- output_hidden_states = True ,
152- )
147+ if batch .do_classifier_free_guidance :
148+ neg_outputs = self .text_encoder (
149+ input_ids = neg_image_inputs .input_ids ,
150+ attention_mask = neg_image_inputs .attention_mask ,
151+ pixel_values = neg_image_inputs .pixel_values ,
152+ image_grid_thw = neg_image_inputs .image_grid_thw ,
153+ output_hidden_states = True ,
154+ )
153155 batch .prompt_embeds .append (
154156 self .encoding_qwen_image_edit (outputs , image_inputs )
155157 )
156158
157- batch .negative_prompt_embeds .append (
158- self .encoding_qwen_image_edit (neg_outputs , neg_image_inputs )
159- )
159+ if batch .do_classifier_free_guidance :
160+ batch .negative_prompt_embeds .append (
161+ self .encoding_qwen_image_edit (neg_outputs , neg_image_inputs )
162+ )
160163
161164 self .offload_model ()
162165
0 commit comments