[diffusion] chore: fix unclean shutdown and resource leaks (#18477)

This commit is contained in:
Mick
2026-02-09 22:32:08 +08:00
committed by GitHub
parent 76eb1c8406
commit 4f7da5ad0f
5 changed files with 30 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
# SPDX-License-Identifier: Apache-2.0
import gc
import multiprocessing as mp
import os
import time
@@ -404,4 +405,12 @@ def run_scheduler_process(
print(OOM_MSG)
raise
finally:
# Clean up resources to speed up shutdown
if "scheduler" in locals():
del scheduler
gc.collect()
if torch.cuda.is_initialized():
torch.cuda.empty_cache()
if torch.distributed.is_available() and torch.distributed.is_initialized():
torch.distributed.destroy_process_group()
logger.info(f"Worker {rank}: Shutdown complete.")