解决TF训练提示 Not using XLA:CPU for cluster

训练时一直未太关注该搞错,启动训练后报警提示如下,了解了下XLA的设置,对性能有一定提升, 于是尝试解决
  W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set.  If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU.  To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.

按照提示说的 要设置环境变量,参照ubuntu环境变量设置

vim  /etc/profile ,在末尾加上如下两行

export XLA_FLAGS=--xla_hlo_profile
export TF_XLA_FLAGS=--tf_xla_cpu_global_jit

export PATH=$PATH:$XLA_FLAGS:$TF_XLA_FLAGS

source  /etc/profile

代码中 参照TF 官方的 链接    

1、with tf.xla.experimental.jit_scope():
   c = tf.matmul(a, b) # compiled

2、with tf.xla.experimental.jit_scope(compile_ops=False): d = tf.matmul(a, c) # not compiled

3、with tf.xla.experimental.jit_scope( compile_ops=lambda node_def: 'matmul' in node_def.op.lower()): e = tf.matmul(a, b) + d # matmul is compiled, the addition is not.

https://tensorflow.google.cn/versions/r1.15/api_docs/python/tf/xla/experimental/jit_scope?hl=zh-cn#example_usage

参照第一条 设置后再次启动训练 

TF_XLA_FLAGS=--tf_xla_cpu_global_jit    python xxx.py   未再出现 Not using XLA:CPU提示

另外参照 一些文章里提到 ,直接按如下 会报找不到 对应的flag ,可以设置到环境变量里再试试

TF_XLA_FLAGS=--xla_generate_hlo_graph=.* python xxx.py
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值