本文主要是介绍Providing a bool or integral fill value without setting the optional `dtype` or `out`...,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用fastnlp的时候,由于使用的pytorch==1.6.0,而fastnlp版本较低,出现以下问题:
Traceback (most recent call last):File "train_zen_cn.py", line 175, in <module>data_bundle, embed, bi_embed, tencent_words_embed, train_feature_data, dev_feature_data, test_feature_data, feature2id, id2feature = load_data()File "/home/.../fastNLP/core/utils.py", line 155, in wrapperresults = func(*args, **kwargs)File "train_zen_cn.py", line 145, in load_dataembed = StaticEmbedding(data_bundle.get_vocab('chars'),File "/home/.../fastNLP/embeddings/static_embedding.py", line 154, in __init__embedding = self._load_with_vocab(model_path, vocab=vocab, init_method=init_method)File "/home/.../fastNLP/embeddings/static_embedding.py", line 266, in _load_with_vocabself.register_buffer('words_to_words', torch.full((len(vocab), ), fill_value=unknown_idx), dtype=torch.long())
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.
需要做出以下修改
# 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))
这篇关于Providing a bool or integral fill value without setting the optional `dtype` or `out`...的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!