How to fix the error "TypeError: forward()... - CUDA
For my bachelor thesis I need to train a network with some music similarity data using GPU and CUDA. 

Tried to fix the problem several times with different approaches, but none of them worked.

use_cuda = torch.cuda.is_available()

BSG_model = bayesian_skipgram(V, EMBEDDING_DIM)

if use_cuda:
    BSG_model.cuda()
optimizer = torch.optim.Adam(BSG_model.parameters(), lr=0.005)
BSG_model.train()
loss_progress = []
iter_time = time.time()

dataloader = DataLoader(data, batch_size=16, shuffle=True)

print("N_batches", len(dataloader))

for epoch in range(1):
    for i, batch in enumerate(dataloader):
        batch_start = time.time()
        main_word = batch[:,0]
        context_word = batch[:,1:]

    #print("Main word:,", main_word.shape, context_word.shape)


    optimizer.zero_grad()

    if use_cuda:
        loss = BSG_model.forward(main_word.cuda(), context_word.cuda(), use_cuda=True)
    else:
        loss = BSG_model.forward(main_word, context_word)

    loss.backward()
    optimizer.step()
    batch_end = time.time() - batch_start
    if i % 10 == 0:
        print("epoch, batch ", epoch, i)
        loss_progress.append(loss.item())  
        print(time.time()-iter_time)
        print(loss)
        iter_time = time.time()


"The expected result should be that the model starts to train the embeddings..."
"The output is the following:"

TypeError                                 Traceback (most recent call last)
&lt;ipython-input-36-c69aba816e22&gt; in &lt;module&gt;()
     34 
     35         if use_cuda:
---&gt; 36             loss = BSG_model.forward(main_word.cuda(), context_word.cuda(), use_cuda=True)
     37         else:
     38             loss = BSG_model.forward(main_word, context_word)

 TypeError: forward() got an unexpected keyword argument 'use_cuda'


The error message is quite self explanatory:  


  TypeError: forward() got an unexpected keyword argument 'use_cuda'


You call forward function like this

oss = BSG_model.forward(main_word.cuda(), context_word.cuda(), use_cuda=True)


with two positional arguments: (main_word.cuda(), context_word.cuda() and one keyword arguement: use_cuda=True.  

Keyword arguments means that when the function is declared/defined it has an argument with the same name. For instance:

def forward(self, word, context, use_cuda):
  ...


Is a declaration of forward function with use_cuda argument.  

However, it seems like you are calling forward with use_cuda keyword argument, but the function forward you are using does not have a use_cuda argument at all!

Please look carefully at the way your BSG_model.forward function is defined.
