-
-
Notifications
You must be signed in to change notification settings - Fork 11k
[Bugfix] fix v1 cpu worker fails on macOS #19121
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
Conversation
|
👋 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 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 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @kebe7jun, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Hello! Gemini or gemini-code-assist here, providing a summary of this pull request to help everyone quickly understand the changes.
This PR aims to fix a specific bug where the v1 CPU worker fails when running on macOS. The root cause appears to be related to how the maximum number of threads is determined and set for libraries like NUMEXPR, which is typically done using os.sched_getaffinity. This function is not available on macOS, leading to the failure.
The core change introduces a new helper function get_max_threads that provides an OS-aware way to determine the available threads. It uses os.sched_getaffinity on systems where it's available (like Linux) and falls back to using os.cpu_count() for macOS (Darwin). The code that sets the NUMEXPR_MAX_THREADS environment variable is then updated to use this new, more robust function, resolving the macOS compatibility issue.
Highlights
- Bugfix: Addresses and fixes a bug causing the v1 CPU worker to fail specifically on macOS.
- Platform Compatibility: Improves compatibility for the CPU backend on macOS by handling OS-specific differences in determining available CPU threads.
- New Helper Function: Introduces a new utility function
get_max_threadsto abstract away OS-specific logic for getting thread information.
Changelog
- vllm/platforms/cpu.py
- Imported the
platformmodule to check the operating system. - Added a new function
get_max_threads(pid=0)which returns the set of available CPU IDs usingos.sched_getaffinityif available, orset(range(os.cpu_count()))if the system is macOS ('Darwin'). RaisesNotImplementedErrorfor other unsupported systems. - Modified the
check_and_update_configmethod to call the newget_max_threads()function instead of the directlen(os.sched_getaffinity(0))when setting theNUMEXPR_MAX_THREADSenvironment variable.
- Imported the
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Mac threads were lost,
Nowplatformfinds the way,
CPU runs free.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this 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 effectively addresses the AttributeError for os.sched_getaffinity on macOS by introducing a fallback mechanism using os.cpu_count(). This is a good fix for improving cross-platform compatibility for CPU workers.
However, there's a critical issue in how the result of the new get_max_threads function is used, which needs to be addressed. Additionally, adding documentation and type hints to the new function would enhance code clarity and maintainability.
Summary of Findings
- Incorrect NUMEXPR_MAX_THREADS Value: The
NUMEXPR_MAX_THREADSenvironment variable is being set with the string representation of a set (e.g.,"{0, 1, 2, 3}") instead of the count of threads (e.g.,"4"). This is becauselen()is missing when callingget_max_threads(). - Missing Documentation and Type Hints: The newly added
get_max_threadsfunction lacks a docstring and type hints, which would improve its readability and maintainability. - Error Message Specificity (Not Commented): The
NotImplementedErroringet_max_threadsuses a generic "Unsupported OS" message. A more specific message like "Unsupported OS for determining CPU affinity or count." could be more informative. This was not added as a direct comment due to review settings (low severity).
Merge Readiness
This pull request makes a valuable fix for macOS compatibility. However, there is a critical issue regarding the incorrect setting of the NUMEXPR_MAX_THREADS environment variable that must be addressed before merging. Additionally, enhancing the new get_max_threads function with a docstring and type hints is recommended for better code quality.
I am unable to approve pull requests. Please ensure the critical issue is resolved, and consider the medium-severity feedback. After these changes, the PR should be in a much better state for further review and merging.
bc4ae18 to
8e5939c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for investigating this. With this change, does V1 run on MacOS now? It would be good to report your testing strategy in the PR description
Updated the PR description. |
|
We should only enable CPU V1 for x86 arch because other arch have no chunked prefill op support... I forgot to consider this :( Lines 1434 to 1440 in b124e10
|
8e5939c to
493089d
Compare
|
@bigPYJ1151 Yes, I updated the fallback logic. |
493089d to
5999e75
Compare
5999e75 to
1f676e5
Compare
|
LGTM. Please fix the precommit so I can enable CI |
Signed-off-by: Kebe <mail@kebe7jun.com>
1f676e5 to
2116c22
Compare
@mgoin fixed. |
Fix #19120
Essential Elements of an Effective PR Description Checklist
Purpose
Fixed an issue where CPU v1 mode could not be enabled on macOS.
Test Plan
vllm serve Qwen/Qwen2.5-0.5B-InstructTest Result
ref: #16441
cc @bigPYJ1151