Repository: pytorch
Issue: TypeError: mask must have dtype bool
Labels: triaged,module: masked operators


I use MaskedTensor(). I give it the mask:
```
MaskedTensor(features[18][:, :, None], (features[18][:, :, None] != 0).bool())
```
`(features[18][:, :, None] != 0).bool().type()` gives me `torch.cuda.BoolTensor`. But I running into the error:
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[40], line 3
      1 for epoch in range(num_epochs):
      2     print(f'Starting epoch {epoch+1}')
----> 3     train_epoch(model, optimizer, dataset_train, batch_size=train_batch_size, 
      4                 shuffle=True, print_loss_every_n_batches=500, device=device)
      6     val_roc_auc = eval_model(model, dataset_val, batch_size=val_batch_szie, device=device)
      7     es(val_roc_auc, model)

File [~/NN_scoring_transactions/src/rnn_baseline/normalize_baseline/./../pytorch_training.py:34](https://vscode-remote+ssh-002dremote-002b10-002e45-002e8-002e20.vscode-resource.vscode-cdn.net/home/rosbank.rus.socgen/rba074146/NN_scoring_transactions/src/rnn_baseline/normalize_baseline/~/NN_scoring_transactions/src/rnn_baseline/pytorch_training.py:34), in train_epoch(model, optimizer, dataset_train, batch_size, shuffle, print_loss_every_n_batches, device)
     30 model.train()
     32 for batch in tqdm(train_generator, desc='Training'):
---> 34     output = torch.flatten(model(batch['transactions_features'], batch['product']))
     36     batch_loss = loss_function(output, batch['label'].float())
     38     batch_loss.backward()

File [~/NN_scoring_transactions/venv/lib/python3.10/site-packages/torch/nn/modules/module.py:1190](https://vscode-remote+ssh-002dremote-002b10-002e45-002e8-002e20.vscode-resource.vscode-cdn.net/home/rosbank.rus.socgen/rba074146/NN_scoring_transactions/src/rnn_baseline/normalize_baseline/~/NN_scoring_transactions/venv/lib/python3.10/site-packages/torch/nn/modules/module.py:1190), in Module._call_impl(self, *input, **kwargs)
   1186 # If we don't have any hooks, we want to skip the rest of the logic in
   1187 # this function, and just call forward.
   1188 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1189         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1190     return forward_call(*input, **kwargs)
   1191 # Do not call functions when jit is used
   1192 full_backward_hooks, non_full_backward_hooks = [], []
...
    208     or data.dtype == torch.int64
    209 ):
    210     raise TypeError(f"{data.dtype} is not supported in MaskedTensor.")

TypeError: mask must have dtype bool.

```



### Versions

Collecting environment information...
PyTorch version: 1.13.0+cu116
Is debug build: False
CUDA used to build PyTorch: 11.6
ROCM used to build PyTorch: N/A

OS: CentOS Linux release 7.9.2009 (Core) (x86_64)
GCC version: (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Clang version: Could not collect
CMake version: version 3.27.2
Libc version: glibc-2.17

Python version: 3.10.8 (main, Oct 28 2022, 08:43:57) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] (64-bit runtime)
Python platform: Linux-3.10.0-1160.76.1.el7.x86_64-x86_64-with-glibc2.17
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: Tesla V100-PCIE-32GB
Nvidia driver version: 460.106.00
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                40
On-line CPU(s) list:   0-39
Thread(s) per core:    2
Core(s) per socket:    10
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 85
Model name:            Intel(R) Xeon(R) Silver 4114 CPU @ 2.20GHz
Stepping:              4
CPU MHz:               919.128
CPU max MHz:           3000.0000
CPU min MHz:           800.0000
BogoMIPS:              4400.00
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              1024K
L3 cache:              14080K
NUMA node0 CPU(s):     0-9,20-29
NUMA node1 CPU(s):     10-19,30-39
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 invpcid_single intel_ppin intel_pt ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_pkg_req pku ospke md_clear spec_ctrl intel_stibp flush_l1d

Versions of relevant libraries:
[pip3] numpy==1.23.1
[pip3] torch==1.13.0+cu116
[pip3] torchaudio==0.13.0+cu116
[pip3] torchvision==0.14.0+cu116
[pip3] triton==2.0.0
[conda] Could not collect