open-mmlab / mmengine

OpenMMLab Foundational Library for Training Deep Learning Models
https://mmengine.readthedocs.io/
Apache License 2.0
1.16k stars 351 forks source link

Thoughts on an integration with πŸ€— Accelerate? #583

Closed muellerzr closed 1 year ago

muellerzr commented 2 years ago

What is the problem this feature will solve?

Integration with πŸ€— Accelerate opens up a wide variety of doors right at the get-go:

What is the feature you are proposing to solve the problem?

Modifying code to utilize πŸ€— Accelerate is extremely straightforward, and leaves the code looking as close to plain PyTorch as possible. See below where the only changes are taking the code from a single-gpu and modifying it to be used across GPUs, TPUs, and M1:

+ from accelerate import Accelerator
+ accelerator = Accelerator()

+ model, optimizer, training_dataloader, scheduler = accelerator.prepare(
+     model, optimizer, training_dataloader, scheduler
+ )

  for batch in training_dataloader:
      optimizer.zero_grad()
      inputs, targets = batch
      inputs = inputs.to(device)
      targets = targets.to(device)
      outputs = model(inputs)
      loss = loss_function(outputs, targets)
+     accelerator.backward(loss)
      optimizer.step()
      scheduler.step()

To read more, check out these important documentation tutorials that describe various aspects of the library:

Let me know if this is of interest to the team and we can assist as much as we can towards getting an integration with mmdetection going! πŸ˜„

What alternatives have you considered?

Lots and lots of custom code to get it working across all devices

ZwwWayne commented 2 years ago

Hi @muellerzr , Thanks for your kind suggestion. We are considering it. If we want do that, we could simply add it in mmengine, which could be used to accelerate all openmmlab projects.

zhouzaida commented 1 year ago

We have support DeepSpeed or FSDP in MMEngine. https://github.com/open-mmlab/mmengine/pull/1183

hiyyg commented 1 year ago

Wish to have Accelerate and Fabric in mmengine, they are very simple and effective!