forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 2
Add retry mechanism and dynamic model loading to SONIC framework #27
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
kakwok
wants to merge
1
commit into
fastmachinelearning:master
Choose a base branch
from
kakwok:SonicRetryDML_CMSSW_17_0_0_pre2
base: master
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.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #ifndef HeterogeneousCore_SonicCore_RetryActionBase | ||
| #define HeterogeneousCore_SonicCore_RetryActionBase | ||
|
|
||
| #include "FWCore/PluginManager/interface/PluginFactory.h" | ||
| #include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
| #include "HeterogeneousCore/SonicCore/interface/SonicClientBase.h" | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| // Base class for retry actions | ||
| class RetryActionBase { | ||
| public: | ||
| RetryActionBase(const edm::ParameterSet& conf, SonicClientBase* client); | ||
| virtual ~RetryActionBase() = default; | ||
|
|
||
| bool shouldRetry() const { return shouldRetry_; } // Getter for shouldRetry_ | ||
|
|
||
| virtual void retry() = 0; // Pure virtual function for execution logic | ||
| virtual void start() = 0; // Pure virtual function for execution logic for initialization | ||
|
|
||
| protected: | ||
| void eval(); // interface for calling evaluate in client | ||
| void finish(bool success); // interface for calling finish directly in client | ||
|
|
||
| protected: | ||
| SonicClientBase* client_; | ||
| bool shouldRetry_; // Flag to track if further retries should happen | ||
| }; | ||
|
|
||
| // Define the factory for creating retry actions | ||
| using RetryActionFactory = | ||
| edmplugin::PluginFactory<RetryActionBase*(const edm::ParameterSet&, SonicClientBase* client)>; | ||
|
|
||
| #endif | ||
|
|
||
| #define DEFINE_RETRY_ACTION(type) DEFINE_EDM_PLUGIN(RetryActionFactory, type, #type); |
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <use name="FWCore/Framework"/> | ||
| <use name="FWCore/PluginManager"/> | ||
| <use name="FWCore/ParameterSet"/> | ||
| <use name="HeterogeneousCore/SonicCore"/> | ||
| <plugin file="*.cc" name="pluginHeterogeneousCoreSonicCore"/> | ||
|
|
28 changes: 28 additions & 0 deletions
28
HeterogeneousCore/SonicCore/plugins/RetrySameServerAction.cc
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,28 @@ | ||
| #include "HeterogeneousCore/SonicCore/interface/RetryActionBase.h" | ||
| #include "HeterogeneousCore/SonicCore/interface/SonicClientBase.h" | ||
|
|
||
| class RetrySameServerAction : public RetryActionBase { | ||
| public: | ||
| RetrySameServerAction(const edm::ParameterSet& pset, SonicClientBase* client) | ||
| : RetryActionBase(pset, client), allowedTries_(pset.getUntrackedParameter<unsigned>("allowedTries", 0)) {} | ||
|
|
||
| void start() override { tries_ = 0; }; | ||
|
|
||
| protected: | ||
| void retry() override; | ||
|
|
||
| private: | ||
| unsigned allowedTries_, tries_; | ||
| }; | ||
|
|
||
| void RetrySameServerAction::retry() { | ||
| ++tries_; | ||
| //if max retries has not been exceeded, call evaluate again | ||
| if (tries_ >= allowedTries_) { | ||
| shouldRetry_ = false; // Flip flag when max retries are reached | ||
| edm::LogInfo("RetrySameServerAction") << "Max retry attempts reached. No further retries."; | ||
| } | ||
| eval(); | ||
| } | ||
|
|
||
| DEFINE_RETRY_ACTION(RetrySameServerAction) |
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,15 @@ | ||
| #include "HeterogeneousCore/SonicCore/interface/RetryActionBase.h" | ||
|
|
||
| // Constructor implementation | ||
| RetryActionBase::RetryActionBase(const edm::ParameterSet& conf, SonicClientBase* client) | ||
| : client_(client), shouldRetry_(true) { | ||
| if (client_ == nullptr) { | ||
| throw cms::Exception("RetryActionBase") << "client pointer cannot be null"; | ||
| } | ||
| } | ||
|
|
||
| void RetryActionBase::eval() { client_->evaluate(); } | ||
|
|
||
| void RetryActionBase::finish(bool success) { client_->finish(success); } | ||
|
|
||
| EDM_REGISTER_PLUGINFACTORY(RetryActionFactory, "RetryActionFactory"); |
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 |
|---|---|---|
| @@ -1,18 +1,34 @@ | ||
| #include "HeterogeneousCore/SonicCore/interface/SonicClientBase.h" | ||
| #include "HeterogeneousCore/SonicCore/interface/RetryActionBase.h" | ||
| #include "FWCore/Utilities/interface/Exception.h" | ||
| #include "FWCore/ParameterSet/interface/allowedValues.h" | ||
|
|
||
| // Custom deleter implementation | ||
| void SonicClientBase::RetryDeleter::operator()(RetryActionBase* ptr) const { delete ptr; } | ||
|
|
||
| SonicClientBase::SonicClientBase(const edm::ParameterSet& params, | ||
| const std::string& debugName, | ||
| const std::string& clientName) | ||
| : allowedTries_(params.getUntrackedParameter<unsigned>("allowedTries", 0)), | ||
| debugName_(debugName), | ||
| clientName_(clientName), | ||
| fullDebugName_(debugName_) { | ||
| : debugName_(debugName), clientName_(clientName), fullDebugName_(debugName_) { | ||
| if (!clientName_.empty()) | ||
| fullDebugName_ += ":" + clientName_; | ||
|
|
||
| const auto& retryPSetList = params.getParameter<std::vector<edm::ParameterSet>>("Retry"); | ||
| std::string modeName(params.getParameter<std::string>("mode")); | ||
|
|
||
| for (const auto& retryPSet : retryPSetList) { | ||
| const std::string& actionType = retryPSet.getParameter<std::string>("retryType"); | ||
|
|
||
| auto retryAction = RetryActionFactory::get()->create(actionType, retryPSet, this); | ||
| if (retryAction) { | ||
| //Convert to RetryActionPtr Type from raw pointer of retryAction | ||
| retryActions_.emplace_back(RetryActionPtr(retryAction.release())); | ||
| } else { | ||
| throw cms::Exception("Configuration") | ||
| << "Unknown Retry type " << actionType << " for SonicClient: " << fullDebugName_; | ||
| } | ||
| } | ||
|
|
||
| if (modeName == "Sync") | ||
| setMode(SonicMode::Sync); | ||
| else if (modeName == "Async") | ||
|
|
@@ -40,24 +56,34 @@ void SonicClientBase::start(edm::WaitingTaskWithArenaHolder holder) { | |
| holder_ = std::move(holder); | ||
| } | ||
|
|
||
| void SonicClientBase::start() { tries_ = 0; } | ||
| void SonicClientBase::start() { | ||
| totalTries_ = 0; | ||
| // initialize all actions | ||
| for (auto& action : retryActions_) { | ||
| action->start(); | ||
| } | ||
| } | ||
|
|
||
| void SonicClientBase::finish(bool success, std::exception_ptr eptr) { | ||
| //retries are only allowed if no exception was raised | ||
| if (!success and !eptr) { | ||
| ++tries_; | ||
| //if max retries has not been exceeded, call evaluate again | ||
| if (tries_ < allowedTries_) { | ||
| evaluate(); | ||
| //avoid calling doneWaiting() twice | ||
| return; | ||
| } | ||
| //prepare an exception if exceeded | ||
| else { | ||
| edm::Exception ex(edm::errors::ExternalFailure); | ||
| ex << "SonicCallFailed: call failed after max " << tries_ << " tries"; | ||
| eptr = make_exception_ptr(ex); | ||
| ++totalTries_; | ||
| edm::LogInfo("SonicClientBase") << "finish: failed after total tries of " << totalTries_; | ||
| for (const auto& action : retryActions_) { | ||
| if (action->shouldRetry()) { | ||
| edm::LogInfo("SonicClientBase") << "Calling retry()"; | ||
| // retry() must trigger eval() or finish() | ||
| action->retry(); | ||
| // return because another finish() was already called inside client->evaluate() | ||
|
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. is this comment still correct for the task-based implementation? |
||
| return; | ||
| } | ||
| } | ||
| //prepare an exception if no more retry actions left | ||
| edm::LogInfo("SonicClientBase") << "SonicCallFailed: call failed, no retry actions available after " << totalTries_ | ||
| << " tries."; | ||
| edm::Exception ex(edm::errors::ExternalFailure); | ||
| ex << "SonicCallFailed: call failed, no retry actions available after " << totalTries_ << " tries."; | ||
| eptr = make_exception_ptr(ex); | ||
| } | ||
| if (holder_) { | ||
| holder_->doneWaiting(eptr); | ||
|
|
@@ -74,7 +100,20 @@ void SonicClientBase::fillBasePSetDescription(edm::ParameterSetDescription& desc | |
| //restrict allowed values | ||
| desc.ifValue(edm::ParameterDescription<std::string>("mode", "PseudoAsync", true), | ||
| edm::allowedValues<std::string>("Sync", "Async", "PseudoAsync")); | ||
| if (allowRetry) | ||
| desc.addUntracked<unsigned>("allowedTries", 0); | ||
| if (allowRetry) { | ||
| // Defines the structure of each entry in the VPSet | ||
| edm::ParameterSetDescription retryDesc; | ||
| retryDesc.add<std::string>("retryType", "RetrySameServerAction"); | ||
| retryDesc.addUntracked<unsigned>("allowedTries", 0); | ||
|
|
||
| // Define a default retry action | ||
| edm::ParameterSet defaultRetry; | ||
| defaultRetry.addParameter<std::string>("retryType", "RetrySameServerAction"); | ||
| defaultRetry.addUntrackedParameter<unsigned>("allowedTries", 0); | ||
|
|
||
| // Add the VPSet with the default retry action | ||
| desc.addVPSet("Retry", retryDesc, {defaultRetry}); | ||
| } | ||
| desc.add("sonicClientBase", desc); | ||
| desc.addUntracked<bool>("verbose", false); | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| <iftool name="cuda"> | ||
| <use name="cuda"/> | ||
| </iftool> | ||
|
|
||
| <export> | ||
| <lib name="1"/> | ||
| <lib name="1"/> | ||
| </export> | ||
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.
is the explicit
RetryActionPtr()needed here? usually foremplace_back(), it shouldn't be