Skip to content

Support device as Dict key#65079

Closed
pbelevich wants to merge 8 commits intogh/pbelevich/156/basefrom
gh/pbelevich/156/head
Closed

Support device as Dict key#65079
pbelevich wants to merge 8 commits intogh/pbelevich/156/basefrom
gh/pbelevich/156/head

Conversation

@pbelevich
Copy link
Contributor

@pbelevich pbelevich commented Sep 15, 2021

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Sep 15, 2021

🔗 Helpful links

💊 CI failures summary and remediations

As of commit 6e3345e (more details on the Dr. CI page):


  • 1/1 failures introduced in this PR

1 failure not recognized by patterns:

Job Step Action
GitHub Actions linux-xenial-cuda11.3-py3.6-gcc7 / build Build 🔁 rerun

This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@pbelevich pbelevich requested review from lw, mrshenli and suo September 15, 2021 18:12
This is required to use RPC DeviceMap aka Dict[torch.device, torch.device] in torchscript




[ghstack-poisoned]
This is required to use RPC DeviceMap aka Dict[torch.device, torch.device] in torchscript




[ghstack-poisoned]
This is required to use RPC DeviceMap aka Dict[torch.device, torch.device] in torchscript




[ghstack-poisoned]
This is required to use RPC DeviceMap aka Dict[torch.device, torch.device] in torchscript




[ghstack-poisoned]
This is required to use RPC DeviceMap aka Dict[torch.device, torch.device] in torchscript




[ghstack-poisoned]
This is required to use RPC DeviceMap aka Dict[torch.device, torch.device] in torchscript




[ghstack-poisoned]
Copy link
Contributor

@lw lw left a comment

Choose a reason for hiding this comment

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

Overall looks good to me (with one suggestion).

} else if (ivalue.isTensor()) {
return std::hash<TensorImpl*>()(ivalue.toTensor().unsafeGetTensorImpl());
} else if (ivalue.isDevice()) {
return std::hash<std::string>()(ivalue.toDevice().str());
Copy link
Contributor

Choose a reason for hiding this comment

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

There already exists a specialization of std::hash for devices:

struct hash<c10::Device> {

Hence this could be simplified, and made more idiomatic and efficient, by doing:

Suggested change
return std::hash<std::string>()(ivalue.toDevice().str());
return std::hash<Device>()(ivalue.toDevice());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for suggestion!

This is required to use RPC DeviceMap aka Dict[torch.device, torch.device] in torchscript




[ghstack-poisoned]
@pbelevich
Copy link
Contributor Author

@pbelevich has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@pbelevich merged this pull request in 19a1063.

@facebook-github-bot facebook-github-bot deleted the gh/pbelevich/156/head branch September 24, 2021 14:17
@tugsbayasgalan tugsbayasgalan changed the title [JIT] Support device as Dict key Support device as Dict key Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants