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

[Core] Centralize GPU Worker construction #4419

Merged
merged 7 commits into from
May 1, 2024

Conversation

njhill
Copy link
Collaborator

@njhill njhill commented Apr 27, 2024

Add _get_worker_kwargs and _create_worker methods to GPUExecutor which construct Worker instances from the executor configuration, and make use of these in places where the logic is currently duplicated.

This will also be used by the to-be-added MultiprocessingGPUExecutor.

Add _get_worker_kwargs _create_worker methods to GPUExecutor which construct Worker instances from the executor configurations, and make use of these in places where the logic is currently duplicated.

This will also be used by the MultiprocessingGPUExecutor executor class.
@youkaichao
Copy link
Member

Is this WorkerWrapperBase.init_worker ?

@njhill
Copy link
Collaborator Author

njhill commented Apr 29, 2024

@youkaichao I don't think so, this is primarily centralizing how the GPU executor config is converted to the worker args.

I don' think WorkerWrapperBase.init_worker is necessarily needed in non-ray cases, the "wrapped" worker init can just be done as part of the remote worker init rather than having separate RPCs to set up the env vars and then init the worker.

@youkaichao
Copy link
Member

I mean, they can share the same code to reduce code duplication. You can include WorkerWrapperBase.init_worker in your code without a rpc call. This way we have a unified entrypoint of worker construction, and we can inject some common logic like log handling, enable_trace_function_call_for_thread, etc.

My design of WorkerWrapperBase is definitely not just tailored to ray.

@njhill
Copy link
Collaborator Author

njhill commented Apr 29, 2024

@youkaichao maybe better to move that common logic to a static function in base_worker.py? since for example in the single GPU case there isn't a wrapper, and it can be called from the existing WorkerWrapperBase.init_worker method (I can make that change if you agree). Or else could you suggest what changes would be made to this PR?

@vrdn-23 vrdn-23 mentioned this pull request Apr 30, 2024
@youkaichao
Copy link
Member

I think WorkerWrapper is required for every Worker, but I didn't find time to do it. The idea is that we need to inject some common logic before every worker starts to initialize, e.g. enable logging, debug tracing, setting environment variables. That's why I designed the WorkerWrapperBase to have arguments of module name and module class name: after we initialize WorkerWrapper, before initialize Worker, the whole Worker module is not imported, meaning that none of the code from Worker-related module will be executed.

@njhill
Copy link
Collaborator Author

njhill commented May 1, 2024

@youkaichao I'm using WorkerWrapperBase to initialize the single GPU worker now, PTAL!

Copy link
Member

@youkaichao youkaichao left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@njhill njhill enabled auto-merge (squash) May 1, 2024 00:48
@njhill njhill merged commit 2e240c6 into vllm-project:main May 1, 2024
47 of 48 checks passed
@njhill njhill deleted the create_worker branch May 1, 2024 01:51
@youkaichao
Copy link
Member

A side note @njhill :

Initially, I would like to make single gpu executor more similar to multi-gpu executor, e.g. move _run_workers function to ExecutorBase. Then all executors just need to run self._run_workers("init_worker"), self._run_workers("init_device"), self._run_workers("load_model") . This unifed interface looks better to me. Different executors just have different _run_workers implementation (and of course, different _init_executor implementation).

I'm not sure if it is good to go. It will have some small overhead for single-gpu execution though, but I expect the overhead to be minimal.

@njhill
Copy link
Collaborator Author

njhill commented May 1, 2024

@youkaichao that does make sense from a unification pov, but the code was actually originally like this before @zhuohan123 refactored it to be as it is now in #3191.

Perhaps the reason was so that we can streamline/optimize the single-gpu case which is potentially most common

@youkaichao
Copy link
Member

Thanks for pointing it out. Didn't notice it before.

robertgshaw2-neuralmagic pushed a commit to neuralmagic/nm-vllm that referenced this pull request May 6, 2024
z103cb pushed a commit to z103cb/opendatahub_vllm that referenced this pull request May 7, 2024
dtrifiro pushed a commit to opendatahub-io/vllm that referenced this pull request May 7, 2024
mawong-amd pushed a commit to ROCm/vllm that referenced this pull request Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants