Skip to content

Commit

Permalink
Added external script for fed_job API (NVIDIA#2623)
Browse files Browse the repository at this point in the history
* Added external script for fed_job API.

* enforce must deploy a controller or executor before adding external script.

---------

Co-authored-by: Yuan-Ting Hsieh (謝沅廷) <yuantingh@nvidia.com>
  • Loading branch information
2 people authored and nvidianz committed Jul 8, 2024
1 parent a6be2f5 commit 14f7c77
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions nvflare/job_config/fed_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ def to(
else:
print(f"{target} already set to use GPU {self._gpus[target]}. Ignoring gpu={gpu}.")
self._deploy_map[target].add_executor(obj, tasks=tasks)
elif isinstance(obj, str): # treat the str type object as external script
if target not in self._deploy_map:
raise ValueError(
f"{target} doesn't have a `Controller` or `Executor`. Deploy one first before adding external script!"
)

self._deploy_map[target].add_external_scripts([obj])
else: # handle objects that are not Controller or Executor type
if target not in self._deploy_map:
raise ValueError(
Expand Down Expand Up @@ -214,8 +221,9 @@ def _add_referenced_components(self, base_component, target):
parameters = get_component_init_parameters(base_component)
attrs = base_component.__dict__
for param in parameters:
if param in attrs:
base_id = attrs[param]
attr_key = param if param in attrs.keys() else "_" + param
if attr_key in attrs.keys():
base_id = attrs[attr_key]
if isinstance(base_id, str): # could be id
if base_id in self._components:
self._deploy_map[target].add_component(self._components[base_id], base_id)
Expand Down

0 comments on commit 14f7c77

Please sign in to comment.