Problem description
When storing the state dict of a transformer_engine model on a device with index A and afterwards load it on another device with index B, some memory still gets allocated on device A. The reason for this seems the be the pickle.loads in https://github.com/NVIDIA/TransformerEngine/blob/main/transformer_engine/pytorch/module/base.py#L411
This issue has a large practical impact in distributed training: if device 0 on a host writes the model checkpoint and when resuming the training all other devices read it, all 8 devices on the host suddenly allocate on device 0. In our case we are not able to resume trainings due to OOMs.
Minimal example
importargparseimporttorchimporttransformer_engineasteparser=argparse.ArgumentParser()
parser.add_argument("--device", default=0, type=int)
parser.add_argument("--load", action="store_true")
args=parser.parse_args()
torch.cuda.set_device(args.device)
hidden_size=1024model=te.pytorch.Linear(hidden_size, hidden_size).cuda()
ifargs.load:
state=torch.load("model.pt")
model.load_state_dict(state)
print("After load, max_memory_reserved on device 0:", torch.cuda.max_memory_reserved(0))
for_inrange(10):
withte.pytorch.fp8_autocast(enabled=True):
output=model(torch.randn((32, hidden_size)).cuda())
torch.save(model.state_dict(), "model.pt")The issue is triggered this way:
>>> python test_fp8_mem.py --device 0
>>> python test_fp8_mem.py --device 1 --load
After load, max_memory_reserved on device 0: 23068672
Although, torch is set to use device 1 in the second call, memory on device 0 gets allocated as well. The overall CUDA context cannot be freed anymore, thus a significant part of the device is blocked.
Workaround
Restricting CUDA_VISIBLE_DEVICES to a single GPU per process works for us as a quick and dirty workaround
Problem description
When storing the state dict of a transformer_engine model on a device with index A and afterwards load it on another device with index B, some memory still gets allocated on device A. The reason for this seems the be the
pickle.loadsin https://github.com/NVIDIA/TransformerEngine/blob/main/transformer_engine/pytorch/module/base.py#L411This issue has a large practical impact in distributed training: if device 0 on a host writes the model checkpoint and when resuming the training all other devices read it, all 8 devices on the host suddenly allocate on device 0. In our case we are not able to resume trainings due to OOMs.
Minimal example
The issue is triggered this way:
Although, torch is set to use device 1 in the second call, memory on device 0 gets allocated as well. The overall CUDA context cannot be freed anymore, thus a significant part of the device is blocked.
Workaround
Restricting
CUDA_VISIBLE_DEVICESto a single GPU per process works for us as a quick and dirty workaround