GPU内存在顺序模型初始化后直接填满,在训练期间不会更改(GPU Memory is full directly after sequential model initialization and w

编程入门 行业动态 更新时间:2024-10-10 11:27:22
GPU内存在顺序模型初始化后直接填满,在训练期间不会更改(GPU Memory is full directly after sequential model initialization and wont change during training)

我正在使用Keras,在Windows 7的后端张量流上使用NVIDIA Quadro M2000M GPU。

当我初始化包含5个GRU,5个Dropout和1个Dense图层的模型时,GPU内存使用量会跳至3800MB的4096MB并保持不变,直到我重新开始我的spyder会话。 在spyder中清除会话:

K.clear_session()

不起作用。 内存使用率保持在较高水平。

这样的模型分配GPU的这么多内存是正常的吗? 我可以改变什么,以便可以使用内存使用情况? 我想提高训练速度,我认为这种高内存使用会阻碍GPU充分发挥其潜力。

更新

我的模型看起来像这样:

model = Sequential() layers = [1, 70, 50,100, 50,20, 1] model.add(GRU( layers[1], #batch_size = 32, input_shape=(sequence_length, anzahl_features), return_sequences=True)) model.add(Dropout(dropout_1)) model.add(GRU( layers[2], #batch_size = 32, return_sequences=True)) model.add(Dropout(dropout_2)) model.add(GRU( layers[3], #batch_size = 32, return_sequences=True)) model.add(Dropout(dropout_3)) model.add(GRU( layers[4], #batch_size = 32, return_sequences=True)) model.add(Dropout(dropout_4)) model.add(GRU( layers[5], #batch_size = 32, return_sequences=False)) model.add(Dropout(dropout_5)) model.add(Dense( layers[6])) model.add(Activation('sigmoid'))

我的特征矩阵的大小为506x500x35(506个示例,500个序列长度和35个特征)。 批量大小设置为128.站点说明:我不是说这是完美的特征矩阵或模型配置。

这里还有GPU-Z的截图,我重新启动spyder并启动模型直到第二个时期:

I am using Keras, on the backend tensorflow on windows 7 with the NVIDIA Quadro M2000M GPU.

When i initialization my model which contains 5 GRU, 5 Dropout and 1 Dense layers the GPU memory usage jumps to 3800MB of 4096MB and stays there until i restart my spyder session. Clearing the session within spyder with:

K.clear_session()

does not work. The Memory usage stays at that high level.

Is it normal that such a model allocate this much memory of the GPU? What can i change so the memory usage can be used proberly? I want to improve the training speed and i think this high memory usage hinder the GPU to use her full potential.

Update

My model looks like this:

model = Sequential() layers = [1, 70, 50,100, 50,20, 1] model.add(GRU( layers[1], #batch_size = 32, input_shape=(sequence_length, anzahl_features), return_sequences=True)) model.add(Dropout(dropout_1)) model.add(GRU( layers[2], #batch_size = 32, return_sequences=True)) model.add(Dropout(dropout_2)) model.add(GRU( layers[3], #batch_size = 32, return_sequences=True)) model.add(Dropout(dropout_3)) model.add(GRU( layers[4], #batch_size = 32, return_sequences=True)) model.add(Dropout(dropout_4)) model.add(GRU( layers[5], #batch_size = 32, return_sequences=False)) model.add(Dropout(dropout_5)) model.add(Dense( layers[6])) model.add(Activation('sigmoid'))

My feature matrix has the size 506x500x35 (506 examples, 500 sequence length and 35 features). The batch size is set to 128. Site note: I am not saying that that is the perfect feature matrix or model configuration.

Here also a screenshot of GPU-Z where i restarted spyder and started the model until the second epoch:

最满意答案

默认情况下,TensorFlow会分配整个GPU内存。

如果您想更好地控制GPU内存使用,可以使用以下方法:

per_process_gpu_memory_fraction配置选项,或 allow_growth配置选项。

By default TensorFlow allocates the whole GPU memory.

If you want to have a better control on the GPU memory usage you can use these methods:

the per_process_gpu_memory_fraction config option, or the allow_growth config option.

更多推荐

本文发布于:2023-08-02 07:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1372708.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   顺序   模型   full   Memory

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!