简体   繁体   中英

Can I input a Byte Tensor to my RNN/LSTM model?

I am developing an RNN/LSTM model to which I want to encode the sequence in a ByteTensor to save memory as I am limited to a very tight memory. However, when I do so, the model returns the following error:

Expected object of scalar type Byte but got scalar type Float for argument #2 'mat2'

So, there seems to be something else that is need to be Byte tensor as well, but I do not know what is it since the console only shows an error at the line:

output = model(predictor)

It means that inside the model there are float tensors which are being used to operate on your byte tensor (most likely operands in matrix multiplications, additions, etc). I believe you can technically cast them to byte by executing model.type(torch.uint8) , but your approach will sooner or later fail anyway - since integers are discrete there is no way to used them in gradient calculations necessary for backpropagation. uint8 values can be used in deep learning to improve performance and memory footprint of inference in a network which is already trained, but this is an advanced technique. For this task your best bet are the regular float32 s. If your GPU supports it, you could also use float16 aka half , though it introduces additional complexity and I wouldn't suggest it for beginners.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM