[Fix] [AMD] diffusion: Prevent ComponentResidencyError after compile warmup (#43952)
Co-authored-by: Mick Qian <mickqian@users.noreply.github.com>
This commit is contained in:
@@ -565,6 +565,13 @@ class DenoisingStage(PipelineStage, RolloutDenoisingMixin):
|
||||
moved.append(module)
|
||||
return moved
|
||||
|
||||
def _explicit_dit_layerwise_offload(self) -> bool:
|
||||
"""True when the user asked for layerwise DiT residency, not a compile-only window."""
|
||||
args = self.server_args
|
||||
if args.dit_layerwise_offload:
|
||||
return True
|
||||
return bool(getattr(args, "is_dit_layerwise_offload_selected", False))
|
||||
|
||||
def _maybe_torch_compile(self, module: object) -> None:
|
||||
"""
|
||||
Compile a module with torch.compile, and enable inductor overlap tweak if available.
|
||||
@@ -2073,9 +2080,13 @@ class DenoisingStage(PipelineStage, RolloutDenoisingMixin):
|
||||
for module in moved:
|
||||
module.to(device)
|
||||
return
|
||||
# prepare for first real request: restore the user-configured residency
|
||||
for module in self._offloaded_dit_modules_for_compile:
|
||||
module.disable_offload()
|
||||
# Compile-only offload is undone so the real request is GPU-resident.
|
||||
# An explicit layerwise request must stay enabled: disable_offload()
|
||||
# clears manager.enabled, and the next use-site then raises
|
||||
# ComponentResidencyError (Wan transformer_2).
|
||||
if not self._explicit_dit_layerwise_offload():
|
||||
for module in self._offloaded_dit_modules_for_compile:
|
||||
module.disable_offload()
|
||||
# clear the list for avoid overhead during real request
|
||||
self._offloaded_dit_modules_for_compile.clear()
|
||||
# The warmup traced the offload hooks, whose graph breaks inside the
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
"""Compile warmup must not clear a layerwise DiT the user asked to keep."""
|
||||
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
|
||||
from sglang.multimodal_gen.runtime.pipelines_core.stages.denoising import (
|
||||
DenoisingStage,
|
||||
)
|
||||
|
||||
|
||||
class _OffloadModule:
|
||||
def __init__(self):
|
||||
self.disable_calls = 0
|
||||
|
||||
def disable_offload(self):
|
||||
self.disable_calls += 1
|
||||
|
||||
|
||||
class TestCompileWarmupKeepsExplicitLayerwise(unittest.TestCase):
|
||||
def _stage(self, **server_args):
|
||||
stage = DenoisingStage.__new__(DenoisingStage)
|
||||
stage.server_args = SimpleNamespace(**server_args)
|
||||
module = _OffloadModule()
|
||||
stage._offloaded_dit_modules_for_compile = [module]
|
||||
return stage, module
|
||||
|
||||
def _finish_compile_window(self, stage):
|
||||
batch = SimpleNamespace(is_warmup=False)
|
||||
with stage._offload_for_torch_compile_warmup(batch):
|
||||
pass
|
||||
|
||||
def test_explicit_dit_layerwise_offload_stays_enabled(self):
|
||||
stage, module = self._stage(
|
||||
dit_layerwise_offload=True,
|
||||
is_dit_layerwise_offload_selected=False,
|
||||
)
|
||||
self._finish_compile_window(stage)
|
||||
self.assertEqual(module.disable_calls, 0)
|
||||
self.assertEqual(stage._offloaded_dit_modules_for_compile, [])
|
||||
|
||||
def test_compile_only_offload_is_disabled_for_the_real_request(self):
|
||||
stage, module = self._stage(
|
||||
dit_layerwise_offload=False,
|
||||
is_dit_layerwise_offload_selected=False,
|
||||
)
|
||||
self._finish_compile_window(stage)
|
||||
self.assertEqual(module.disable_calls, 1)
|
||||
self.assertEqual(stage._offloaded_dit_modules_for_compile, [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -47,10 +47,12 @@ class TestOffloadDuringCompile(CustomTestCase):
|
||||
self.dit = _DiT()
|
||||
self.counter = CompileCounter()
|
||||
self.dit.compile(backend=self.counter)
|
||||
self.stage = SimpleNamespace(
|
||||
_offloaded_dit_modules_for_compile=[self.dit],
|
||||
_move_resident_components_for_warmup=lambda: [],
|
||||
self.stage = DenoisingStage.__new__(DenoisingStage)
|
||||
self.stage.server_args = SimpleNamespace(
|
||||
dit_layerwise_offload=False, is_dit_layerwise_offload_selected=False
|
||||
)
|
||||
self.stage._offloaded_dit_modules_for_compile = [self.dit]
|
||||
self.stage._move_resident_components_for_warmup = lambda: []
|
||||
|
||||
def _forward(self, *, is_warmup):
|
||||
with DenoisingStage._offload_for_torch_compile_warmup(
|
||||
|
||||
Reference in New Issue
Block a user