In your current code snippet you are assigning train_loader to the input batch, not a “loader” or generator object.
If you want to use your custom generator, create an iterator and call next on it:
data_iter = data_gen(args.batch_size)
next(data_iter)
next(data_iter)
next(data_iter)
next(data_iter)