-
Notifications
You must be signed in to change notification settings - Fork 5.9k
fix Error of gpu version paddle when CUDA device is not set properly #27819
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
fix Error of gpu version paddle when CUDA device is not set properly #27819
Conversation
|
Thanks for your contribution! |
python/paddle/fluid/framework.py
Outdated
| if device_count > 0: | ||
| _global_expected_place_ = core.CUDAPlace(0) | ||
| else: | ||
| logging.warning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use warnings instead of logging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
python/paddle/fluid/framework.py
Outdated
| _global_expected_place_ = core.CUDAPlace(0) | ||
| else: | ||
| logging.warning( | ||
| "You are using GPU version Paddle, But Your CUDA Device is not set properly. CPU device will be used by default." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But -> but
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| try: | ||
| device_count = core.get_cuda_device_count() | ||
| except Exception as e: | ||
| device_count = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to do something if an Exception happens instead of just ignore it, we can raise warnings at least. It can be refined in the next PR.
| stderr=subprocess.PIPE) | ||
| stdout, stderr = ps_proc.communicate() | ||
|
|
||
| assert 'CPU device will be used by default' in str( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not important.
Since unittest is used, I recommend using unittest's API, like self.assertXXX instead of python's builtin assert.
luotao1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for framework.py
…addlePaddle#27819) * fix gpu version paddle Error when have no CUDA device * optimize format and add new unittest * fix coverage problem * fix unittest format * change static mode to dygraph mode * use subprocess in unittest
PR types
Others
PR changes
Others
Describe
When users install GPU version Paddle, CPU device can't be used if CUDA device is not set properly.
To open dygraph mode by default.
disable static()is used inpaddle/__init__.py. Refer to PR Use dygraph mode by default #27443 .When Paddle is compiled with CUDA version,
CUDAPlace(0)will be used if default place isNone. It will raise Error if CUDA device is not set properly.This PR is used to solve this problem. CPU device will be used by default when there's no proper CUDA devices.