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

Fairscale training #79

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Fairscale training #79

wants to merge 5 commits into from

Conversation

IanMagnusson
Copy link
Contributor

@IanMagnusson IanMagnusson commented Sep 12, 2022

This draft code adds two arguments to catwalk.train. 1) the --use_fairscale flag uses a FairScaleTrainingEngine instead of a normal TorchTrainingEngine. 2) the --modules_to_wrap" argument takes list of regex to for module names to wrap using Tango's with_wrapped_modules`. Neither of these currently work fully.

Problems

Without wrapping modules

By itself --use_fairscale will train and reproduce validation metrics as follows.

 python -m catwalk.train --model rc::gpt2 --task piqa --device_count 2 --use_fairscale 
...
Running log-likelihood queries: 100%|##########| 2000/2000 [00:07<00:00, 262.34it/s]
Calculating metrics: 100%|##########| 1000/1000 [00:00<00:00, 2167.71it/s]96.44it/s]
Step 999 metrics for <catwalk.tasks.eleuther.EleutherTask object at 0x7f0ac84373d0>: acc: 0.647
Running log-likelihood queries: 100%|##########| 2000/2000 [00:07<00:00, 257.42it/s]st_val_loss=3.02, val_loss=3.02]
Calculating metrics: 100%|##########| 1000/1000 [00:00<00:00, 2078.94it/s]11.26it/s]
Step 1999 metrics for <catwalk.tasks.eleuther.EleutherTask object at 0x7f0ac84373d0>: acc: 0.648
...
 python -m catwalk.train --model rc::gpt2 --task piqa --device_count 2
....
Running log-likelihood queries: 100%|##########| 2000/2000 [00:07<00:00, 270.13it/s]
Calculating metrics: 100%|##########| 1000/1000 [00:00<00:00, 4003.12it/s]85.04it/s]
Metrics for piqa: acc: 0.647######  | 804/1000 [00:00<00:00, 4020.71it/s]
Running log-likelihood queries: 100%|##########| 2000/2000 [00:07<00:00, 260.74it/s]_val_loss=3.02, val_loss=3.02]  
Calculating metrics: 100%|##########| 1000/1000 [00:00<00:00, 4000.07it/s]76.95it/s]
Metrics for piqa: acc: 0.648#####9  | 799/1000 [00:00<00:00, 3991.17it/s]
...

However it must run with amp/mixed_precision disabled to avoid NaNs in training. As such there is no memory footprint savings and the compute speed is lower than just not using fairscale. For instance with gpt2 on piqa with 2 gpus and batch size 16, memory is at 31150MiB / 40536MiB without fairscale and at 30952MiB / 40536MiB with --use_fairscale.

With module wrapping

The modules to wrap can be specified like this: python -m catwalk.train --model rc::gpt2 --task piqa --device_count 2 --use_fairscale --modules_to_wrap inner_module\\.transformer\\.h\\.\[0-9\]+. However inside catwalk_model.predict() in training_callback.py the following error occurs:

RuntimeError: Expected all tensors to be on the same device, but found at                    
                             least two devices, cuda:0 and cpu! (when checking argument for argument index                
                             in method wrapper__index_select)   

The issue as I understand it is that our custom .predict code does not support the distributed communication necessary. But my understanding of the problem is limited.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
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 this pull request may close these issues.

None yet

1 participant