-
Notifications
You must be signed in to change notification settings - Fork 183
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
Add shutdown method to Flare Client API #3152
base: main
Are you sure you want to change the base?
Conversation
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.
See my comments and questions.
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.
We need to be able to shutdown the API.
0ece3c2
to
ca7b69c
Compare
83f8165
to
94544fe
Compare
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.
See my comments for corrections and improvement.
return client_api.receive(timeout) | ||
global default_context | ||
local_ctx = ctx if ctx else default_context | ||
return local_ctx.api.receive(timeout) |
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.
Should check local_ctx is not None. If none, raise exception.
return client_api.send(model, clear_cache) | ||
global default_context | ||
local_ctx = ctx if ctx else default_context | ||
return local_ctx.api.send(model, clear_cache) |
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.
Should check local_ctx is not None. If none, raise exception.
return client_api.system_info() | ||
global default_context | ||
local_ctx = ctx if ctx else default_context | ||
return local_ctx.api.system_info() |
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.
Should check local_ctx is not None. If none, raise exception.
return client_api.get_config() | ||
global default_context | ||
local_ctx = ctx if ctx else default_context | ||
return local_ctx.api.get_config() |
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.
Should check local_ctx is not None. If none, raise exception.
nvflare/client/api_context.py
Outdated
def _create_client_api(self, api_type: ClientAPIType) -> APISpec: | ||
"""Creates a new client_api based on the provided API type.""" | ||
if api_type == ClientAPIType.IN_PROCESS_API: | ||
return data_bus.get_data(CLIENT_API_KEY) |
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.
What if it doesn't exist in data_bus? Should raise exception.
nvflare/client/ex_process/api.py
Outdated
@@ -206,3 +205,7 @@ def clear(self): | |||
model_registry = self.get_model_registry() | |||
model_registry.clear() | |||
self.receive_called = False | |||
|
|||
def shutdown(self): | |||
model_registry = self.get_model_registry() |
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.
What if the app calls shutdown multiple times?
How do you ensure that cell agent is closed? You need to keep flare_agent in "self" and then call self.flare_agent.stop().
|
||
def shutdown(self): | ||
self.stop = True | ||
self.stop_reason = "API shutdown called." |
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.
Any resources to clean up? Anything to stop?
nvflare/client/task_registry.py
Outdated
@@ -114,6 +114,6 @@ def clear(self) -> None: | |||
def __str__(self): | |||
return f"{self.__class__.__name__}(config: {self.config.get_config()})" | |||
|
|||
def __del__(self): | |||
def shutdown(self): |
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.
Why does task registry have flare_agent? This design seems very odd. It is created when init the API, hence it should belong to the API, and shutdown there too.
In general, the creator of a resource is responsible for its lifecycle (create and shutdown/close/stop/destroy).
class SummaryWriter: | ||
class _BaseWriter: | ||
def __init__(self, ctx: Optional[APIContext] = None): | ||
global default_context |
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.
Should minimize use of gloabl.
You can do: ctx = api.get_default_ctx().
71ffe16
to
df38c1c
Compare
Issue
Description
New API Usage:
Types of changes
./runtest.sh
.