Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to accelerate for Multi GPU #87

Closed
Ssukriti opened this issue Mar 13, 2024 · 3 comments · Fixed by #92
Closed

Switch to accelerate for Multi GPU #87

Ssukriti opened this issue Mar 13, 2024 · 3 comments · Fixed by #92
Assignees

Comments

@Ssukriti
Copy link
Collaborator

Ssukriti commented Mar 13, 2024

Is your feature request related to a problem? Please describe.

Accelerate https://huggingface.co/docs/transformers/en/accelerate is created by HF to help users easily train a Transformers model on any type of distributed setup, whether it is multiple GPU’s on one machine or multiple GPU’s across several machines. We should leverage the library for its ease of use.

Describe the solution you'd like

  1. update the README.md removing instructions for torch.run and replace with accelerate.launch
  2. replace the FSDP JSON with a config yaml like this.
  3. move fsdp_config.json out of tuning/config (which houses code) into somewhere which only houses config fixtures.

Describe alternatives you've considered

torchrun used currently can be less user friendly . See #80

(@fabianlim thanks for the suggestions)

@fabianlim
Copy link
Collaborator

fabianlim commented Mar 14, 2024

If we consider the constrained problem of running gpu jobs within a single pod, where each gpu is handled by a single process. There are the following options where mutiple processes are run:

  1. all together in a single container, within a single Kube pod
  2. individually each within a container, all containers housed within a single Kube pod.

There is also the third option where the processes are distributed across multiple Kube pods, but this may be over-complex. This would be the standard Kubeflow training operator approach.

Huggingface's recommendation is to run distributed training jobs using accelerate.

  • build on top of torchrun. The main process will spawn multiple worker processes for distributed training.
  • torchrun has a watchdog agent that handles things like fault tolerance.
  • processes communicates via various backends (e.g. static or c10d).
  • GPU communicates over GPU-network interfaces (e.g., NCCL).

Option 1:

  • is docker compliant to run multiple processes to parallelise work (e.g., running workers to parallelize an SQL query). This is very much like a master process spawning many child processes for distributed training.
  • has some fault tolerance capabilities already built in.

Option 2:

  • although the HF blog seems to claim that accelerate is backward compatible with torchrun, not sure how much of it is true. Certainly in the code there are a lot of acclerate specific flags that will only be set by accelerate launch.
  • for kube jobs it is mostly recommended to use the pytorch job controller, here is an example for distributed cpu jobs that can be extrapolated to GPUs. THey use torchrun, but probably also works for accelerate launch (due to the similarities in the API) This is incorrect as this will launch each worker in its own pod.

@kmehant
Copy link
Collaborator

kmehant commented Mar 15, 2024

There is also the third option where the processes are distributed across multiple Kube pods, but this may be over-complex. This would be the standard Kubeflow training operator approach.

The "PyTorchJob" operator/CR from standard Kubeflow training operator allows us to run multiple processes within single container in a pod (Master pod) like the option 1 when we just want to run a multi-gpu single node training job. When we wish to spawn multi-node multi-gpu job, then we would leverage the worker pod where distributed environment variables (node rank, master address, port etc) are automatically injected by the operator. We just simply replicate accelerate launch in the worker pod and the node rank from the operator determines whether the pod is a worker pod or not. Also there is local rank created by torch.distributed which differentiates between all the processes.

In option 1, AFAIK, most of the popular container runtimes are multiprocess friendly and on the resource side, the resource requests and limits are container level in Kubernetes.

@Ssukriti
Copy link
Collaborator Author

Ssukriti commented Mar 15, 2024

thanks for findings. We are working on the kubernetes solution in platform team in the next week.

The "PyTorchJob" operator/CR from standard Kubeflow training operator allows us to run multiple processes within single container in a pod (Master pod)

we will be testing it with kubeflow training operator. we will update when work is done as part of issue #88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants