[ray.data.llm] Fix build_llm_processor for ServeDeploymentProcessor#57061
Conversation
There was a problem hiding this comment.
Code Review
This pull request correctly addresses a bug where chat_template_kwargs was passed to processor types that do not support it, leading to errors. The fix, which involves checking if the configuration is an instance of OfflineProcessorConfig before passing the argument, is appropriate. Additionally, updating the tests to use the public build_llm_processor API instead of the internal ProcessorBuilder is a great improvement for ensuring the tests reflect end-user scenarios. I've provided one suggestion to refactor the implementation for better code clarity and maintainability.
|
cc: @nrghosh |
kouroshHakha
left a comment
There was a problem hiding this comment.
There is a fundamental problem found in this issue / PR that needs to be addressed properly. The gist of the issue is that we did not enforce any standard signature for builder methods. it implicitly started with config, preprocess, postprocess and for some builders we added chat_template_kwargs` that went missing by other builders that were not on the critical path. The proper fix is either: 1) enforce a strong typing / signature for the builder methods or 2) make the builder kwargs a passthrough towards the registered builder functions.
So here is my proposal for fixing this fundamentally and is more aligned with approach 2.
-
change the signature of the public
build_llm_processorto (config, preprocess, postprocess, builder_kwargs) -
Keep the old things as is, and pass through the builder_kwargs to the registered builder function. If the builder function does not have the matching signature it will barf during the build.
The current fix in this PR is not good, because it creates a leakage that OfflineProcessorConfigs will always have chat_template_kwargs which is again an implicit assumption.
I think the second approach is more generic and flexible.
nrghosh
left a comment
There was a problem hiding this comment.
taking a first pass to address comments
hao-aaron
left a comment
There was a problem hiding this comment.
Agree with kourosh, i think it makes more sense for arg checking to be done inside each builder function.
e7fb1b4 to
66f1517
Compare
|
microcheck failure doesn't seem to be relevant: |
python/ray/data/llm.py
Outdated
| # Pass through any additional builder kwargs | ||
| if builder_kwargs is not None: | ||
| # Check for conflicts with explicitly passed arguments | ||
| reserved_keys = {"preprocess", "postprocess"} | ||
| conflicting_keys = reserved_keys & builder_kwargs.keys() | ||
| if conflicting_keys: | ||
| raise ValueError( |
There was a problem hiding this comment.
could you create a utility on ProcessBuilder to do this validation there?
ProcessBuilder.validate_builder_kwargs(builder_kwargs)
return ProcessBuilder.build(config, preprocess, postprocess, builder_kwargs)
There was a problem hiding this comment.
Sounds good, done in the latest revision.
| @@ -188,6 +188,110 @@ def overrider(name: str, stage: StatefulStage): | |||
| ) | |||
|
|
|||
|
|
|||
| def test_builder_kwargs_passthrough(): | |||
There was a problem hiding this comment.
Could you spearate out these test scenarios into different test methods? Maybe create a Test class to capture them all and share resource between them using fixtures, etc.
There was a problem hiding this comment.
Yep, done in the latest revision.
…s that don't support it Signed-off-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com>
Signed-off-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com>
- use generic `builder_kwargs` passthrough in `build_llm_processor` - replace `chat_template_kwargs` param with `builder_kwargs` dict that passes through to the registered builder functions - remove implicit assumptions and have builders raise `TypeError` for unsupported kwargs - test passthrough with conflicts Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com>
Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com>
1e74785 to
6df4716
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively resolves the issue of chat_template_kwargs being passed to unsupported processors by introducing a more generic builder_kwargs dictionary. This is a solid architectural improvement that enhances flexibility and robustness. The validation for reserved keys is a good safeguard, and updating the tests to use the public build_llm_processor API makes them more representative of end-user scenarios. The changes are well-implemented, and the new tests are thorough. I have one minor suggestion to simplify the code.
Signed-off-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com>
6df4716 to
1fd1b19
Compare
Signed-off-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com>
d1f88ff to
d554625
Compare
| preprocess=lambda row: {"val": row["id"]}, | ||
| builder_kwargs={conflicting_key: lambda row: {"other": row["id"]}}, | ||
| ) | ||
|
|
There was a problem hiding this comment.
Bug: Test Registry Persistence Causes Flaky Errors
The ProcessorBuilder registry isn't consistently cleared between tests. test_builder() registers DummyProcessorConfig without unregistering it, leading to flaky "already registered" errors in TestBuilderKwargsValidation tests when test_builder() runs first.
…project#57061) Signed-off-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com> Co-authored-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Co-authored-by: Nikhil Ghosh <nikhil@anyscale.com>
…project#57061) Signed-off-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com> Co-authored-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Co-authored-by: Nikhil Ghosh <nikhil@anyscale.com> Signed-off-by: Josh Kodi <joshkodi@gmail.com>
…project#57061) Signed-off-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com> Co-authored-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Co-authored-by: Nikhil Ghosh <nikhil@anyscale.com>
…project#57061) Signed-off-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com> Co-authored-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Co-authored-by: Nikhil Ghosh <nikhil@anyscale.com> Signed-off-by: xgui <xgui@anyscale.com>
…project#57061) Signed-off-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com> Co-authored-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Co-authored-by: Nikhil Ghosh <nikhil@anyscale.com>
…project#57061) Signed-off-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com> Co-authored-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Co-authored-by: Nikhil Ghosh <nikhil@anyscale.com> Signed-off-by: Aydin Abiar <aydin@anyscale.com>
…project#57061) Signed-off-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com> Co-authored-by: jeffreyjeffreywang <jeffjeffreywang@gmail.com> Co-authored-by: Nikhil Ghosh <nikhil@anyscale.com> Signed-off-by: Future-Outlier <eric901201@gmail.com>
Why are these changes needed?
chat_template_kwargswas introduced in #56490 and is currently passed through all processors, even though some (e.g.,ServeDeploymentProcessorandHttpRequestProcessor) do not support this field. As a result, constructing aServeDeploymentProcessorviabuild_llm_processorraises errors.This issue wasn’t caught in tests because they have been using
ProcessorBuilder.build, which bypasses the layer wherechat_template_kwargsis passed.In this PR, we:
builder_kwargsand delegate their validation to individual processors. Thechat_template_kwargswill be passed as part ofbuilder_kwargsto thevLLMEngineProcessor.Related issue number
Resolves #57060
Checks
git commit -s) in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.Note
Make build_llm_processor skip chat_template_kwargs for non-offline processors and update processor tests to use public ray.data.llm APIs.
build_llm_processorto only passchat_template_kwargswhenconfigis anOfflineProcessorConfig.ray.data.llmand usebuild_llm_processorinstead ofProcessorBuilder.buildwhere applicable.Written by Cursor Bugbot for commit fb36cc3. This will update automatically on new commits. Configure here.