You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a question about the below minimal working example from the DeepSpeed README.
for step, batch in enumerate(data_loader):
#forward() method
loss = model_engine(batch)
#runs backpropagation
model_engine.backward(loss)
#weight update
model_engine.step()
Suppose that deepspeed.initialize() was solely called to wrap around my model, and my client script already creates a data_loader. What batch size should be used when instantiating my data_loader for the above loop to work fine?
If there was no DeepSpeed, I'd initialize my data_loader as follows in the client script:
where args.train_batch_size above corresponds to DeepSpeed's train_micro_batch_size_per_gpu , i.e., the batch size for each GPU for each step, independent of gradient accumulation steps.
Should I continue to use the micro batch size when instantiating my data_loader in the client script? The documentation is not clear on this.
This is a great question, and is certainly an easy source of confusion unfortunately.
When the client handles data loading issues, the uses of train_micro_batch_size_per_gpu in DeepSpeed are restricted to:
Detecting gradient accumulation boundaries in order to initiate gradient reduction and optimizer.step()
Computing various latency and throughput statistics.
Thus a mismatch in args.train_batch_size (in your example) and train_micro_batch_size_per_gpu could result in serious training bugs because of usage 1, and less serious system perf errors because of usage 2. So yes, please ensure that args.train_batch_size = train_micro_batch_size_per_gpu.
We are exploring ideas to easily detect these kinds of serious mismatches in args and json config settings, and we appreciate your input. Thanks!
Reacted by Wonyoung Jang, Xiang Chendong and He JiangYang
To be clear, if my client script has a train_batch_size of 2, and I am running my code on a single node with 8 GPUs, then I need to ensure that my DeepSpeed config has:
gradient_accumulation_steps = X
train_batch_size = 2*8*X
Is this correct?
Also, if I wanted to go to multiple nodes, all having 8 GPUs each, what would I update these parameters to?
Based on the code snippet you shared earlier, args.train_batch_size is not the effective batch size of training, but rather is the batch size that fills one GPU memory on each call to the data_loader. Thus, args.train_batch_size is the equivalent of train_micro_batch_size_per_gpu. For example in 1-GPU training, your client script will probably be calling the data_loader gradient_accumulation_steps times to accumulate data samples to aggregate an effective batch size (the equivalent of train_batch_size in the json config) before making an optimizer step to update the model parameters.
Can you clarify that I am aligned with your scenario/thinking?
@tjruwase yes that is correct -- in that snippet, args is client args. So args.train_batch_size will be defined by me directly in my client script. The "train_batch_size" in the DeepSpeed config file is not the same as this one.
params_file_path will point to a JSON file in which I have "train_batch_size": 2, so my client script will have a DataLoader that is instantiated with this batch size before the batches get enumerated.
deepspeed_config will point to a JSON file in which I have "train_batch_size": 2*8*X (where the 8 refers to the number of GPUs in my single-node) and "gradient_accumulation_steps": X. Does this seem fine?
Great, thanks! Actually that link does not say anything about the effective batch size, this one does, although it doesn't elaborate on the difference between the single and multi-node cases from the perspective of the effective batch size.
Also, it talks about using train_step_batch_size to compute train_batch_size, but from its description, it sounds exactly the same as train_micro_batch_size_per_gpu . Are these two the same and just haven't been merged together?
Also, my script does validation set metric computation currently after every epoch of training in a distributed fashion and prints the all-reduced metric. It seems like I should not be using the model_engine wrapper for this metric computation, since the forward() implementation in DeepSpeedLight is specific to training. So while I use model_engine variable for training, I should avoid it during validation and just use the client model variable, is that correct?
Also, it talks about using train_step_batch_size to compute train_batch_size, but from its description, it sounds exactly the same as train_micro_batch_size_per_gpu . Are these two the same and just haven't been merged together?
Yes, train_step_batch_size was renamed to train_micro_batch_size_per_gpu . Please pardon our typo.
For now, it is okay to use your client model to do validation since it is not a throughput bottleneck. Ideally, we believe DeepSpeed should support that as well. Perhaps, you can helps us verify that support at a more convenient time for you.
@tjruwase but how would model_engine support validation as of now? The DeepSpeedLight forward() method does a check for gradient accumulation steps, which is training-specific and not to be done during validation. So we cannot reuse the model_engine for validation, right?
I have not thought through all the requirements, but you could set gradient accumulation steps to 1 in this case. In other words, we could have a separate json config field for validation.
Yes, that would be an overkill indeed. I just wanted to point out that it could be supported. For now, DeepSpeed will focus on the throughput-sensitive training pipeline, and clients can stick to their preferred validation method.
Activity
g-karthik commentedon Mar 19, 2020
@jeffra @ShadenSmith
tjruwase commentedon Mar 19, 2020
This is a great question, and is certainly an easy source of confusion unfortunately.
When the client handles data loading issues, the uses of
train_micro_batch_size_per_gpuin DeepSpeed are restricted to:Thus a mismatch in
args.train_batch_size(in your example) andtrain_micro_batch_size_per_gpucould result in serious training bugs because of usage 1, and less serious system perf errors because of usage 2. So yes, please ensure thatargs.train_batch_size=train_micro_batch_size_per_gpu.We are exploring ideas to easily detect these kinds of serious mismatches in args and json config settings, and we appreciate your input. Thanks!
tjruwase commentedon Mar 19, 2020
By the way, we have an open issue on this, in case you are interested in tracking.
g-karthik commentedon Mar 19, 2020
@tjruwase Thanks for the info!
To be clear, if my client script has a
train_batch_sizeof 2, and I am running my code on a single node with 8 GPUs, then I need to ensure that my DeepSpeed config has:Is this correct?
Also, if I wanted to go to multiple nodes, all having 8 GPUs each, what would I update these parameters to?
tjruwase commentedon Mar 20, 2020
Based on the code snippet you shared earlier,
args.train_batch_sizeis not the effective batch size of training, but rather is the batch size that fills one GPU memory on each call to the data_loader. Thus,args.train_batch_sizeis the equivalent oftrain_micro_batch_size_per_gpu. For example in 1-GPU training, your client script will probably be calling the data_loadergradient_accumulation_stepstimes to accumulate data samples to aggregate an effective batch size (the equivalent oftrain_batch_sizein the json config) before making an optimizer step to update the model parameters.Can you clarify that I am aligned with your scenario/thinking?
g-karthik commentedon Mar 20, 2020
@tjruwase yes that is correct -- in that snippet,
argsis client args. Soargs.train_batch_sizewill be defined by me directly in my client script. The "train_batch_size" in the DeepSpeed config file is not the same as this one.g-karthik commentedon Mar 20, 2020
So my thinking is that the client args has the following:
params_file_pathwill point to a JSON file in which I have"train_batch_size": 2, so my client script will have aDataLoaderthat is instantiated with this batch size before the batches get enumerated.deepspeed_configwill point to a JSON file in which I have"train_batch_size": 2*8*X(where the 8 refers to the number of GPUs in my single-node) and"gradient_accumulation_steps": X. Does this seem fine?tjruwase commentedon Mar 20, 2020
Yes, this seems fine. Please let us know how it goes.
g-karthik commentedon Mar 20, 2020
Cool, thanks for the confirmation! How would this configuration change when I want to use multiple nodes? Let's say I have
Nnodes, each with 8 GPUs.tjruwase commentedon Mar 20, 2020
You will set
train_batch_sizein JSON file to2*N*8*X. Please see our multi-node training documentation.g-karthik commentedon Mar 20, 2020
Great, thanks! Actually that link does not say anything about the effective batch size, this one does, although it doesn't elaborate on the difference between the single and multi-node cases from the perspective of the effective batch size.
Also, it talks about using
train_step_batch_sizeto computetrain_batch_size, but from its description, it sounds exactly the same astrain_micro_batch_size_per_gpu. Are these two the same and just haven't been merged together?Also, my script does validation set metric computation currently after every epoch of training in a distributed fashion and prints the all-reduced metric. It seems like I should not be using the
model_enginewrapper for this metric computation, since theforward()implementation inDeepSpeedLightis specific to training. So while I usemodel_enginevariable for training, I should avoid it during validation and just use the clientmodelvariable, is that correct?tjruwase commentedon Mar 20, 2020
Yes,
train_step_batch_sizewas renamed totrain_micro_batch_size_per_gpu. Please pardon our typo.For now, it is okay to use your client model to do validation since it is not a throughput bottleneck. Ideally, we believe DeepSpeed should support that as well. Perhaps, you can helps us verify that support at a more convenient time for you.
g-karthik commentedon Mar 20, 2020
@tjruwase but how would
model_enginesupport validation as of now? TheDeepSpeedLightforward() method does a check for gradient accumulation steps, which is training-specific and not to be done during validation. So we cannot reuse themodel_enginefor validation, right?tjruwase commentedon Mar 20, 2020
I have not thought through all the requirements, but you could set gradient accumulation steps to 1 in this case. In other words, we could have a separate json config field for validation.
g-karthik commentedon Mar 20, 2020
Having a separate JSON config for validation would imply instantiating a separate
model_enginefor validation. Seems a bit much.Or maybe not -- but it will require significant changes to
DeepSpeedLightand the parser.tjruwase commentedon Mar 20, 2020
Yes, that would be an overkill indeed. I just wanted to point out that it could be supported. For now, DeepSpeed will focus on the throughput-sensitive training pipeline, and clients can stick to their preferred validation method.
ShadenSmith commentedon Mar 22, 2020
Closing this issue - feel free to continue discussion as needed (and/or re-open).
fix for smaller SGS sizes, ensures each grad is backed by unique tens…
ZeRO 3 Offload (#834)