Skip to content

fix attributeerror in tutorial part10#2990

Closed
Rachelxuan11 wants to merge 5 commits intoOpenMined:masterfrom
Rachelxuan11:dev
Closed

fix attributeerror in tutorial part10#2990
Rachelxuan11 wants to merge 5 commits intoOpenMined:masterfrom
Rachelxuan11:dev

Conversation

@Rachelxuan11
Copy link
Contributor

Problem
Run tutorial Part10 and got the same error as this issue #2758.
This error is shown as follows:

in train_enc()
17 spdz_params = list()
18 for remote_index in range(len(compute_node)): # for each client
---> 19 spdz_params.append(params[remote_index][param_i].copy().fix_precision().share(bob, alice, crypto_provider=james).get()) # AttributeError: 'numpy.ndarray' object has no attribute 'wrap', if .get() is used here. This could be avoided by model.get() first, and then .share() the copy to a list of clients. This obeys the actually protocol of encrypted model averaging, but fixes this bug.

Solution
user model.copy().get().fix_precision().share(...) instead of model.copy().fix_precision().share(...).get() could avoid this error

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

You'll be able to see Jupyter notebook diff and discuss changes. Powered by ReviewNB.

@Rachelxuan11 Rachelxuan11 requested a review from iamtrask February 1, 2020 08:15
Comment on lines +200 to 201
" epoch, batch_idx * data.shape[0], len(train_loader) * data.shape[0],\n",
" 100. * batch_idx / len(train_loader), loss.item()))\n",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a small change

" for data, target in test_loader:\n",
" output = model(data)\n",
" test_loss += F.mse_loss(output.view(-1), target, reduction='sum').item() # sum up batch loss\n",
" pred = output.data.max(1, keepdim=True)[1] # get the index of the max log-probability\n",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant for this example regression task

Comment on lines -461 to +460
" spdz_params.append(params[remote_index][param_i].copy().fix_precision().share(bob, alice, crypto_provider=james).get())\n",
" spdz_params.append(params[remote_index][param_i].copy().get().fix_precision().share(bob, alice, crypto_provider=james)\n",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid the AttributeError

@gmuraru
Copy link
Member

gmuraru commented Feb 2, 2020

It seems that there is an error here (it is lalso present on master, but also in this PR). Do you have some time to investigate :)

~/contrib/tests/PySyft/syft/generic/frameworks/hook/hook_args.py in <lambda>(i, **kwargs)
    742         if isinstance(r, (list, tuple))  # if the rule is a list or tuple.
    743         # Last if not, rule is probably == 1 so use type to return the right transformation.
--> 744         else lambda i, **kwargs: register_tensor(i, **kwargs)
    745         for a, r in zip(response, rules)  # And do this for all the responses / rules provided
    746     ]

~/contrib/tests/PySyft/syft/generic/frameworks/hook/hook_args.py in register_tensor(tensor, owner, response_ids)
    710             and each id is pop out when needed.
    711     """
--> 712     tensor.owner = owner
    713     try:
    714         tensor.id = response_ids.pop(-1)

AttributeError: 'numpy.ndarray' object has no attribute 'owner'

@github-actions
Copy link

This pull request has been marked stale because it has been open 30 days with no activity. Leave a comment or remove the stale label to unmark it. Otherwise, this will be closed in 7 days.

@github-actions github-actions bot added the Status: Stale 🍞 Been open for a while with no activity label May 22, 2020
@github-actions github-actions bot closed this May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Stale 🍞 Been open for a while with no activity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants