-
Notifications
You must be signed in to change notification settings - Fork 74
[rollout, diffusion] fix: support prompt embedding cache for Qwen-Image #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,13 +72,19 @@ def _prepare_token_id_generation_context( | |
| self._current_timestep = None | ||
| self._interrupt = False | ||
|
|
||
| if isinstance(prompt_ids, list): | ||
| prompt_ids = torch.tensor(prompt_ids, device=self.device) | ||
| if isinstance(negative_prompt_ids, list): | ||
| negative_prompt_ids = torch.tensor(negative_prompt_ids, device=self.device) | ||
|
Comment on lines
-75
to
-78
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove this ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean that this conversion should be controlled by whether the prompt embedding cache is enabled? For example: if not prompt_embed_cache_enabled:
if isinstance(prompt_ids, list):
prompt_ids = torch.tensor(prompt_ids, device=self.device)
if isinstance(negative_prompt_ids, list):
negative_prompt_ids = torch.tensor(
negative_prompt_ids,
device=self.device,
)When the prompt embedding cache is enabled, the token IDs would remain as lists until they pass through the cached Is this the implementation you are suggesting?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see thanks
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will revise the implementation to preserve maximum compatibility with the existing behavior and add only the code strictly required when the prompt cache is enabled. |
||
| prompt_embed_cache = getattr(self, "_prompt_embed_cache", None) | ||
| prompt_embed_cache_enabled = bool(prompt_embed_cache is not None and prompt_embed_cache.enabled) | ||
| if not prompt_embed_cache_enabled: | ||
| if isinstance(prompt_ids, list): | ||
| prompt_ids = torch.tensor(prompt_ids, device=self.device) | ||
| if isinstance(negative_prompt_ids, list): | ||
| negative_prompt_ids = torch.tensor(negative_prompt_ids, device=self.device) | ||
|
|
||
| if prompt_ids is not None: | ||
| batch_size = prompt_ids.shape[0] if prompt_ids.ndim == 2 else 1 | ||
| if isinstance(prompt_ids, torch.Tensor): | ||
| batch_size = prompt_ids.shape[0] if prompt_ids.ndim == 2 else 1 | ||
| else: | ||
| batch_size = len(prompt_ids) if prompt_ids and isinstance(prompt_ids[0], list) else 1 | ||
| elif prompt_embeds is not None: | ||
| batch_size = prompt_embeds.shape[0] | ||
| else: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,6 +170,9 @@ async def run_server(self, args: argparse.Namespace): | |
| engine_args["enable_dummy_pipeline"] = True | ||
| engine_args["custom_pipeline_args"] = {"pipeline_class": pipeline_path} | ||
|
|
||
| engine_args["enable_prompt_embed_cache"] = self.config.enable_prompt_embed_cache | ||
| engine_args["prompt_embed_cache_size"] = self.config.prompt_embed_cache_size | ||
|
|
||
| if getattr(self.config, "step_execution", False): | ||
| engine_args["step_execution"] = True | ||
|
|
||
|
|
@@ -360,7 +363,9 @@ def _preprocess_input( | |
|
|
||
| custom_prompt: OmniCustomPrompt = {"prompt_token_ids": prompt_ids} | ||
| if prompt_mask is not None: | ||
| custom_prompt["prompt_mask"] = prompt_mask | ||
| custom_prompt["prompt_mask"] = ( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If unconditionally converting |
||
| prompt_mask.tolist() if isinstance(prompt_mask, torch.Tensor) else prompt_mask | ||
| ) | ||
| if len(default_params_list) > 1: | ||
| # Multi-stage pipelines tag the diffusion stage so the orchestrator can route inputs correctly. | ||
| custom_prompt["modalities"] = ["image"] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recover these change also