Hi @ptrblck. Thank you very much for the reply. I did try out the changes you recommended and obtained the following results:

Execution Times when number of workers = 1:

Dataloader_time:  [0.08958374404907224]
Avg_Dataloader_time:  [0.0001910101152432244]
TrainD_time:  [23.295507202148457]
TrainC_time:  [29.29996321105957]
Avg_TrainD_time:  [0.04967059104935705]
Avg_TrainC_time:  [0.062473269106736826]
Validation_time:  [12.500955078125]
update_weights_time:  [0.0004887039959430695]
Avg_update_weights_time:  [1.0420127845268006e-06]
before_train_time:  [0.0003477120101451874]
after_train_before_validation:  [0.0010117119550704956]
after_validation_before_test:  [0.0006152639985084533]
iterations_time:  [93.8879296875]
iterations_print_time:  [3.0880000442266465e-05]
Test_time:  []
epoch_time:  [106.3928203125]


Execution Times when number of workers = 0:

Dataloader_time:  [0.041077375993132596]
Avg_Dataloader_time:  [8.758502343951514e-05]
TrainD_time:  [16.117475570678714]
TrainC_time:  [20.818791797637946]
Avg_TrainD_time:  [0.03436561955368596]
Avg_TrainC_time:  [0.04438974796937728]
Validation_time:  [12.2724638671875]
update_weights_time:  [0.00019359999895095825]
Avg_update_weights_time:  [4.127931747355187e-07]
before_train_time:  [0.0003356800079345703]
after_train_before_validation:  [0.0005851200222969055]
after_validation_before_test:  [0.0014738880395889283]
iterations_time:  [45.32078125]
iterations_print_time:  [1.2032000347971917e-05]
Test_time:  []
epoch_time:  [57.59690625]

a. There is a remarkable improvement as compared to the earlier settings. However, there is still some visible difference between iterations_time and Dataloader_time + TrainD_time + TrainC_time. Can you help identify what I might be missing here?
b. I am not sure what you mean by profiling the WeightedRandomSampler Calls. As evident from the code, the function execution times should be included in the Dataloader_time, no?
c. I also had one other query. The only reason I am using torch.utils.data.DataLoader is to fetch one mini-batch size of sample data at every iteration. Is there any other (more) efficient way to do the same?