Skip to content
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

Avoid searching all datasets in UserCode.asset property #9108

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions packages/syft/src/syft/service/code/user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
from ..action.action_object import ActionObject
from ..context import AuthedServiceContext
from ..dataset.dataset import Asset
from ..dataset.dataset import Dataset
from ..job.job_stash import Job
from ..output.output_service import ExecutionOutput
from ..output.output_service import OutputService
Expand Down Expand Up @@ -726,17 +725,6 @@ def assets(self) -> DictTuple[str, Asset] | SyftError:
if isinstance(api, SyftError):
return api

# get all assets on the server
datasets: list[Dataset] = api.services.dataset.get_all()
if isinstance(datasets, SyftError):
return datasets

all_assets: dict[UID, Asset] = {}
for dataset in datasets:
for asset in dataset.asset_list:
asset._dataset_name = dataset.name
all_assets[asset.action_id] = asset

# get a flat dict of all inputs
all_inputs = {}
inputs = self.input_policy_init_kwargs or {}
Expand All @@ -746,8 +734,11 @@ def assets(self) -> DictTuple[str, Asset] | SyftError:
# map the action_id to the asset
used_assets: list[Asset] = []
for kwarg_name, action_id in all_inputs.items():
asset = all_assets.get(action_id, None)
if asset:
assets = api.dataset.get_assets_by_action_id(uid=action_id)
if isinstance(assets, SyftError):
return assets
if assets:
asset = assets[0]
asset._kwarg_name = kwarg_name
used_assets.append(asset)

Expand Down
Loading