[REFACT]Refactor diffusion outputs to payload metadata (#4922)
Signed-off-by: bjf-frz <frz123db@gmail.com>
This commit is contained in:
1 parent
4b9d09cb87
commit
1a4a042a83
44 files changed
+1373
-478
No files matched your search
@@ -331,7 +331,10 @@ def _run_offline(deploy_config_path: str, output_path: Path) -> tuple[Image.Imag
|
||||
if ro and getattr(ro, "outputs", None):
|
||||
cot_text = "".join(getattr(o, "text", "") or "" for o in ro.outputs)
|
||||
if not cot_text:
|
||||
ar_text = getattr(out, "custom_output", {}).get("ar_generated_text")
|
||||
multimodal_output = getattr(out, "multimodal_output", {}) or {}
|
||||
metadata = multimodal_output.get("metadata", {}) if isinstance(multimodal_output, dict) else {}
|
||||
text_metadata = metadata.get("text", {}) if isinstance(metadata, dict) else {}
|
||||
ar_text = text_metadata.get("ar_generated_text") if isinstance(text_metadata, dict) else None
|
||||
if isinstance(ar_text, list):
|
||||
cot_text = "\n".join(text for text in ar_text if text)
|
||||
else:
|
||||
|
||||
@@ -288,7 +288,7 @@ class QwenImagePipelineWithLogProbForTest(QwenImagePipeline):
|
||||
else:
|
||||
# Both prompt_ids and prompt_embeds are None (e.g. during warmup/dummy run).
|
||||
# Return a minimal dummy output to avoid crashing.
|
||||
return DiffusionOutput(output=None, custom_output={})
|
||||
return DiffusionOutput(output=None)
|
||||
|
||||
if isinstance(negative_prompt_ids, list):
|
||||
negative_prompt_ids = torch.tensor(negative_prompt_ids, device=self.device)
|
||||
@@ -399,14 +399,20 @@ class QwenImagePipelineWithLogProbForTest(QwenImagePipeline):
|
||||
image = self.vae.decode(latents, return_dict=False)[0][:, :, 0]
|
||||
|
||||
return DiffusionOutput(
|
||||
output=_maybe_to_cpu(image),
|
||||
output={
|
||||
"payload": {
|
||||
"image": _maybe_to_cpu(image),
|
||||
},
|
||||
"metadata": {
|
||||
"prompt_embeddings": {
|
||||
"prompt_embeds": _maybe_to_cpu(prompt_embeds),
|
||||
"prompt_embeds_mask": _maybe_to_cpu(prompt_embeds_mask),
|
||||
"negative_prompt_embeds": _maybe_to_cpu(negative_prompt_embeds),
|
||||
"negative_prompt_embeds_mask": _maybe_to_cpu(negative_prompt_embeds_mask),
|
||||
},
|
||||
},
|
||||
},
|
||||
trajectory_latents=_maybe_to_cpu(all_latents),
|
||||
trajectory_log_probs=_maybe_to_cpu(all_log_probs),
|
||||
trajectory_timesteps=_maybe_to_cpu(all_timesteps),
|
||||
custom_output={
|
||||
"prompt_embeds": _maybe_to_cpu(prompt_embeds),
|
||||
"prompt_embeds_mask": _maybe_to_cpu(prompt_embeds_mask),
|
||||
"negative_prompt_embeds": _maybe_to_cpu(negative_prompt_embeds),
|
||||
"negative_prompt_embeds_mask": _maybe_to_cpu(negative_prompt_embeds_mask),
|
||||
},
|
||||
)
|
||||
@@ -390,20 +390,23 @@ class vLLMOmniHttpServerLocal:
|
||||
|
||||
diffusion_output = self._to_tensor(final_res.images[0]).float() / 255.0
|
||||
|
||||
mm_output = final_res.custom_output or {}
|
||||
metadata = (
|
||||
final_res.multimodal_output.get("metadata", {}) if isinstance(final_res.multimodal_output, dict) else {}
|
||||
)
|
||||
prompt_embeddings = metadata.get("prompt_embeddings", {}) if isinstance(metadata, dict) else {}
|
||||
|
||||
if sampling_params.get("logprobs", False):
|
||||
all_log_probs = mm_output.get("all_log_probs")
|
||||
all_log_probs = final_res.trajectory_log_probs
|
||||
log_probs = all_log_probs[0] if all_log_probs is not None else None
|
||||
else:
|
||||
log_probs = None
|
||||
|
||||
all_latents = mm_output.get("all_latents")
|
||||
all_timesteps = mm_output.get("all_timesteps")
|
||||
prompt_embeds = mm_output.get("prompt_embeds")
|
||||
prompt_embeds_mask = mm_output.get("prompt_embeds_mask")
|
||||
negative_prompt_embeds = mm_output.get("negative_prompt_embeds")
|
||||
negative_prompt_embeds_mask = mm_output.get("negative_prompt_embeds_mask")
|
||||
all_latents = final_res.trajectory_latents
|
||||
all_timesteps = final_res.trajectory_timesteps
|
||||
prompt_embeds = prompt_embeddings.get("prompt_embeds")
|
||||
prompt_embeds_mask = prompt_embeddings.get("prompt_embeds_mask")
|
||||
negative_prompt_embeds = prompt_embeddings.get("negative_prompt_embeds")
|
||||
negative_prompt_embeds_mask = prompt_embeddings.get("negative_prompt_embeds_mask")
|
||||
|
||||
extra_fields = {
|
||||
"all_latents": all_latents[0] if all_latents is not None else None,
|
||||
|
||||
Reference in new issue
Block a user