[英]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. 我正在开发一个RNN / LSTM模型,我想在ByteTensor中对序列进行编码以节省内存,因为我限于非常紧凑的内存。 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'
标量类型为Byte的预期对象,但参数#2'mat2'的标量类型为Float
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). 这意味着在
model
内部有用于对字节张量进行运算的浮点张量(矩阵乘法,加法等中最有可能的操作数)。 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. 我相信您可以通过执行
model.type(torch.uint8)
技术上将其转换为字节,但是您的方法迟早会失败-由于整数是离散的,因此无法在反向传播所需的梯度计算中使用它们。 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. uint8
值可用于深度学习中,以改善已经经过训练的网络中推理的性能和内存占用,但这是一项高级技术。 For this task your best bet are the regular float32
s. 对于此任务,最好的选择是常规
float32
。 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. 如果您的GPU支持它,那么您也可以使用
float16
aka half
,尽管它引入了额外的复杂性,我不建议初学者使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.