Skip to content

Conversation

@hmellor
Copy link
Member

@hmellor hmellor commented May 2, 2025

  • Enables the mypy extension for Pydantic
  • Fix the new mypy errors created by doing that
  • Swap out the builtin dataclasses for Pydantic dataclasses (free input validation!)
    $ vllm serve meta-llama/Llama-3.2-1B-Instruct --gpu-memory-utilization 0.45 --compilation-config '{"level":2.5}'
    INFO 05-12 12:59:58 [__init__.py:248] Automatically detected platform cuda.
    WARNING 05-12 13:00:02 [config.py:2034] max_model_len was is not set. Defaulting to arbitrary value of 8192.
    WARNING 05-12 13:00:02 [config.py:2040] max_num_seqs was is not set. Defaulting to arbitrary value of 128.
    usage: vllm serve [model_tag] [options]
    vllm serve: error: argument --compilation-config/-O: 1 validation error for CompilationConfig
    level
      Input should be a valid integer, got a number with a fractional part [type=int_from_float, input_value=2.5, input_type=float]
        For further information visit https://errors.pydantic.dev/2.11/v/int_from_float

N.B. Pydantic base models handle mutable defaults correctly. x: list = [] looks much nicer than the alternative mypy will allow x: list = Field(default_factory=lambda: [])

hmellor added 4 commits May 2, 2025 20:46
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@hmellor hmellor requested review from mgoin and russellb as code owners May 2, 2025 19:32
@github-actions
Copy link

github-actions bot commented May 2, 2025

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

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 either: Add ready label to the PR or enable auto-merge.

🚀

@mergify mergify bot added frontend structured-output tpu Related to Google TPUs labels May 2, 2025
@hmellor hmellor changed the title Enable-pydantic-mypy Enable Pydantic mypy checks and convert configs to Pydantic dataclasses May 2, 2025
@hmellor
Copy link
Member Author

hmellor commented May 2, 2025

I think this PR must wait for #17485. Hopefully the switch to static analysis in the docs build will prevent the Pydantic errors

russellb
russellb previously approved these changes May 5, 2025
Copy link
Member

@russellb russellb left a comment

Choose a reason for hiding this comment

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

thanks!

Copy link
Member

@russellb russellb left a comment

Choose a reason for hiding this comment

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

well, I'm happy with the changes in general, but it looks like you have some failing tests.

@russellb russellb dismissed their stale review May 5, 2025 12:33

dismissing approval, pending test resolution

@mergify
Copy link

mergify bot commented May 6, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @hmellor.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label May 6, 2025
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@hmellor hmellor marked this pull request as draft May 12, 2025 09:42
hmellor added 2 commits May 12, 2025 11:43
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@mergify mergify bot removed tpu Related to Google TPUs needs-rebase labels May 12, 2025
hmellor added 4 commits May 12, 2025 12:11
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
hmellor added 5 commits May 16, 2025 09:40
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@hmellor
Copy link
Member Author

hmellor commented May 16, 2025

Instead of fighting Sphinx, I will try and merge #18145 so that we never have to think about breaking the docs build again 🎉

@mergify
Copy link

mergify bot commented May 19, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @hmellor.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

hmellor added 2 commits May 26, 2025 18:07
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@mergify mergify bot removed the needs-rebase label May 26, 2025
hmellor added 3 commits May 26, 2025 18:13
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@hmellor hmellor requested a review from jeejeelee as a code owner May 27, 2025 15:13
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@simon-mo simon-mo merged commit 4c2b38c into vllm-project:main May 28, 2025
74 checks passed
@hmellor hmellor deleted the enable-pydantic-mypy branch May 28, 2025 16:09
@ProExpertProg
Copy link
Collaborator

Getting this error on Python 3.10 after this PR:

Traceback (most recent call last):
  File "/home/luka/neuralmagic-vllm/examples/offline_inference/basic/generate.py", line 3, in <module>
    from vllm import LLM, EngineArgs
  File "/home/luka/neuralmagic-vllm/vllm/__init__.py", line 12, in <module>
    from vllm.engine.arg_utils import AsyncEngineArgs, EngineArgs
  File "/home/luka/neuralmagic-vllm/vllm/engine/arg_utils.py", line 21, in <module>
    from vllm.config import (BlockSize, CacheConfig, CacheDType, CompilationConfig,
  File "/home/luka/neuralmagic-vllm/vllm/config.py", line 1704, in <module>
    class ParallelConfig:
  File "/home/luka/neuralmagic-vllm/venv/lib/python3.10/site-packages/pydantic/dataclasses.py", line 264, in dataclass
    return create_dataclass if _cls is None else create_dataclass(_cls)
  File "/home/luka/neuralmagic-vllm/venv/lib/python3.10/site-packages/pydantic/dataclasses.py", line 261, in create_dataclass
    _pydantic_dataclasses.complete_dataclass(cls, config_wrapper, raise_errors=False, types_namespace=None)
  File "/home/luka/neuralmagic-vllm/venv/lib/python3.10/site-packages/pydantic/_internal/_dataclasses.py", line 181, in complete_dataclass
    cls.__pydantic_validator__ = validator = create_schema_validator(
  File "/home/luka/neuralmagic-vllm/venv/lib/python3.10/site-packages/pydantic/plugin/_schema_validator.py", line 50, in create_schema_validator
    return SchemaValidator(schema, config)
pydantic_core._pydantic_core.SchemaError: Error building "dataclass" validator:
  SchemaError: Error building "dataclass-args" validator:
  SchemaError: Field 'distributed_executor_backend':
  SchemaError: Error building "default" validator:
  SchemaError: Error building "nullable" validator:
  SchemaError: Error building "union" validator:
  SchemaError: Error building "is-subclass" validator:
  TypeError: 'str' object cannot be converted to 'PyType'

@hmellor
Copy link
Member Author

hmellor commented May 28, 2025

amitm02 pushed a commit to amitm02/vllm that referenced this pull request Jun 1, 2025
…es (vllm-project#17599)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: amit <amit.man@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants