[Bugfix] Override dunder methods of placeholder modules (#11882)

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
Cyrus Leung
2025-01-09 17:02:53 +08:00
committed by GitHub
parent 310aca88c9
commit 0bd1ff4346
2 changed files with 220 additions and 16 deletions

View File

@@ -7,9 +7,9 @@ import pytest
import torch
from vllm_test_utils import monitor
from vllm.utils import (FlexibleArgumentParser, StoreBoolean, deprecate_kwargs,
get_open_port, memory_profiling, merge_async_iterators,
supports_kw)
from vllm.utils import (FlexibleArgumentParser, PlaceholderModule,
StoreBoolean, deprecate_kwargs, get_open_port,
memory_profiling, merge_async_iterators, supports_kw)
from .utils import error_on_warning, fork_new_process_for_each_test
@@ -323,3 +323,44 @@ def test_memory_profiling():
del weights
lib.cudaFree(handle1)
lib.cudaFree(handle2)
def test_placeholder_module_error_handling():
placeholder = PlaceholderModule("placeholder_1234")
def build_ctx():
return pytest.raises(ModuleNotFoundError,
match="No module named")
with build_ctx():
int(placeholder)
with build_ctx():
placeholder()
with build_ctx():
_ = placeholder.some_attr
with build_ctx():
# Test conflict with internal __name attribute
_ = placeholder.name
# OK to print the placeholder or use it in a f-string
_ = repr(placeholder)
_ = str(placeholder)
# No error yet; only error when it is used downstream
placeholder_attr = placeholder.placeholder_attr("attr")
with build_ctx():
int(placeholder_attr)
with build_ctx():
placeholder_attr()
with build_ctx():
_ = placeholder_attr.some_attr
with build_ctx():
# Test conflict with internal __module attribute
_ = placeholder_attr.module