Thanks for the code.
Your code works fine on my machine. Here is the formatted code in case you want to rerun it:
import torch
import torchvision
import torchvision.transforms as transforms
import torch.utils.data as data
import torchvision.datasets as datasets
import torch.nn as nn


transform = transforms.Compose([
    transforms.ToTensor(),
    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])


train_data = datasets.CIFAR10(
    root = "./data",
    train = True,
    download = True,
    transform = transform)

train_data, val_data = torch.utils.data.random_split(
    train_data, [int(len(train_data) * 0.8), int(len(train_data)*0.2)])

test_data = datasets.CIFAR10(
    root = "./data",
    train = False,
    download = True,
    transform = transform)


classes = test_data.classes
dic_classes = {}
for i in range(len(classes)):
    dic_classes[i] = classes[i]

print(dic_classes)

trainloader = torch.utils.data.DataLoader(
    train_data, batch_size=16, shuffle=True)
valloader = torch.utils.data.DataLoader(
    val_data, batch_size=16, shuffle=True)
testloader = torch.utils.data.DataLoader(
    test_data, batch_size=16, shuffle=False)


import matplotlib.pyplot as plt
import numpy as np

def imshow(img, labels, dic):
    num = len(labels)
    rows = int(np.sqrt(num))
    cols = int(np.sqrt(num))
    
    fig = plt.figure(figsize=(20,20))
    for i in range(rows*cols):
        ax = fig.add_subplot(rows, cols, i+1)
        tmp = img[i]
        tmp = tmp / 2 + 0.5     # unnormalize
        npimg = tmp.numpy()
        ax.imshow(np.transpose(npimg, (1, 2, 0)), cmap = "bone")
        ax.title.set_text(dic[labels[i].item()])
        #plt.show()
        ax.axis('off')

dataiter = iter(trainloader)
images, labels = dataiter.next()
imshow(images, labels, dic_classes)

I don’t get any errors and the sample images are displayed.
PS: you can post code snippets by warpping them into three backticks ```, which makes debugging easier.