pytorch-rnn.flatten_parameters作用

部署运行你感兴趣的模型镜像

最近翻阅pytorch的代码,常常发现这样一句:rnn.flatten_parameters,但却不知道作用,遂作此文

rnn.flatten_parameters作用

Resets parameter data pointer so that they can use faster code paths

翻译一下,就是重置参数的数据指针。其实就是contiguous(连续性)的问题,在pytorch issue上有这样的warning:

UserWarning: RNN module weights are not part of single contiguous chunk of memory. This means they need to be compacted at every call, possibly greately increasing memory usage. To compact weights again call flatten_parameters()

我的理解是,为了提高内存的利用率和效率,调用flatten_parameters让parameter的数据存放成contiguous chunk(连续的块)。类似我们调用tensor.contiguous

参考链接:

您可能感兴趣的与本文相关的镜像

PyTorch 2.5

PyTorch 2.5

PyTorch
Cuda

PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理

D:\anaconda3\envs\Pytorch\Lib\site-packages\torch\cuda\__init__.py:235: UserWarning: NVIDIA GeForce RTX 5060 Laptop GPU with CUDA capability sm_120 is not compatible with the current PyTorch installation. The current PyTorch install supports CUDA capabilities sm_50 sm_60 sm_61 sm_70 sm_75 sm_80 sm_86 sm_90. If you want to use the NVIDIA GeForce RTX 5060 Laptop GPU GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/ warnings.warn( Traceback (most recent call last): File "d:\VSCodeProjects\WaterQualityPrediction\3.py", line 105, in <module> model = GRU_ODE_Predictor(input_dim=X.shape[2], hidden_dim=64, output_dim=1).to(device) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda3\envs\Pytorch\Lib\site-packages\torch\nn\modules\module.py", line 1340, in to return self._apply(convert) ^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda3\envs\Pytorch\Lib\site-packages\torch\nn\modules\module.py", line 900, in _apply module._apply(fn) File "D:\anaconda3\envs\Pytorch\Lib\site-packages\torch\nn\modules\rnn.py", line 288, in _apply self._init_flat_weights() File "D:\anaconda3\envs\Pytorch\Lib\site-packages\torch\nn\modules\rnn.py", line 215, in _init_flat_weights self.flatten_parameters() File "D:\anaconda3\envs\Pytorch\Lib\site-packages\torch\nn\modules\rnn.py", line 269, in flatten_parameters torch._cudnn_rnn_flatten_weight( RuntimeError: CUDA error: no kernel image is available for execution on the device CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1 Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.
最新发布
07-29
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值