train_batch_size + dataset + actual batch size
Hello,
I have 4 questions for clarification:
- Why we should pass the training_data to the deepspeed.initialize to generate a new trainloader rather than using a normal torch trainloader ?
- Can we use a custom pytorch trainloader in case we have custom dataset that returns for example inputs, outputs and mask ?
- If the actual batch size that is used to be passed to the model is different than the train_batch_size in the json file, what will happen ?
- Can we just define gradient_accumulation_steps and train_micro_batch_size_per_gpu only and leave deepspeed to calculate train_batch_size automatically ?
-
Passing training_data to deepspeed.initialize is optional, and not required. Some models can benefit from deepspeed's i/o optimizations. However, using torch trainloader is fine.
-
In our experience, deepspeed works well with custom trainloaders and datasets. So I suspect the answer to that is yes, but please share any issues you run into.
-
The train_batch_size in json file is used to perform gradient accumulation and compute progress statistics, so a mismatch could result in incorrect training and confusing statistics.
-
Yes, this is supported.
@tjruwase could you clarify - how does the parallelization work with a custom dataloader? Do you need to make sure the dataloader uses the local rank as input to load a separate portion of the dataset manually?
This is correct, it is the responsibility of the custom loader to load the appropriate dataset portion based on local rank (or whatever else the client finds appropriate) into GPU memory. DeepSpeed does not impose any restrictions on the custom dataloader, and does not perform any sanity checks.
Hope that clears things up.
@tjruwase Thanks for the clarification. Just one more question.
Assuming I have a custom data generator like that:
for batch_idx, batch in enumerate(DatasetGenerator):
data, target,src_padding = batch['input'].to(model_engine.local_rank), batch['target'].to(model_engine.local_rank), batch['padding_mask'].to(model_engine.local_rank)
Does this mean:
- The batch size should be equal to train_micro_batch_size_per_gpu ?
- It should provide different/random batch for each gpu/node ?
-
Yes, batch_size should be equal to train_micro_batch_size_per_gpu, which is batch size for a single step on one gpu.
-
Assuming DatasetGenerator is returning the correct batch for each gpu, then this would be correct since the .to() is simply moving the data bits into gpu memory.
@tjruwase Thanks a lot that answers all my questions for now :)
@tjruwase assuming I'm using some customer data loader as @agemagician above but in a multi-node, multi-gpu settings, how would I go about and send tensors to the right GPU? Do I still do tensor.to(engine.local_rank) or global_rank please? Thanks.
@tnq177, I believe you want local_rank as crossing node boundaries requires communication collectives, like broadcast.