Skip to content

Conversation

@pangyoki
Copy link
Contributor

@pangyoki pangyoki commented Oct 10, 2020

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.

Cannot use GPU because there is no GPU detected on your machine.
  • Reason
    To open dygraph mode by default. disable static() is used in paddle/__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 is None. It will raise Error if CUDA device is not set properly.
if core.is_compiled_with_cuda():
     _global_expected_place_ = core.CUDAPlace(0)

This PR is used to solve this problem. CPU device will be used by default when there's no proper CUDA devices.

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@pangyoki pangyoki changed the title fix Error of gpu version paddle when have no CUDA device fix Error of gpu version paddle when CUDA device is not set properly Oct 10, 2020
if device_count > 0:
_global_expected_place_ = core.CUDAPlace(0)
else:
logging.warning(
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

_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."
Copy link
Contributor

Choose a reason for hiding this comment

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

But -> but

Copy link
Contributor Author

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
Copy link
Contributor

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(
Copy link
Contributor

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.

Copy link
Contributor

@luotao1 luotao1 left a 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

@zhiqiu zhiqiu merged commit 6150cc8 into PaddlePaddle:develop Oct 14, 2020
chen-zhiyu pushed a commit to chen-zhiyu/Paddle that referenced this pull request Oct 15, 2020
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants