报错:Kernel Restarting The kernel for Untitled.ipynb appears to have died. It will restart automatical

你参考其他人的文章,安装好M1版本的TensorFlow环境后,使用notebook出现了一些问题。

import tensorflow as tf
import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"
tf.compat.v1.disable_eager_execution()
hello=tf.constant('Hello,TensorFlow')
config=tf.compat.v1.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.9
sess=tf.compat.v1.Session(config=config)
print(sess.run(hello))

执行后,提示:

b'Hello,TensorFlow'
2024-01-08 16:05:50.503566: I metal_plugin/src/device/metal_device.cc:1154] Metal device set to: Apple M1 Max
2024-01-08 16:05:50.503598: I metal_plugin/src/device/metal_device.cc:296] systemMemory: 64.00 GB
2024-01-08 16:05:50.503603: I metal_plugin/src/device/metal_device.cc:313] maxCacheSize: 24.00 GB
2024-01-08 16:05:50.503654: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:306] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2024-01-08 16:05:50.503691: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:272] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)
2024-01-08 16:05:50.505344: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:388] MLIR V1 optimization pass is not enabled

核心信息为:
2024-01-08 16:05:50.503566: I metal_plugin/src/device/metal_device.cc:1154] Metal device set to: Apple M1 Max
2024-01-08 16:05:50.503654: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:306] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2024-01-08 16:05:50.503691: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:272] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: )
2024-01-08 16:05:50.505344: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:388] MLIR V1 optimization pass is not enabled

出现则表示安装成功了。

同样,你可以直接在终端中执行以下命令:

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

出现以下内容,表示成功:
在这里插入图片描述
但是,如果使用TensorFlow过程中,notebook弹框显示:

Kernel Restarting
The kernel for Untitled.ipynb appears to have died. It will restart automatically.

这确实是个问题!

最后正确解决的办法是重新装TensorFlow。

其实,你在网上找教程,可能找到的是旧版本的安装教程!

所以导致你安装错误了,而目前我最新的版本是2.15.0,正确的安装方式请查看我的另外一篇文章:MacOS安装Miniforge、Tensorflow、Jupyter Lab等(2024年最新)

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Java代码中,当两个线程同时更新数据库表时出现死锁的错误,可以采取以下方法来避免和解决这个问题: 1. 优化并发控制:确保在更新数据库表之前,使用适当的并发控制机制对表进行合理的锁定和解锁操作。例如,可以使用数据库的悲观锁或乐观锁机制,或者使用并发控制工具类如synchronized关键字、ReentrantLock等。 2. 事务的粒度管理:根据具体情况调整事务的范围和粒度。如果两个线程需要同时更新同一张表的不同记录,可以考虑将事务的范围缩小到单条记录的级别,减少死锁的概率。 3. 查询和更新顺序的统一:尽量保持线程在执行查询和更新操作时的顺序一致。例如,可以约定所有线程按照相同的顺序访问数据库表,这样可以避免死锁的发生。 4. 减少事务持有时间:尽量减少事务持有锁的时间,只在必要时占用锁,并尽快释放锁。可以将事务拆分为多个较小的事务或使用批处理操作来减少事务持有时间。 5. 数据库隔离级别设置:根据具体需求和性能要求,适当调整数据库的隔离级别。更高的隔离级别(如Serializable)可以减少死锁的可能性,但也可能导致性能下降。 6. 引入超时机制:在代码中引入适当的超时机制,如果某个线程在一段时间内无法获取到所需的锁,可以放弃当前操作并进行重试或回滚,避免长时间阻塞和死锁。 请注意,解决死锁问题需要根据具体情况进行调整和测试,并且在设计数据库表结构和代码逻辑时要考虑并发控制和事务管理的方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值