import time
import numpy
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.autograd import Variable
from torch.nn.parameter import Parameter


class Toy(nn.Module):
    def __init__(self):
        super(Toy, self).__init__()
        self.embed = nn.Embedding(100000, 256, sparse=False)

    def forward(self, idx):
        return F.sigmoid(self.embed(idx))


toy = Toy().cuda()
optimizer = optim.SGD(toy.parameters(), lr=0.001)
criterion = nn.CrossEntropyLoss().cuda()


x = Variable(
    torch.from_numpy(numpy.random.randint(0, 100000, 256)).cuda(),
    requires_grad=False
)

t = Variable(
    torch.LongTensor(numpy.random.randint(0, 2, 256)).cuda(),
    requires_grad=False
) 


start_time = time.time()
for _ in xrange(2000):
    y = toy(x)
    cost = criterion(y, t)
    cost.backward()
    optimizer.step()
print time.time() - start_time

I tried this piece of code, the elapsed time is 18.3s (sparse=True) vs 3.84s (sparse=False) in a Tesla P100. I have Ubuntu 16 and CUDA8. Could someone please elaborate the some possible reasons?
Thank you in advance!