[feat] Support prompt embedding caching for diffusion model (#2962)
Signed-off-by: knlnguyen1802 <knlnguyen1802@gmail.com> Co-authored-by: Samit <285365963@qq.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
9 files changed
+980
-11
No files matched your search
@@ -2130,6 +2130,28 @@ class MagiHumanPipeline(nn.Module, ProgressBarMixin, DiffusionPipelineProfilerMi
|
||||
|
||||
return resample(audio_np, target_len)
|
||||
|
||||
def encode_prompt(
|
||||
self,
|
||||
prompt: str,
|
||||
target_length: int | None = None,
|
||||
) -> tuple[torch.Tensor, int]:
|
||||
"""Encode *prompt* with the T5-Gemma text encoder and pad to fixed length.
|
||||
|
||||
This is the single text-encoder entrypoint so the runner-level
|
||||
prompt-embedding cache (see
|
||||
``vllm_omni/diffusion/cache/prompt_embed_cache.py``) can transparently
|
||||
memoize results when the same prompt is submitted repeatedly.
|
||||
|
||||
Returns:
|
||||
``(context, original_context_len)`` matching
|
||||
:func:`_get_padded_t5_gemma_embedding`.
|
||||
"""
|
||||
return _get_padded_t5_gemma_embedding(
|
||||
prompt,
|
||||
self.text_encoder,
|
||||
target_length if target_length is not None else self.t5_gemma_target_length,
|
||||
)
|
||||
|
||||
@torch.inference_mode()
|
||||
def forward(
|
||||
self,
|
||||
@@ -2200,11 +2222,7 @@ class MagiHumanPipeline(nn.Module, ProgressBarMixin, DiffusionPipelineProfilerMi
|
||||
device=device,
|
||||
)
|
||||
|
||||
context, original_context_len = _get_padded_t5_gemma_embedding(
|
||||
prompt,
|
||||
self.text_encoder,
|
||||
self.t5_gemma_target_length,
|
||||
)
|
||||
context, original_context_len = self.encode_prompt(prompt)
|
||||
|
||||
if image_path is not None:
|
||||
br_image = self._encode_image(load_image(image_path), br_height, br_width)
|
||||
|
||||
Reference in new issue
Block a user