Fix run_in_spark crash with new-style services (APIMethod)#5549
Open
Mr-Neutr0n wants to merge 2 commits intobentoml:mainfrom
Open
Fix run_in_spark crash with new-style services (APIMethod)#5549Mr-Neutr0n wants to merge 2 commits intobentoml:mainfrom
Mr-Neutr0n wants to merge 2 commits intobentoml:mainfrom
Conversation
The Spark batch processing code in spark.py was written for the legacy InferenceAPI interface which has .input and .output IO descriptors with from_arrow/to_arrow methods. After the service API refactor, services using the @bentoml.service() decorator produce APIMethod objects that don't have these attributes, causing an AttributeError at runtime. This patch adds detection for legacy vs new-style services and handles each appropriately: - Legacy services continue to use InferenceAPI.input/output with the existing HTTPClient, preserving backward compatibility. - New-style services use SyncHTTPClient (which auto-discovers endpoints from the server's schema) and handle Arrow RecordBatch conversion through pandas, with a helper that converts common return types (ndarray, list, dict, DataFrame) back to RecordBatch. - output_schema is now required for new-style services since APIMethod doesn't expose spark_schema(). Fixes bentoml#5524
For more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5524.
bentoml.batch.run_in_spark()crashes withAttributeError: 'APIMethod' object has no attribute 'input'when used with services defined via the@bentoml.service()decorator. The Spark batch code was written for the legacyInferenceAPIinterface and wasn't updated after the service API refactor.Changes
_is_legacy_service()to distinguish between legacyService(withInferenceAPI) and new-style services (withAPIMethod).InferenceAPI.input/outputIO descriptors and the existingHTTPClient, preserving full backward compatibility.SyncHTTPClientfrom_bentoml_impl.client(which auto-discovers endpoints from the running server's/schema.json) and convert Arrow RecordBatches through pandas. A_result_to_record_batch()helper handles converting common return types (ndarray, list, dict, DataFrame, etc.) back to Arrow RecordBatch format.output_schemais now required for new-style services, sinceAPIMethoddoesn't exposespark_schema(). A clear error message is raised if it's missing.Testing
Verified the fix against the reproduction case from the issue (service with
@bentoml.tasktakingnp.ndarrayinput, called viarun_in_sparkwith an explicitoutput_schema).