开发者社区 > 大数据与机器学习 > 人工智能平台PAI > 正文

麻烦问下机器学习PAI,本地单机训练没问题,配了tf_config开启训练报这个错大概是啥问题?

tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: using a tf.Tensor as a Python bool is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
Exception ignored in: >
Traceback (most recent call last):
File "/venv/lib/python3.6/site-packages/tensorflow_core/python/training/server_lib.py", line 158, in del
AttributeError: 'NoneType' object has no attribute 'UnimplementedError'

麻烦问下机器学习PAI,本地单机训练没问题,配了tf_config开启train_distribute: PSStrategy训练报这个错大概是啥问题?

展开
收起
cuicuicuic 2023-07-16 18:52:51 84 0
2 条回答
写回答
取消 提交回答
  • 2000元阿里云代金券免费领取,2核4G云服务器仅799元/3年,新老用户都有优惠,立即抢购>>>

    错误信息 "tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: using a tf.Tensor as a Python bool is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function." 表示在计算图执行中,使用 tf.Tensor 作为 Python 的布尔值是不允许的。建议在函数上加上 @tf.function 装饰器或者切换到 Eager Execution 模式。

    异常信息 "Exception ignored in: > Traceback (most recent call last): File "/venv/lib/python3.6/site-packages/tensorflow_core/python/training/server_lib.py", line 158, in del AttributeError: 'NoneType' object has no attribute 'UnimplementedError'" 是由于某些原因导致服务器对象的销毁(del)时发生了异常。

    这两个错误可能与 TensorFlow 的版本、代码逻辑和环境设置有关。我们可以尝试一些常见的解决方案来处理这些问题:

    1. 使用 Eager Execution 模式:Eager Execution 模式允许即时执行 TensorFlow 的操作,而不是构建静态图并进行计算。通过将以下代码添加到开头,可以启用 Eager Execution 模式:

      import tensorflow as tf
      tf.compat.v1.enable_eager_execution()
      

      这样就可以避免第一个错误。

    2. 使用 tf.function 装饰器:如果你需要在计算图中运行代码,可以尝试给报错的函数加上 @tf.function 装饰器。这将使函数转换为 TensorFlow 的计算图,从而避免了相关错误。例如:

      @tf.function
      def my_function(...):
       ...
      

      这样就可以解决第一个错误。

    3. 检查代码逻辑和环境设置:确保你的代码逻辑正确,并且各种配置项(如 tf_config)已正确设置。

    如果以上方法都不能解决问题,还请提供更多详细信息,例如使用的 TensorFlow 版本、完整的错误堆栈跟踪等,以便我们能够更好地帮助你解决问题。

    2023-07-31 17:38:27
    赞同 展开评论 打赏
  • 2000元阿里云代金券免费领取,2核4G云服务器仅799元/3年,新老用户都有优惠,立即抢购>>>

    多机的地址要先自己配置好的,默认值是个示例,此回答整理自钉群“【EasyRec】推荐算法交流群”

    2023-07-16 19:01:38
    赞同 展开评论 打赏

相关产品

  • 人工智能平台 PAI
  • 热门讨论

    热门文章

    相关电子书

    更多
    大规模机器学习在蚂蚁+阿里的应用 立即下载
    阿里巴巴机器学习平台AI 立即下载
    机器学习及人机交互实战 立即下载
    http://www.vxiaotou.com