Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the pydantic logging validator #12420

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maxdebayser
Copy link
Contributor

@maxdebayser maxdebayser commented Jan 24, 2025

Prevent the validator from logging unused extra fields before object is validated by the pydantic validator.

During the routing based on the request content where pydantic tries several classes for deserialization, this would result in spurious logs.

For example, during in a request like this one:

curl http://localhost:8000/v1/embeddings \
  -H "Content-Type: application/json" \
  -d '{
    "input": "The rampant curiosity for what a new Tool album would sound like has gotten more and more exaggerated with each release cycle.",
    "model": "sentence-transformers/all-MiniLM-L12-v2"
  }'

vLLM would log

WARNING 01-24 19:52:15 protocol.py:66] The following fields were present in the request but ignored: {'input'}

This is because pydantic tries to deserialize the JSON either as an EmbeddingCompletionRequest or an EmbeddingChatRequest. During the validation of the EmbeddingChatRequest it shows this log because the field only exists in EmbeddingCompletionRequest . This could lead users to believe that the input field was ignored while processing the request.

cc: @DarkLight1337 , @njhill (since you touched this code recently)

Prevent the validator from logging unused extra fields
before object is validated by the pydantic validator.

During the routing based on the request content where
pydantic tries several classes for deserialization, this
would result in spurious logs.

Signed-off-by: Max de Bayser <[email protected]>
Copy link

👋 Hi! Thank you for contributing to the vLLM project.
Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

@mergify mergify bot added the frontend label Jan 24, 2025
Copy link
Member

@DarkLight1337 DarkLight1337 left a comment

Choose a reason for hiding this comment

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

Thanks for fixing! Also cc @mgoin

@DarkLight1337
Copy link
Member

Hmm, looks like this is causing a bunch of tests to fail. For example:

[2025-01-24T20:53:45Z] Traceback (most recent call last):
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/uvicorn/protocols/http/httptools_impl.py", line 409, in run_asgi
[2025-01-24T20:53:45Z]     result = await app(  # type: ignore[func-returns-value]
[2025-01-24T20:53:45Z]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
[2025-01-24T20:53:45Z]     return await self.app(scope, receive, send)
[2025-01-24T20:53:45Z]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/fastapi/applications.py", line 1054, in __call__
[2025-01-24T20:53:45Z]     await super().__call__(scope, receive, send)
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/applications.py", line 112, in __call__
[2025-01-24T20:53:45Z]     await self.middleware_stack(scope, receive, send)
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/middleware/errors.py", line 187, in __call__
[2025-01-24T20:53:45Z]     raise exc
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/middleware/errors.py", line 165, in __call__
[2025-01-24T20:53:45Z]     await self.app(scope, receive, _send)
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/middleware/cors.py", line 85, in __call__
[2025-01-24T20:53:45Z]     await self.app(scope, receive, send)
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/middleware/exceptions.py", line 62, in __call__
[2025-01-24T20:53:45Z]     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/_exception_handler.py", line 53, in wrapped_app
[2025-01-24T20:53:45Z]     raise exc
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/_exception_handler.py", line 42, in wrapped_app
[2025-01-24T20:53:45Z]     await app(scope, receive, sender)
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/routing.py", line 715, in __call__
[2025-01-24T20:53:45Z]     await self.middleware_stack(scope, receive, send)
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/routing.py", line 735, in app
[2025-01-24T20:53:45Z]     await route.handle(scope, receive, send)
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/routing.py", line 288, in handle
[2025-01-24T20:53:45Z]     await self.app(scope, receive, send)
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/routing.py", line 76, in app
[2025-01-24T20:53:45Z]     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/_exception_handler.py", line 53, in wrapped_app
[2025-01-24T20:53:45Z]     raise exc
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/_exception_handler.py", line 42, in wrapped_app
[2025-01-24T20:53:45Z]     await app(scope, receive, sender)
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/starlette/routing.py", line 73, in app
[2025-01-24T20:53:45Z]     response = await f(request)
[2025-01-24T20:53:45Z]                ^^^^^^^^^^^^^^^^
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/fastapi/routing.py", line 301, in app
[2025-01-24T20:53:45Z]     raw_response = await run_endpoint_function(
[2025-01-24T20:53:45Z]                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/fastapi/routing.py", line 212, in run_endpoint_function
[2025-01-24T20:53:45Z]     return await dependant.call(**values)
[2025-01-24T20:53:45Z]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/vllm/entrypoints/openai/api_server.py", line 364, in show_available_models
[2025-01-24T20:53:45Z]     models_ = await handler.show_available_models()
[2025-01-24T20:53:45Z]               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/vllm/entrypoints/openai/serving_models.py", line 115, in show_available_models
[2025-01-24T20:53:45Z]     ModelCard(id=base_model.name,
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/pydantic/main.py", line 212, in __init__
[2025-01-24T20:53:45Z]     validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
[2025-01-24T20:53:45Z]                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/vllm/entrypoints/openai/protocol.py", line 51, in __log_extra_fields__
[2025-01-24T20:53:45Z]     result = handler(data)
[2025-01-24T20:53:45Z]              ^^^^^^^^^^^^^
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/vllm/entrypoints/openai/protocol.py", line 69, in __log_extra_fields__
[2025-01-24T20:53:45Z]     data.keys() - field_names)
[2025-01-24T20:53:45Z]     ^^^^^^^^^
[2025-01-24T20:53:45Z]   File "/usr/local/lib/python3.12/dist-packages/pydantic/main.py", line 856, in __getattr__
[2025-01-24T20:53:45Z]     raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
[2025-01-24T20:53:45Z] AttributeError: 'ModelPermission' object has no attribute 'keys'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants