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

Set device = -1 but still using GPU #23

Closed
A-baoYang opened this issue Jan 30, 2023 · 3 comments
Closed

Set device = -1 but still using GPU #23

A-baoYang opened this issue Jan 30, 2023 · 3 comments
Assignees
Labels
Priority: Medium third priority Status: 3-Completed finished Type: Bug not work as expected
Milestone

Comments

@A-baoYang
Copy link

A-baoYang commented Jan 30, 2023

Hi @emfomy , thank you for your attention 🙏

ckip_transformers version

0.2.7

What happened

Set device = -1, but the model still uses GPU.

script:

from ckip_transformers.nlp import CkipNerChunker
ner_driver = CkipNerChunker(level=3, device=-1)
res = ner_driver(text_list)

Before running the script:
image

After running the script:
image

What do you think should happen instead

It should not consume GPU resources.

How to reproduce

Run the script in GPU enable env:

from ckip_transformers.nlp import CkipNerChunker
ner_driver = CkipNerChunker(level=3, device=-1)
res = ner_driver(text_list)

Operating System

Ubuntu 20.04.2 LTS

Development Environment

  • Python 3.8.12
  • PyTorch 1.9.0+cu111
  • Transformers 4.7.0
  • Tensorflow 2.11.0

Anything else

I've checked the source code, self.device is set as "cpu", and both model and data tensor has to(self.device), so it's weird to have this problem.
And if the environment has no GPU, the model script is still runnable.

@emfomy emfomy self-assigned this Mar 21, 2023
@emfomy emfomy added Priority: Medium third priority Type: Bug not work as expected labels Mar 21, 2023
@emfomy emfomy added this to the 0.3 milestone Mar 21, 2023
@emfomy
Copy link
Member

emfomy commented Mar 26, 2023

It seems to be a bug related to PyTorch's DataLoader with the pin_memory option enabled. The tensor in dataloader is always pinned on GPU.

To avoid this bug, please use pin_memory=False while calling the driver (see here).

I might set pin_memory defaults to False in the future version.

@emfomy emfomy added the Status: 2-Progressing working on it label Mar 26, 2023
@emfomy
Copy link
Member

emfomy commented Apr 9, 2023

Fixed in v0.3.3.

@emfomy emfomy closed this as completed Apr 9, 2023
@emfomy emfomy added Status: 3-Completed finished and removed Status: 2-Progressing working on it labels Apr 9, 2023
@A-baoYang
Copy link
Author

Thank you so much for the updates!

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: Bug not work as expected
Projects
None yet
Development

No branches or pull requests

2 participants