Could you post a code snippet to reproduce this issue, please?
This dummy example runs fine:
model = models.resnet18()
optimizer=torch.optim.AdamW(model.parameters(),lr=0.005,weight_decay=0.01)
scheduler=torch.optim.lr_scheduler.OneCycleLR(optimizer,max_lr=0.0005,total_steps=10,epochs=30)

output = model(torch.randn(1, 3, 224, 224))
loss = F.cross_entropy(output, torch.randint(0, 1000, (1,)))
loss.backward()
optimizer.step()
scheduler.step()