[MISC] Consolidate cleanup() and refactor offline_inference_with_prefix.py (#9510)

This commit is contained in:
Cody Yu
2024-10-18 14:30:55 -07:00
committed by GitHub
parent 9bb10a7d27
commit d11bf435a0
20 changed files with 84 additions and 105 deletions

View File

@@ -1,5 +1,3 @@
import contextlib
import gc
import json
import os
import sys
@@ -27,8 +25,7 @@ from vllm.assets.image import ImageAsset
from vllm.assets.video import VideoAsset
from vllm.config import TaskOption, TokenizerPoolConfig
from vllm.connections import global_http_connection
from vllm.distributed import (destroy_distributed_environment,
destroy_model_parallel,
from vllm.distributed import (cleanup_dist_env_and_memory,
init_distributed_environment,
initialize_model_parallel)
from vllm.inputs import (ExplicitEncoderDecoderPrompt, TextPrompt,
@@ -140,17 +137,7 @@ def dist_init():
)
initialize_model_parallel(1, 1)
yield
cleanup()
def cleanup():
destroy_model_parallel()
destroy_distributed_environment()
with contextlib.suppress(AssertionError):
torch.distributed.destroy_process_group()
gc.collect()
if not is_cpu():
torch.cuda.empty_cache()
cleanup_dist_env_and_memory()
@pytest.fixture()
@@ -167,7 +154,7 @@ def should_do_global_cleanup_after_test(request) -> bool:
def cleanup_fixture(should_do_global_cleanup_after_test: bool):
yield
if should_do_global_cleanup_after_test:
cleanup()
cleanup_dist_env_and_memory()
@pytest.fixture(autouse=True)
@@ -606,7 +593,7 @@ class HfRunner:
def __exit__(self, exc_type, exc_value, traceback):
del self.model
cleanup()
cleanup_dist_env_and_memory()
@pytest.fixture(scope="session")
@@ -861,7 +848,7 @@ class VllmRunner:
def __exit__(self, exc_type, exc_value, traceback):
del self.model
cleanup()
cleanup_dist_env_and_memory()
@pytest.fixture(scope="session")