mrdbourke / pytorch-deep-learning

Materials for the Learn PyTorch for Deep Learning: Zero to Mastery course.
https://learnpytorch.io
MIT License
9.34k stars 2.78k forks source link

Help? Pls #901

Open LazySloth26 opened 2 months ago

LazySloth26 commented 2 months ago

enumerate(dataloader) is in cpu but idk how to fix that, i tried to comment it for it to run but now is failing during the for loop. it says TypeError: 'NoneType' object is not iterable

im running it on pycharm and i lack experience in this.

progress_bar = tqdm(
        # enumerate(dataloader),
        desc=f"Training Epoch {epoch}",
        total=len(dataloader),
        disable=disable_progress_bar
    )

    print(progress_bar[1], '1')

    for batch, (X, y) in progress_bar:
        # Send data to target device
        X, y = X.to(device), y.to(device)

        # 1. Forward pass
        y_pred = model(X)
IlanVinograd commented 2 months ago

Hi man ✋ , try uncomment the enumerate(dataloader) like here and If your model and data are on the GPU, you should move your model and data to the GPU before iterating through the dataloader. You can do this by sending both the model and the data to the device using .to(device).

progress_bar = tqdm(
    enumerate(dataloader),
    desc=f"Training Epoch {epoch}",
    total=len(dataloader),
    disable=disable_progress_bar
)

for batch_idx, (X, y) in progress_bar:
    # Send data to target device
    X, y = X.to(device), y.to(device)

    # 1. Forward pass
    y_pred = model(X)

Make sure device is properly defined and refers to the GPU (e.g., device = torch.device("cuda:0").

please let me know if it helps you 😄