当前位置:网站首页>RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
2022-04-23 19:13:00 【pflik-sj】
一、问题描述
报错提示:
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out` arguments is currently unsupported. In PyTorch 1.7, when `dtype` and `out` are not set a bool fill value will return a tensor of torch.bool dtype, and an integral fill value will return a tensor of torch.long dtype.
报错全文提示:
File "main.py", line 62, in <module>
run(train_dataset, val_dataset, test_dataset, args.save_dir, args.log_dir, model, args.epochs, args.batch_size, args.lr, args.lr_decay_factor, args.lr_decay_step_size, args.weight_decay, args.energy_and_force, args.p)
File "**项目路径**/SphereNet_3D/spherenet_code/train.py", line 42, in run
train_loss = train(model, optimizer, train_loader, energy_and_force, p, loss_func, device)
File "**项目路径**/SphereNet_3D/spherenet_code/train.py", line 75, in train
for step, batch_data in enumerate(tqdm(train_loader)):
File "**虚拟环境路径**/miniconda3/envs/spherenet/lib/python3.7/site-packages/tqdm/std.py", line 1195, in __iter__
for obj in iterable:
File "**虚拟环境路径**/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 363, in __next__
data = self._next_data()
File "**虚拟环境路径**/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 403, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "**虚拟环境路径**/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch
return self.collate_fn(data)
File "**虚拟环境路径**/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch_geometric/loader/dataloader.py", line 20, in __call__
self.exclude_keys)
File "**虚拟环境路径**/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch_geometric/data/batch.py", line 74, in from_data_list
exclude_keys=exclude_keys,
File "**虚拟环境路径**/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch_geometric/data/collate.py", line 109, in collate
out_store.batch = repeat_interleave(repeats, device=device)
File "**虚拟环境路径**/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch_geometric/data/collate.py", line 208, in repeat_interleave
outs = [torch.full((n, ), i, device=device) for i, n in enumerate(repeats)]
File "**虚拟环境路径**/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch_geometric/data/collate.py", line 208, in <listcomp>
outs = [torch.full((n, ), i, device=device) for i, n in enumerate(repeats)]
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out` arguments is currently unsupported. In PyTorch 1.7, when `dtype` and `out` are not set a bool fill value will return a tensor of torch.bool dtype, and an integral fill value will return a tensor of torch.long dtype.
二、情况分析
-
报错的主要原因是:
pytorch版本有点低
,出现了一些问题。
我使用的pytorch == 1.6.0
,也是属于官方提示的范围内的。一般出现问题去官网看一下,再根据报错的情况具体查一下。 -
此次报错情况(一般是最后一行代码出现的问题):
outs = [torch.full((n, ), i, device=device) for i, n in enumerate(repeats)]
说明是:full()
这个函数有问题。
并且根据提示:RuntimeError: Providing a bool or integral fill value without setting the optional
dtypeor
outarguments is currently unsupported.
基本上就是因为dtype
或者out
这两个参数的问题。 -
我们看一下官网(按着自己的版本):
注意他说的这个警告!当前不支持
fill_value
在未设置可选dtype
或out
参数的情况下提供布尔值或整数填充值。 其实就是需要把参数置成dtype=torch.long
和dtype=torch.bool
,需要给参数一个值,不然没有想要的返回值。
之前还试了一下dtype=torch.float
,可是这个并不能解决问题,而且还有了新的问题。参照官方文档,个人感觉这样是不对的。
三、解决方法
方法一
- 根据报错的最后一项:
File "**虚拟环境路径**/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch_geometric/data/collate.py", line 208, in <listcomp>
outs = [torch.full((n, ), i, device=device) for i, n in enumerate(repeats)]
- 根据提示的路径找到这个文件
collate.py
,找到torch.full()
函数。
注:在linux环境下直接使用/full
这个命令就可以了。 - 最后直接加上这个参数
dtype=torch.long
就可以了。
我的问题出现的情况没有在原文中,在我的代码中没有找到torch.full()
,所以修改了源码
方法二
在之前解决方法之前肯定查了好多的方法,比较靠谱的就是下面这个。
参考:参考博文
只需要提供tensor返回的数据类型(dtype=torch.long
)就可以了,而不用再在后面加.torch.long()
这种方式了。具体加的位置是在torch.full()
函数的参数项中即可。
#self.register_buffer('words_to_words ', torch.full((len(vocab),),fill_value=unknown_idx) .long())
#但是因为好像版本问题报错,所以就修改成了下面这样子
self.register_buffer('words_to words ',torch.full(len(vocab),),fill_value=unknown_idx,dtype=torch.long))
版权声明
本文为[pflik-sj]所创,转载请带上原文链接,感谢
https://sunflower.blog.csdn.net/article/details/124360181
边栏推荐
- Zlib realizes streaming decompression
- Openlayers 5.0 reload the map when the map container size changes
- 12个例子夯实promise基础
- Sogou cell thesaurus analysis (only extract words and word frequency)
- 2021-2022-2 ACM集训队每周程序设计竞赛(8)题解
- Yyds dry goods inventory stringprep --- Internet string preparation
- Quick start to static class variables
- SQL of contention for system time plus time in ocrale database
- Openlayers 5.0 discrete aggregation points
- 12 examples to consolidate promise Foundation
猜你喜欢
ArcMap publishing slicing service
12个例子夯实promise基础
The difference between ordinary inner class and static inner class
Some records used by VS2010
[record] typeerror: this getOptions is not a function
[报告] Microsoft :Application of deep learning methods in speech enhancement
JVM的类加载过程
MySQL Téléchargement et installation de la version Linux
Redis optimization series (III) solve common problems after master-slave configuration
[记录]TypeError: this.getOptions is not a function
随机推荐
SSDB foundation 2
開關電源設計分享及電源設計技巧圖解
2022.04.23 (the best time for lc_714_to buy and sell stocks, including handling charges)
Openlayers 5.0 reload the map when the map container size changes
微搭低代码零基础入门课(第三课)
All table queries and comment description queries of SQL Server
RPM package management
Some records used by VS2010
std::stoi stol stoul stoll stof stod
Solve the problem of invalid listview Click
[record] typeerror: this getOptions is not a function
From technical system to business insight, the closing chapter of the practice of small and medium-sized R & D team structure
openlayers 5.0 当地图容器大小改变时,重新加载地图
Parsing headless jsonarray arrays
MySQL statement
js 计算时间差
【玩转Lighthouse】腾讯云轻量服务器搭建全平台视频解析视频下载网站
Openlayers draw rectangle
UML类图几种关系的总结
机器学习目录