Huggingface transformer sequence classification
I am fine tuning a transformer and I would like to use GPUsThispage shows how we to do the sametrainer = Trainer(
    model=model,
    args=training_args,
    compute_metrics=compute_metrics,
    train_dataset=train_df_tuning_dataset_tokenized,
    eval_dataset=val_dataset_tokenized
)Do I need to modify above part like below? I am adding.to(device)to ensure data is on GPUdevice = 'cuda' if torch.cuda.is_available() else 'cpu'
#device = 'cpu'
device

trainer = Trainer(
    model=model,
    args=training_args,
    compute_metrics=compute_metrics,
    train_dataset=train_df_tuning_dataset_tokenized.to(device),
    eval_dataset=val_dataset_tokenized.to(device)
)
2022-03-26T03:19:09Z
I am not 100% sure, but I think you need to send the dataset and the model to device before you call the Trainer.Something like this might work,import torch
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')

model.to(device)
train_df_tuning_dataset_tokenized.to(device)
val_dataset_tokenized.to(device)


trainer = Trainer(
    model=model,
    args=training_args,
    compute_metrics=compute_metrics,
    train_dataset=train_df_tuning_dataset_tokenized,
    eval_dataset=val_dataset_tokenized
)
2022-03-26T03:32:14Z
lets hope we get a confirmation. Thanks for pointing out that model needs to be on gpu too
2022-03-26T12:08:42Z
Hi,You shouldn’t actually have any device placements, the Trainer handles this for you. The Trainer has an attribute calledplace_model_on_devicewhich is set toTrueby default.The Trainer will also handle device placement of your data.