Skip to content

Conversation

22quinn
Copy link
Collaborator

@22quinn 22quinn commented Oct 19, 2025

Purpose

Fix outlines_core lazy imports broken by #26633

Annotations are executed at import time by default. To reproduce the issue, run the following

uv pip uninstall outlines_core
python -c "from vllm.v1.engine.llm_engine import LLMEngine"

Error stack trace

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/data/users/quinnzhu/gitrepos/vllm/vllm/v1/engine/llm_engine.py", line 31, in <module>
    from vllm.v1.engine.core_client import EngineCoreClient
  File "/data/users/quinnzhu/gitrepos/vllm/vllm/v1/engine/core_client.py", line 42, in <module>
    from vllm.v1.engine.core import EngineCore, EngineCoreProc
  File "/data/users/quinnzhu/gitrepos/vllm/vllm/v1/engine/core.py", line 39, in <module>
    from vllm.v1.core.kv_cache_utils import (
  File "/data/users/quinnzhu/gitrepos/vllm/vllm/v1/core/kv_cache_utils.py", line 27, in <module>
    from vllm.v1.request import Request
  File "/data/users/quinnzhu/gitrepos/vllm/vllm/v1/request.py", line 22, in <module>
    from vllm.v1.structured_output.request import StructuredOutputRequest
  File "/data/users/quinnzhu/gitrepos/vllm/vllm/v1/structured_output/__init__.py", line 17, in <module>
    from vllm.v1.structured_output.backend_xgrammar import XgrammarBackend
  File "/data/users/quinnzhu/gitrepos/vllm/vllm/v1/structured_output/backend_xgrammar.py", line 20, in <module>
    from vllm.v1.structured_output.utils import (
  File "/data/users/quinnzhu/gitrepos/vllm/vllm/v1/structured_output/utils.py", line 120, in <module>
    class OutlinesVocabulary:
  File "/data/users/quinnzhu/gitrepos/vllm/vllm/v1/structured_output/utils.py", line 126, in OutlinesVocabulary
    def __init__(self, vocabulary: oc.Vocabulary) -> None:
                                   ^^^^^^^^^^^^^
  File "/data/users/quinnzhu/gitrepos/vllm/vllm/utils/import_utils.py", line 320, in __getattr__
    self._module = self._load()
                   ^^^^^^^^^^^^
  File "/data/users/quinnzhu/gitrepos/vllm/vllm/utils/import_utils.py", line 310, in _load
    raise err from None
  File "/data/users/quinnzhu/gitrepos/vllm/vllm/utils/import_utils.py", line 304, in _load
    module = importlib.import_module(self.__name__)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'outlines_core'

Test Plan

uv pip uninstall outlines_core
python -c "from vllm.v1.engine.llm_engine import LLMEngine"

Test Result

Passed


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a bug where lazy imports for outlines_core would fail if the package was not installed. The root cause was the evaluation of type annotations at import time, which triggered the lazy loader. The fix correctly introduces from __future__ import annotations in the affected files (vllm/v1/structured_output/backend_outlines.py and vllm/v1/structured_output/utils.py) to defer the evaluation of type hints. This change is idiomatic, well-targeted, and effectively resolves the ModuleNotFoundError. The implementation is clean and I have no further suggestions.

@mergify mergify bot added the v1 label Oct 19, 2025
@22quinn 22quinn requested a review from houseroad October 19, 2025 00:43
@22quinn 22quinn added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 19, 2025
@Isotr0py Isotr0py enabled auto-merge (squash) October 19, 2025 01:34
@Isotr0py Isotr0py merged commit 191eed0 into vllm-project:main Oct 19, 2025
50 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed structured-output v1

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants