vllm-project/vllm · error · AttributeError
module {__package__} has no attribute {name}
Error message
module {__package__} has no attribute {name} What it means
vllm/__init__.py uses lazy module-level __getattr__ (PEP 562): only names in the MODULE_ATTRS map (LLM, SamplingParams, ModelRegistry, EngineArgs, RequestOutput, initialize_ray_cluster, etc., see __all__) are importable from the vllm top level, resolved on demand to their defining submodules. Accessing any other attribute through the package (vllm.foo or from vllm import foo) raises this AttributeError to keep import time low.
Source
Thrown at vllm/__init__.py:73
PoolingRequestOutput,
RequestOutput,
ScoringOutput,
ScoringRequestOutput,
)
from vllm.pooling_params import PoolingParams
from vllm.sampling_params import SamplingParams
from vllm.v1.executor.ray_utils import initialize_ray_cluster
else:
def __getattr__(name: str) -> typing.Any:
from importlib import import_module
if name in MODULE_ATTRS:
module_name, attr_name = MODULE_ATTRS[name].split(":")
module = import_module(module_name, __package__)
return getattr(module, attr_name)
else:
raise AttributeError(f"module {__package__} has no attribute {name}")
__all__ = [
"__version__",
"__version_tuple__",
"LLM",
"ModelRegistry",
"PromptType",
"TextPrompt",
"TokensPrompt",
"SamplingParams",
"RequestOutput",
"CompletionOutput",
"PoolingOutput",
"PoolingRequestOutput",
"EmbeddingOutput",
"EmbeddingRequestOutput",
"ClassificationOutput",View on GitHub (pinned to c794754062)
Solutions
- Check vllm.__all__ (or the MODULE_ATTRS map in vllm/__init__.py) for the names that are actually re-exported
- Import from the defining submodule instead, e.g. `from vllm.utils import ...` or `from vllm.config import ...` — find it with grep or your IDE's go-to-definition against installed vllm
- If the symbol existed under this name in an older vllm, consult the migration/deprecation notes and switch to the current import path
- Upgrade/downgrade vllm only if the code targets a version whose top-level exports included the name
Example fix
# before import vllm logger = vllm.configure_logger(...) # AttributeError # after from vllm.logging_utils import configure_logger logger = configure_logger(...)
Defensive patterns
Strategy: type-guard
Validate before calling
import vllm
name = "SamplingParams"
if name not in getattr(vllm, "__all__", ()):
raise SystemExit(f"{name} is not exported from the vllm top level; import it from its submodule") Type guard
def vllm_exports(name: str) -> bool:
import vllm
return name in vllm.__all__ # MODULE_ATTRS keys, resolved lazily via __getattr__ Try / catch
try:
cls = getattr(vllm, name)
except AttributeError:
# fall back to the defining submodule, e.g. vllm.utils / vllm.config
cls = getattr(importlib.import_module(f"vllm.{submodule}"), name) Prevention
- Import internals from their submodules (vllm.utils, vllm.config, vllm.logging_utils), not the package root
- Use getattr(vllm, name, None) or check __all__ for feature detection instead of direct attribute access
- Pin the vllm version and write imports against that version's documented public API
- Remember top-level exports are lazy (PEP 562): accessing them triggers the real submodule import
When it happens
Trigger: `from vllm import configure_logger` or `vllm.MyClass` where MyClass was never exported at top level — e.g. utilities, config objects, or engine internals that live in submodules; also hasattr(vllm, name) probes against the lazy map. Note submodule imports (vllm.utils) are handled by the import system and do not raise this; only missing top-level attribute names do.
Common situations: Code written against old vLLM versions that eagerly imported many names into the package namespace; IDE autocomplete suggesting symbols that exist in submodules but not in __all__; libraries doing duck-typed feature detection via getattr(vllm, 'X', None) (which works) vs direct attribute access (which raises).
Related errors
- HTTP request failed: {0}
- JSON error: {0}
- Tokenizer error: {0}
- tokenize endpoint unavailable: {0}
- Configuration error: {0}
AI-assisted analysis of vllm-project/vllm@c794754062 (2026-08-14).
Data as JSON: /api/errors/4c24d75639d411fe.
Report an issue: GitHub.