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

feat(util): Allow passing a torch.device instance #20

Merged
merged 1 commit into from
Aug 10, 2022

Conversation

pan93412
Copy link
Contributor

@pan93412 pan93412 commented Aug 8, 2022

Abstract

This PR allows us passing the torch.device constructed by ourselves, which is useful in using mps 1 as the backend instead of CUDA's.

Usage

device = torch.device("mps")
ws_driver = CkipWordSegmenter(model="bert-base", device=device)

Tests

I have tested in my Apple Silicon device, with the nightly version of PyTorch.
It works as intended without any observable bugs.

Footnotes

  1. https://pytorch.org/docs/stable/notes/mps.html

Abstract
======

This PR allows us passing the `torch.device` constructed by ourselves,
which is useful in using `mps` ([^1]) as the backend instead of CUDA's.

[^1] https://pytorch.org/docs/stable/notes/mps.html

Usage
=====

```py
device = torch.device("mps")
ws_driver  = CkipWordSegmenter(model="bert-base", device=device)
```

Tests
====

I have tested in my Apple Silicon device, with the nightly version of PyTorch.
It works as intended without any observable bugs.
@pan93412
Copy link
Contributor Author

pan93412 commented Aug 8, 2022

Screenshots

image

image

image

@emfomy emfomy changed the base branch from master to develop August 10, 2022 05:37
@emfomy emfomy self-requested a review August 10, 2022 05:37
@emfomy emfomy self-assigned this Aug 10, 2022
@emfomy emfomy added Priority: Medium third priority Status: 1-Assigned assigned an assignee Type: Enhancement request new feature labels Aug 10, 2022
@emfomy emfomy added this to the 0.3.0 milestone Aug 10, 2022
@emfomy emfomy merged commit 5258227 into ckiplab:develop Aug 10, 2022
@emfomy
Copy link
Member

emfomy commented Aug 10, 2022

Great PR!

@pan93412 pan93412 deleted the patch-1 branch August 10, 2022 05:52
@emfomy emfomy added Status: 3-Completed finished and removed Status: 1-Assigned assigned an assignee labels Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Medium third priority Status: 3-Completed finished Type: Enhancement request new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants