Skip to content

Commit f4df67b

Browse files
committed
[bugfix] Speed up Dreamverse Modal compile warmup
1 parent 321d511 commit f4df67b

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

apps/dreamverse/dreamverse/video_generation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ def initialize(self, model_config: dict | None = None) -> None:
280280
compile=CompileConfig(
281281
enabled=enable_compile,
282282
text_encoder_enabled=enable_compile,
283+
vae_enabled=enable_compile,
283284
backend="inductor",
284285
fullgraph=True,
285286
mode="max-autotune-no-cudagraphs",

apps/dreamverse/scripts/modal/modal_app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
image = modal.Image.from_registry(IMAGE)
1818
image = image.env({
19+
"DREAMVERSE_IMAGE": IMAGE,
1920
"HF_HOME": "/root/.cache/huggingface",
2021
"FASTVIDEO_DREAMVERSE_HOME": "/var/lib/dreamverse",
21-
"FASTVIDEO_ENABLE_STARTUP_WARMUP": "0",
22+
"FASTVIDEO_ENABLE_STARTUP_WARMUP": "1",
2223
"FASTVIDEO_GPU_COUNT": "1",
23-
"ENABLE_TORCH_COMPILE": "0",
24+
"ENABLE_TORCH_COMPILE": "1",
2425
"STREAM_MODE": "av_fmp4",
2526
})
2627

fastvideo/models/encoders/gemma.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,32 @@ def named_parameters(self, prefix: str = "", recurse: bool = True):
363363

364364
def prepare_for_compile(self) -> None:
365365
# Load Gemma outside Dynamo so torch.compile does not trace HF file-system checks.
366-
_ = self.gemma_model
366+
model = self.gemma_model
367+
# Run one tiny eager forward before torch.compile. FastVideo calls the text encoder with
368+
# Transformers' output_hidden_states path, which wraps each Gemma layer
369+
# forward method and restores it by setting an instance-level forward
370+
# attribute. If that attribute appears after Dynamo captures guards, the
371+
# next text-encoder call recompiles; doing it here makes the first
372+
# compiled call see the stable layer state.
373+
token_id = getattr(model.config, "eos_token_id", None)
374+
if isinstance(token_id, (list, tuple)):
375+
token_id = token_id[0] if token_id else None
376+
if token_id is None:
377+
token_id = getattr(model.config, "pad_token_id", 0)
378+
input_ids = torch.full(
379+
(1, 1),
380+
int(token_id or 0),
381+
dtype=torch.long,
382+
device=model.device,
383+
)
384+
attention_mask = torch.ones_like(input_ids)
385+
with torch.no_grad():
386+
model(
387+
input_ids=input_ids,
388+
attention_mask=attention_mask,
389+
output_hidden_states=True,
390+
return_dict=True,
391+
)
367392

368393
@property
369394
def gemma_model(self) -> Gemma3ForConditionalGeneration:

0 commit comments

Comments
 (0)