当前位置:网站首页>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:15:00 pflik-sj

One 、 Problem description

Wrong presentation :

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.

Error full text prompt :

 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 "** Project path **/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 "** Project path **/SphereNet_3D/spherenet_code/train.py", line 75, in train
    for step, batch_data in enumerate(tqdm(train_loader)):
  File "** Virtual environment path **/miniconda3/envs/spherenet/lib/python3.7/site-packages/tqdm/std.py", line 1195, in __iter__
    for obj in iterable:
  File "** Virtual environment path **/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 363, in __next__
    data = self._next_data()
  File "** Virtual environment path **/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 "** Virtual environment path **/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch
    return self.collate_fn(data)
  File "** Virtual environment path **/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch_geometric/loader/dataloader.py", line 20, in __call__
    self.exclude_keys)
  File "** Virtual environment path **/miniconda3/envs/spherenet/lib/python3.7/site-packages/torch_geometric/data/batch.py", line 74, in from_data_list
    exclude_keys=exclude_keys,
  File "** Virtual environment path **/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 "** Virtual environment path **/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 "** Virtual environment path **/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.

Two 、 Situation analysis

  1. The main reason for reporting errors is :pytorch The version is a little low , There are some problems .
    I use pytorch == 1.6.0, It is also within the scope of official tips . Generally, if there is a problem, go to the official website to have a look , Then check the details according to the error report .

  2. Error reporting this time ( It's usually the problem with the last line of code ):

    outs = [torch.full((n, ), i, device=device) for i, n in enumerate(repeats)]

    That is the :full() There's something wrong with this function .
    And according to the prompt :RuntimeError: Providing a bool or integral fill value without setting the optional dtypeorout arguments is currently unsupported.
    Basically because dtype perhaps out The problem with these two parameters .

  3. Let's see Official website ( According to their own version ):

    Pay attention to the warning he said ! Currently does not support fill_value Optional... Is not set dtype or out In the case of parameter, provide Boolean or integer filling value . In fact, you need to set the parameter to dtype=torch.long and dtype=torch.bool, You need to give a value to the parameter , Otherwise, there is no desired return value .
    I tried it before dtype=torch.float, But this doesn't solve the problem , And there are new problems . Refer to official documents , Personally, I feel this is wrong .

3、 ... and 、 resolvent

Method 1

  1. According to the last item of error report :
  File "** Virtual environment path **/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)]
  1. Find the file according to the prompted path collate.py, find torch.full() function .
    notes : stay linux Use directly in the environment /full This order will do .
  2. Finally, add this parameter directly dtype=torch.long That's all right. . Insert picture description here
    The situation of my question is not in the original text , Not found in my code torch.full(), So I modified the source code

Method 2

I must have checked a lot of methods before solving them , The more reliable one is the following .
Reference resources : Refer to the post
Just provide tensor Data type returned (dtype=torch.long) That's all right. , Instead of adding .torch.long() This way . The specific location of the addition is torch.full() In the parameter item of the function .

#self.register_buffer('words_to_words ', torch.full((len(vocab),),fill_value=unknown_idx) .long())
# But because it seems that there is a version problem, an error is reported , So it's changed to the following 
self.register_buffer('words_to words ',torch.full(len(vocab),),fill_value=unknown_idx,dtype=torch.long))

版权声明
本文为[pflik-sj]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231913354198.html