rasbt / machine-learning-book

Code Repository for Machine Learning with PyTorch and Scikit-Learn
https://sebastianraschka.com/books/#machine-learning-with-pytorch-and-scikit-learn
MIT License
3.63k stars 1.31k forks source link

RuntimeError: "nll_loss_forward_reduce_cuda_kernel_2d_index" not implemented for 'Int' #192

Closed leizhanggit closed 2 months ago

leizhanggit commented 2 months ago

Hello,

I am trying to run the code in Chapter 16, Page 580

I encountered an error:

start_time = time.time()

for epoch in range(NUM_EPOCHS):

    model.train()

    for batch_idx, batch in enumerate(train_loader):

        ### Prepare data
        input_ids = batch['input_ids'].to(DEVICE)
        attention_mask = batch['attention_mask'].to(DEVICE)
        labels = batch['labels'].to(DEVICE)

        ### Forward
        outputs = model(input_ids, attention_mask=attention_mask, labels=labels). >>>>>>>>>>>>
        loss, logits = outputs['loss'], outputs['logits']

RuntimeError: "nll_loss_forward_reduce_cuda_kernel_2d_index" not implemented for 'Int' File , line 15 12 labels = batch['labels'].to(DEVICE) 14 ### Forward ---> 15 outputs = model(input_ids, attention_mask=attention_mask, labels=labels)

The code is exactly the same, except I read the csv file from spark and then converted it to pandas dataframe.

I would like to know, What are the correct column data types for 'review' and 'sentiment' columns? my column type for 'sentiment' column is integer. I am not sure if it is correct?

Or the error was caused by somewhere else?

rasbt commented 2 months ago

Hi there,

The expected column type is int64 (also called "Long"). What I suspect is that your data type may be in 32-bit precision.

leizhanggit commented 2 months ago

Thanks, your sense is right. it is int64. The code works now.