【发布时间】:2022-01-27 02:30:13
【问题描述】:
我正在编写一个 pytest 文件来检查我的机器学习库是否使用 GPU。对于 Tensorflow,我可以使用 tf.config.list_physical_devices() 进行检查。对于 XGBoost,到目前为止,我在运行我的软件时通过查看 GPU 利用率 (nvdidia-smi) 对其进行了检查。但是我怎样才能在一个简单的测试中检查呢?类似于我对 Tensorflow 进行的测试。
import pytest
import tensorflow as tf
import xgboost
# Marking all tests to be GPU dependent
pytestmark = pytest.mark.gpu
def test_tf_finds_gpu():
"""Check if Tensorflow finds the GPU."""
assert tf.config.list_physical_devices("GPU")
def test_xgb_finds_gpu():
"""Check if XGBoost finds the GPU."""
...
# What can I write here?
【问题讨论】:
标签: python tensorflow gpu