python-3.x - 如何拥有 tf.zero 形状的大矩阵
问题描述
print("sequences",len(sequences))
print("seq_length",(seq_length))
print("vocab size",(vocab_size))
X = tf.zeros((len(sequences), seq_length, vocab_size), dtype=tf.bool)
y = tf.zeros((len(sequences), vocab_size), dtype=tf.bool)
输出
sequences 30373553
seq_length 30
vocab size 1290174
ResourceExhaustedError Traceback (most recent call last)
<ipython-input-35-1bd9b1544ba0> in <module>()
2 print("seq_length",(seq_length))
3 print("vocab size",(vocab_size))
----> 4 X = tf.zeros((len(sequences), seq_length, vocab_size), dtype=tf.bool)
5 y = tf.zeros((len(sequences), vocab_size), dtype=tf.bool)
6
3 frames
/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)
ResourceExhaustedError: OOM when allocating tensor with shape[30373553,30,1290174] and type bool on /job:localhost/replica:0/task:0/device:CPU:0 by allocator cpu [Op:Fill] name: zeros/
在 tensorflow 2.0 上工作
我想制作一个形状为零的矩阵 [30373553,30,1290174]
在 TensorFlow 1.5 上运行相同的代码时没有这样的错误,但是在使用 Tensorflow 2.0 时给出了这个错误
解决方案
假设每个bool
元素使用 1 字节的内存,您的形状张量[30373553, 30, 1290174]
将需要大约 1200 TB 的内存才能实现。这么多内存...
我猜这在 TensorFlow 1.5 中并没有出错,因为旧的延迟执行范例,你可以tf.zeros([30373553, 30, 1290174])
毫无问题地调用,因为调用返回的符号张量在你调用之前不会实际分配到内存tf.Session.run()
中包含张量的 tf.Graph。然而,在 TensorFlow 2.0 中,Eager Execution 将在调用后立即执行内存分配。
推荐阅读
- angular - 角度 - 当用户离开一页(一个组件)时显示警报
- ios - swift:如何创建 UIPageViewController?
- java - 使用 Spring Boot 进行测试时仅从测试/资源加载数据
- django - Django 批量创建检查如何在批量对象和实例中已经存在?
- mysql - Mysql数据存储
- babeljs - 如何在 gatsby 项目中正确设置流 js?
- windows - Python 3.7 - 激活 venv 错误 参数格式不正确 65001 WINDOWS
- twitter-bootstrap - 透明图像在引导按钮上显示为白色
- css - “信箱” Android 平板电脑的响应式设计
- css - 为什么过渡在比桌面更小的屏幕上不起作用?