karthik-0306 opened a new issue, #41384:
URL: https://github.com/apache/beam/issues/41384

   ### What happened?
   
   `OnnxModelHandlerNumpy` (`onnx_inference.py`) and `XGBoostModelHandler` 
(`xgboost_inference.py`) don't override `ModelHandler.update_model_path`, which 
is a no-op in the base class. When `RunInference` gets a new `ModelMetadata` on 
`model_metadata_pcoll` (for example from `WatchFilePattern`), 
`_RunInferenceDoFn._load_model` calls `update_model_path(new_path)` and then 
`load_model()`, which reloads the original `model_uri` / `model_state`. The 
pipeline keeps using the old model, with no error or warning, and caches it 
under the new model's tag.
   
   Repro: two `LinearRegression` models converted with skl2onnx, `a.onnx` (y = 
x) and `b.onnx` (y = 100x):
   
   ```python
   side = p | 'side' >> beam.Create([ModelMetadata(model_id='b.onnx', 
model_name='b')])
   _ = (p | beam.Create([np.array([2.0], dtype=np.float32)])
          | RunInference(OnnxModelHandlerNumpy('a.onnx'), 
model_metadata_pcoll=side))
   ```
   
   The prediction is `2.0` (model a). The same pipeline with 
`SklearnModelHandlerNumpy` and pickled models returns `200.0` with `model_id` 
set to `b.pkl`. The ONNX results also have `model_id=None`, because 
`run_inference` doesn't pass `model_id` to `_convert_to_result`.
   
   The PyTorch, sklearn, TensorFlow and HuggingFace handlers implement 
`update_model_path`. Side-input model updates (#25200) and the ONNX handler 
(#24911) were merged a week apart in February 2023, and the XGBoost handler 
(#24965) a month later.
   
   Expected: after the side input emits `b.onnx`, RunInference uses model b, as 
it does for the sklearn handler. I plan to add `update_model_path` to both 
handlers and set `model_id` on the ONNX results.
   
   Version: master at b791929763 (2.79.0.dev).
   
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [x] Component: Python SDK
   - [ ] Component: Java SDK
   - [ ] Component: Go SDK
   - [ ] Component: Typescript SDK
   - [ ] Component: IO connector
   - [ ] Component: Beam YAML
   - [ ] Component: Beam examples
   - [ ] Component: Beam playground
   - [ ] Component: Beam katas
   - [ ] Component: Website
   - [ ] Component: Infrastructure
   - [ ] Component: Spark Runner
   - [ ] Component: Flink Runner
   - [ ] Component: Prism Runner
   - [ ] Component: Hazelcast Jet Runner
   - [ ] Component: Google Cloud Dataflow Runner


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to