I’m not sure this is a bug or not.
I need to deploy the AWS elastic inference for our service. The Elastic Inference requires using CPU to load and run models.
but our code runs well on GPUs, but CPU.
as the simple code below, it can be run on GPUs but on CPU it returns “index out of range in self” Error.

CPUs returns index out of range in self error
import numpy as np
import torch
import torch.nn as nn
sinusoid_table = torch.FloatTensor(torch.Size([50 + 1, 512]))
pos_emb = nn.Embedding.from_pretrained(sinusoid_table, freeze=True)
positions = torch.arange(200).expand(1, 200).contiguous()+1
positions=positions
a= pos_emb(positions)
print(a)
on GPUs this run well
import torch
import torch.nn as nn
device = torch.device(‘cuda:0’)
sinusoid_table = torch.FloatTensor(torch.Size([50 + 1, 512])).to(device)
pos_emb = nn.Embedding.from_pretrained(sinusoid_table, freeze=True).to(device)
positions = torch.arange(200).expand(1, 200).contiguous()+1
positions=positions.to(device)
a= pos_emb(positions)
print(a)

I’m using PytorchECL 1.3.1 (support Elastic Inference) comes with Amazon AMI
Tested with normal pytorch==1.5.0
both of them result the “index out of range error”
Any helps is appreciated. thank you.