[Perf]Enable regional compile for Cosmos3 HSDP blocks (#4485)

Signed-off-by: bjf-frz <frz123db@gmail.com>
This commit is contained in:
bjf-frz authored and GitHub committed 2026-06-18 16:54:05 +08:00
1 parent 77d395150b
commit 14d70d9870
2 files changed
+66 -2

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import torch.nn as nn
from vllm_omni.diffusion.compile import regionally_compile
class _WrappedBlock(nn.Module):
def __init__(self) -> None:
super().__init__()
self.compile_called = False
def compile(self, *args, **kwargs):
self.compile_called = True
return self
class _ModelWithWrappedRepeatedBlocks(nn.Module):
_repeated_blocks = ["OriginalBlock"]
_layerwise_offload_blocks_attrs = ["transformer_blocks"]
def __init__(self) -> None:
super().__init__()
self.transformer_blocks = nn.ModuleList([_WrappedBlock(), _WrappedBlock()])
self.other_blocks = nn.ModuleList([_WrappedBlock()])
def test_regionally_compile_matches_wrapped_blocks_by_declared_container_attr():
model = _ModelWithWrappedRepeatedBlocks()
regionally_compile(model)
assert all(block.compile_called for block in model.transformer_blocks)
assert not model.other_blocks[0].compile_called