You could probably create an internal attribute in your Dataset's __init__ and manipulate this attribute inside the training loop via: loader.dataset.my_flag = my_value.
This .my_flag could be checked in __getitem__.
However, if I’m not mistaken, this will only work using a single process.
For multiple workers in your DataLoader, a shared array could probably work as the flag as given in this small example 24.