解决:Not creating XLA devices, tf_xla_enable_xla_devices not set

本文介绍了解决TensorFlow 2.4.1环境下出现的“NotcreatingXLAdevices,tf_xla_enable_xla_devicesnotset”提示的方法。通过设置环境变量TF_XLA_FLAGS,可以消除该提示并启用XLA设备支持。
部署运行你感兴趣的模型镜像

解决:Not creating XLA devices, tf_xla_enable_xla_devices not set

实验环境

  • Windows 10
  • NVIDIA GeForce GTX 1050
  • CUDA11.0
  • CUDNN 8.0
  • Tesorflow-gpu 2.4.1

提示如下

在这里插入图片描述

分析原因

据说是Tesorflow-gpu 2.4.1,默认情况下,不再注册XLA:CPU和XLA:GPU设备。如果确实需要它们,请可使用

os.environ['TF_XLA_FLAGS'] = '--tf_xla_enable_xla_devices'

但是此标志最终将在后续发行版中删除。

解决方法

import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

print(tf.__version__)
a = tf.constant(1.)
b = tf.constant(2.)
print(a+b)
print('GPU:', tf.test.is_gpu_available())

改为

import tensorflow as tf
import os
os.environ['TF_XLA_FLAGS'] = '--tf_xla_enable_xla_devices'
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
print(tf.__version__)
a = tf.constant(1.)
b = tf.constant(2.)
print(a+b)
print('GPU:', tf.test.is_gpu_available())

即可!
在这里插入图片描述
在这里插入图片描述
你将会发现,在代码开头加了

os.environ['TF_XLA_FLAGS'] = '--tf_xla_enable_xla_devices'

将不会有

Not creating XLA devices, tf_xla_enable_xla_devices not set

提示!

您可能感兴趣的与本文相关的镜像

TensorFlow-v2.15

TensorFlow-v2.15

TensorFlow

TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型

{"author":"user","content":"2025-12-24 11:09:39.769900: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found\n2025-12-24 11:09:39.770109: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.\n2025-12-24 11:09:41.635755: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set\n2025-12-24 11:09:41.651637: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library nvcuda.dll\n2025-12-24 11:09:41.792188: E tensorflow/stream_executor/cuda/cuda_driver.cc:328] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected\n2025-12-24 11:09:41.795143: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: XNG-XDCWSXNXUEK\n2025-12-24 11:09:41.795329: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: XNG-XDCWSXNXUEK\n2025-12-24 11:09:41.796807: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2\nTo enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n2025-12-24 11:09:41.798930: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set\n2025-12-24 11:10:12.280533: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)","chatRequest":{"chatContext":[],"configs":{}}}
最新发布
12-25
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FriendshipT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值