问题:Cannot assign a device for operation Variable
报错代码:
import tensorflow as tf
import numpy as np
import os
os.environ["CUDA_DEVICES_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"with tf.device("/gpu:0"): ## 与下面注释的命令等价
# with tf.device("/job:localhost/replica:0/task:0/device:GPU:0"):a = tf.Variable(0,dtype=tf.float32)with tf.device("/gpu:1"):b = tf.constant(0, shape=[1], dtype=tf.float32)config = tf.ConfigProto()
config.gpu_options.allow_growth = True
config.log_device_placement = True
with tf.Session(config=config) as sess:sess.run(tf.global_variables_initializer())c = sess.run(a)b_ = sess.run(b)print(b_,c)
报错:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation Variable: node Variable (defined at /wzg_code/×××/multi_gpu_test.py:19) was explicitly assigned to /device:GPU:1 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:1 ]. Make sure the device specification refers to a valid device.[[Variable]]
当时考虑了将 tf.device("gpu:0") 的位置改成: tf.device(“/job:localhost/replica:0/task:0/device:XLA_GPU:0”),仍然报错,最后发现需要在sess的配置上进行修改,增加 config.allow_soft_placement=True,虽然不知道为什么,但是work了。更正后的代码如下:
import tensorflow as tf
import numpy as np
import os
os.environ["CUDA_DEVICES_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"with tf.device("/gpu:0"):
# with tf.device("/job:localhost/replica:0/task:0/device:GPU:0"):a = tf.Variable(0,dtype=tf.float32)with tf.device("/gpu:1"):b = tf.constant(0, shape=[1], dtype=tf.float32)#config = tf.ConfigProto()
config = tf.ConfigProto(allow_soft_placement=True)
config.gpu_options.allow_growth = True
config.log_device_placement = True
with tf.Session(config=config) as sess:sess.run(tf.global_variables_initializer())c = sess.run(a)b_ = sess.run(b)print(b_,c)
问题:Cannot assign a device for operation Variable相关推荐
- Cannot assign a device for operation
Cannot assign a device for operation 参考:https://blog.csdn.net/sjwzdh/article/details/103301380/ 解决方法 ...
- tensorflow错误:InvalidArgumentError (see above for traceback): Cannot assign a device for operation
一.错误 InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'shuffle_b ...
- train_image_classifier.py:Cannot assign a device for operation CifarNet/conv1/Conv2D: node CifarNet
出错内容如下: Errors may have originated from an input operation. Input Source operations connected to nod ...
- Make sure the device specification refers to a valid device
开始调用 with tf.Session() as sess,tf.device('/gpu:0'): 时报错: InvalidArgumentError (see above for traceba ...
- float gpu 加速_tensorflow - GPU 加速
首先检测是否可用 GPU importtensorflow as tfprint('GPU', tf.test.is_gpu_available()) #GPU True tf.device Tens ...
- IPU Saved Model Tool 异常处理
IPU未初始化 No device target has been configured. Did you configure the IPU devices by running `tensorfl ...
- Tensorflow分布式训练原理
以下文章摘录自: <机器学习观止--核心原理与实践> 京东: https://item.jd.com/13166960.html 当当:http://product.dangdang.co ...
- 搭建迁移训练Slim框架环境
前言 Slim是一个小巧.微型基于Tensor Flow的训练框架,它支持许多轻量级的神经网络,如:Mobilenet,能够快速训练在微型低功耗的设备上运算的神经网络,在MCU上一般运算赫兹都在百兆上 ...
- NLP实战之基于seq2seq的有约束文本生成
seq2seq构建写对联AI 问题背景介绍 对联又称对子,对仗工整,平仄协调,是一字一音的汉文语言独特的艺术形式,是中国传统文化瑰宝.对联的上下联有着非常工整的对应关系,我们可以尝试使用神经网络学习对 ...
最新文章
- call指令和ret指令的配合使用
- iOS Assigning to 'idXXXDelegate' from incompatible type 'BViewController *__strong'
- boost::icl::interval_map用法的测试程序
- 前端MVC Vue2学习总结(四)——条件渲染、列表渲染、事件处理器
- python面向对象变成(1):类的基本概念
- vue 右键菜单插件 简单、可扩展、样式自定义的右键菜单
- python远程控制终端数据_python 网络远程控制
- Atitit.月度计划日程表 每月流程表v5
- 计算机dll修复工具,DLL修复工具有哪些?DLL修复工具盘点
- php 省市区县 四级联动,GitHub - yupoxiong/region: ThinkPHP5/6省市区(县)街道四级联动扩展...
- 诊断实验评估指标-灵敏度(sensitivity)特异度(specificity)准确度(accuracy)
- 攻防世界web练习5
- 深度讲解VIEWPORT和PX是什么
- 4.(简答题,25.0分) (20分)(1)定义一个新冠病毒类Virus,定义一个德尔塔病毒类(Delta)和奥密克戎病毒类(Omicron),这两个类是新冠病毒类的子类;定义一个“可抵御地”接口,德
- 标准化存贷款数据报送系统
- 几款游戏引擎技术对比
- 云计算系统体系架构介绍
- [创新实践] SLAM简介
- windows连接Linux服务器 安装禅道
- 通过adb命令卸载小米手机预设的应用
热门文章
- mos管结电容等效模型_MOS管等效模型
- cmd做个定时弹窗_windows如何设置定时关机?
- BCrypt加密怎么存入数据库_松哥手把手带你入门 Spring Security,别再问密码怎么解密了...
- vbox虚拟系统和主系统自动挂载共享文件夹
- python视频压缩算法_Python入门到精通视频,阿里巴巴大力推荐,20行Python代码,无损压缩千百张图片!...
- 循环在c语言中的表示什么作用,《C语言中的for循环》教案
- Java Scheduler ScheduledExecutorService ScheduledThreadPoolExecutor示例
- 凉亭瓦片计算方式_凉亭简介
- python string_Python String center()
- 苹果x翻新机序列号开头_Android翻新电话每隔X秒