问题说明

tf.test.is_gpu_available()结果为TRUE,但有Not creating XLA devices, tf_xla_enable_xla_devices not set报错

XLA

XLA的全称是Accelerated Linear Algebra,即加速线性代数。作为一种深度学习编译器,长期以来被作为Tensorflow框架的一个试验特性被开发,历时至今已经超过两三年了,随着Tensorflow 2.X的发布,XLA也终于从试验特性变成了默认打开的特性。此外, Pytorch社区也在大力推动XLA在Pytorch下的开发,现在已经有推出PyTorch/XLA TPU版本,暂只支持谷歌平台TPU上使用。

分析原因

可见XLA是一个GPU加速模块,如果你的tf.test.is_gpu_available()结果为TRUE,TensorFlow也可使用GPU进行训练,但没打开XLA进行加速。2.4.0版本XLA功能默认关闭,官方更新文档给出了解决方案

即需要在系统环境变量中添加,使其默认打开XLA加速。博客https://blog.csdn.net/FriendshipTang/article/details/114685263给出了一种在代码前进行添加的方法

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'
类似于宏定义,但每次写代码都需要重新申明,有没有修改虚拟环境的系统变量的方法呢

最终解决

可以使用conda env config vars set TF_XLA_FLAGS=--tf_xla_enable_xla_devices设置当前虚拟环境中的自定义环境变量。设置完毕后需重新启动虚拟环境才可生效,再次使用tf.test.is_gpu_available()便不会再出现Not creating XLA devices, tf_xla_enable_xla_devices not set`报错,且训练速度会大大加快,可以使用以下代码进行速度测试。

import tensorflow as tf
import timeitwith tf.device('/cpu:0'):cpu_a = tf.random.normal([10000, 1000])cpu_b = tf.random.normal([1000, 2000])print(cpu_a.device, cpu_b.device)with tf.device('/gpu:0'):gpu_a = tf.random.normal([10000, 1000])gpu_b = tf.random.normal([1000, 2000])print(gpu_a.device, gpu_b.device)def cpu_run():with tf.device('/cpu:0'):c = tf.matmul(cpu_a, cpu_b)return cdef gpu_run():with tf.device('/gpu:0'):c = tf.matmul(gpu_a, gpu_b)return c# warm up  这里就当是先给gpu热热身了
cpu_time = timeit.timeit(cpu_run, number=10)
gpu_time = timeit.timeit(gpu_run, number=10)
print('warmup:', cpu_time, gpu_time)cpu_time = timeit.timeit(cpu_run, number=10)
gpu_time = timeit.timeit(gpu_run, number=10)
print('run time:', cpu_time, gpu_time)

参考博客

https://github.com/tensorflow/tensorflow/issues/44683
https://blog.csdn.net/weixin_42642296/article/details/112565119
https://blog.csdn.net/robot8me/article/details/109471568
https://blog.csdn.net/FriendshipTang/article/details/114685263

彻底解决conda环境下 tensorflow gpu版本出现的问题:Not creating XLA devices, tf_xla_enable_xla_devices not set相关推荐

  1. Windows 10环境下TensorFlow(gpu版本)配置教程——[图解] [详细版][零基础]

    Tensorflow环境下的深度学习框架的配置主要包含以下几步: 0.前言 1.PyCharm的安装步骤: 2.Python的安装步骤: 3.AnaConda的安装步骤: 4.CUDA的安装步骤: 5 ...

  2. 安装Tensorflow 报错false Not creating XLA devices, tf_xla_enable_xla_devices not set

    学习图像识别配置环境 https://blog.csdn.net/weixin_44170512/article/details/103990592 一步一步按照博主配置 执行到这两句 import ...

  3. tensorflow:Not creating XLA devices, tf_xla_enable_xla_devices not set

    运行代码出现 I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_d ...

  4. 解决:Not creating XLA devices, tf_xla_enable_xla_devices not set

    解决:Not creating XLA devices, tf_xla_enable_xla_devices not set 实验环境 提示如下 分析原因 解决方法 实验环境 Windows 10 N ...

  5. Ubuntu18解决:Not creating XLA devices, tf_xla_enable_xla_devices not set

    实验环境 ubuntu18 NVIDIA GeForce GTX 1050 CUDA11.0 CUDNN 8.0 Tesorflow-gpu 2.4.1 问题 分析原因 据说是Tesorflow-gp ...

  6. win10系统tensorflow2.4.0-gpu安装“Not creating XLA devices, tf_xla_enable_xla_devices not set”解决方法

    未解决前报错   最近在安装tensorflow2.4.0-gpu版本后的项目开发过程中出现了"Not creating XLA devices, tf_xla_enable_xla_dev ...

  7. Linux conda tensorflow-gpu安装及Not creating XLA devices, tf_xla_enable_xla_devices not set相关问题解决

    0.首先介绍一下conda创建虚拟环境的基本操作. (1)创建Python的虚拟环境,并指定Python版本,不指定的话会使用默认的版本(Conda Base 环境中的Python版本). conda ...

  8. 【Error】解决:Not creating XLA devices, tf_xla_enable_xla_devices not set

    提示如下 分析原因 据说是Tesorflow-gpu 2.4.1,默认情况下,不再注册XLA:CPU和XLA:GPU设备.如果确实需要它们,请可使用 os.environ['TF_XLA_FLAGS' ...

  9. tensorflow运行环境linux,在ubuntu或者min运行环境下安装gpu版本的tensorflow

    转载请注明出处:blog.csdn.net/sproll 本文描述在ubuntu系列操作系统上安装gpu版本的tensorflow的过程. 0,准备工作 BIOS中关闭板载显卡,显示器接在nvidia ...

最新文章

  1. Goldengate DDL复制相关注意事项
  2. #10010 「一本通 1.1 练习 6」糖果传递 (数学+贪心)
  3. AT4519-[AGC032D]Rotation Sort【dp】
  4. 三大纪律七项注意(Access数据库)
  5. 【转】DICOM医学图像处理:开源库mDCM与DCMTK的比較分析(一),JPEG无损压缩DCM图像
  6. 随机过程中的功率谱密度
  7. 在java中蓝色_Java基础
  8. Python学习总结之一 -- 基础篇
  9. Atitit.attilax的 case list 项目经验 案例列表
  10. oa系统服务器到国外,oa系统放到云服务器云服务器
  11. 判断是否是空对象_3分钟短文 | Laravel 查询结果检查是不是空,5个方法你别用错...
  12. 解决idea谷歌翻译插件不可用
  13. 管理员界面html,12套超酷的后台管理员界面网站模板
  14. 数模国赛备赛(1)元胞自动机CA 生命游戏 森林火灾 传染病模型 MATLAB版资源整理
  15. kettle命令运行工具(pan、kitchen、carte)
  16. Kotlin第二章:kotlin基础
  17. Transformer8
  18. linux项目部署、Nginx详解
  19. 什么是机器视觉? 和计算机视觉有什么区别?
  20. 医疗器械产品 EMC 测试与整改思路

热门文章

  1. 如何轻松拥有属于自己的淘宝店手机客户端?
  2. 高中音乐教学计算机,浅析多媒体计算机技术在高中音乐课的应用
  3. (纪中)1593. 【GDKOI训练】电视游戏问题(vidgame)【DP】
  4. Typora编辑器(蓝奏)
  5. 解决latex图片浮动体过多的报错:Output loop---100 consecutive dead cycles和Too many unprocessed floats
  6. 三国群英传服务器端架设修改,三国群英传ol9005版本架设单机方法
  7. 大牛关于学习C++的建议
  8. 用咖啡为模型解释一下装饰者模式
  9. python输出假分数_解析ArcGis的标注(一)——先看看分数式、假分数式标注是怎样实现的...
  10. 单片机STC89C52RC实现时钟(汇编语言)