-
Notifications
You must be signed in to change notification settings - Fork 254
Add graph reinit on failure #4237
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
Open
atobiszei
wants to merge
14
commits into
main
Choose a base branch
from
atobisze_mp_reinit_graph
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+259
−52
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1850989
Fix python build for mp_on_py_off config
atobiszei 537cc52
Turn off unstable tests
atobiszei 271f337
Add graph reinit on failure
atobiszei 271ee8e
Merge remote-tracking branch 'origin/main' into atobisze_mp_reinit_graph
atobiszei 28aadd6
Merge remote-tracking branch 'origin/main' into atobisze_mp_reinit_graph
atobiszei 10477df
Remove default queue switch off
atobiszei 6b96b84
Fix style
atobiszei 4806c6b
Fix
atobiszei 8d60096
Fix CI: add ErrorOnNegativeTestCalculator to whitelist, remove queue …
atobiszei d6c7ff0
Move ErrorOnNegativeTestCalculator to its own file
atobiszei 4aee6d6
Review fixes
atobiszei 3ac2926
Self-review
atobiszei 25e3f72
Self-review
atobiszei 66d3f19
Self-review: add try/catch in GraphReinitGuard dtor, use this-> consi…
atobiszei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
|
|
||
| #include <atomic> | ||
| #include <condition_variable> | ||
| #include <exception> | ||
| #include <future> | ||
| #include <memory> | ||
| #include <mutex> | ||
|
|
@@ -39,6 +40,8 @@ | |
| #pragma GCC diagnostic pop | ||
| #pragma warning(pop) | ||
|
|
||
| #include "src/logging.hpp" | ||
|
|
||
| #include "graph_executor_constants.hpp" | ||
| #include "graph_side_packets.hpp" | ||
| #include "outputstreamobserver.hpp" | ||
|
|
@@ -65,7 +68,49 @@ struct GraphHelper { | |
| genAiExecutionContextMap(std::move(gh.genAiExecutionContextMap)), | ||
| currentTimestamp(gh.currentTimestamp) {} | ||
| GraphHelper& operator=(GraphHelper&&) = delete; | ||
| ~GraphHelper(); | ||
| // Creates a fresh CalculatorGraph, initializes it with the config, | ||
| // wires up output stream observers, builds side packets and starts the run. | ||
| absl::Status initialize(const ::mediapipe::CalculatorGraphConfig& config, const GraphSidePackets& sidePacketMaps); | ||
| // Tears down the current (errored) graph and rebuilds a fresh one | ||
| // with the same observers and side packets. Called when inference | ||
| // encounters a graph error to avoid returning a poisoned graph to the pool. | ||
| void reinitialize(const ::mediapipe::CalculatorGraphConfig& config, const GraphSidePackets& sidePacketMaps); | ||
| }; | ||
|
|
||
| // RAII guard that reinitializes the graph if inference exits with an error. | ||
| // Construct before the first graph interaction (packet push). Call dismiss() | ||
| // on the success path. If not dismissed, the destructor rebuilds the graph | ||
| // so the next request from the pool gets a clean graph. | ||
| class GraphReinitGuard { | ||
| GraphHelper& helper; | ||
| const ::mediapipe::CalculatorGraphConfig& config; | ||
| const GraphSidePackets& sidePacketMaps; | ||
| bool dismissed = false; | ||
|
|
||
| public: | ||
| GraphReinitGuard(GraphHelper& helper, | ||
| const ::mediapipe::CalculatorGraphConfig& config, | ||
| const GraphSidePackets& sidePacketMaps) : | ||
| helper(helper), | ||
| config(config), | ||
| sidePacketMaps(sidePacketMaps) {} | ||
| void dismiss() { dismissed = true; } | ||
| ~GraphReinitGuard() { | ||
| if (!dismissed) { | ||
| try { | ||
| helper.reinitialize(config, sidePacketMaps); | ||
| } catch (const std::exception& e) { | ||
| SPDLOG_ERROR("GraphReinitGuard: reinitialize threw: {}", e.what()); | ||
| } catch (...) { | ||
| SPDLOG_ERROR("GraphReinitGuard: reinitialize threw unknown exception"); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+99
to
+109
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case we could only log error anyway. Will add that. |
||
| GraphReinitGuard(const GraphReinitGuard&) = delete; | ||
| GraphReinitGuard& operator=(const GraphReinitGuard&) = delete; | ||
| }; | ||
|
|
||
| // we need to keep Graph alive during MP reload hence shared_ptr | ||
| class GraphQueue : public Queue<std::shared_ptr<GraphHelper>> { | ||
| std::shared_ptr<GraphSidePackets> sidePacketMaps; | ||
|
|
||
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
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
49 changes: 49 additions & 0 deletions
49
src/test/mediapipe/calculators/error_on_negative_test_calculator.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //***************************************************************************** | ||
| // Copyright 2026 Intel Corporation | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| //***************************************************************************** | ||
| #include <cstring> | ||
|
|
||
| #include <openvino/openvino.hpp> | ||
|
|
||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | ||
| #include "mediapipe/framework/calculator_framework.h" | ||
| #pragma GCC diagnostic pop | ||
|
|
||
| namespace mediapipe { | ||
|
|
||
| class ErrorOnNegativeTestCalculator : public CalculatorBase { | ||
| public: | ||
| static absl::Status GetContract(CalculatorContract* cc) { | ||
| cc->Inputs().Index(0).Set<ov::Tensor>(); | ||
| cc->Outputs().Index(0).Set<ov::Tensor>(); | ||
| return absl::OkStatus(); | ||
| } | ||
| absl::Status Open(CalculatorContext* cc) final { return absl::OkStatus(); } | ||
| absl::Status Close(CalculatorContext* cc) final { return absl::OkStatus(); } | ||
| absl::Status Process(CalculatorContext* cc) final { | ||
| ov::Tensor input = cc->Inputs().Index(0).Get<ov::Tensor>(); | ||
| if (static_cast<float*>(input.data())[0] < 0.0f) { | ||
| return absl::InvalidArgumentError("Negative input value"); | ||
| } | ||
| ov::Tensor output(input.get_element_type(), input.get_shape()); | ||
| std::memcpy(output.data(), input.data(), input.get_byte_size()); | ||
| cc->Outputs().Index(0).Add(new ov::Tensor(output), cc->InputTimestamp()); | ||
| return absl::OkStatus(); | ||
| } | ||
| }; | ||
|
|
||
| REGISTER_CALCULATOR(ErrorOnNegativeTestCalculator); | ||
| } // namespace mediapipe |
Oops, something went wrong.
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.
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.
Unit test that will ensure failed graphs are reusable is missing
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.
Added test