Skip to content

Conversation

winglian
Copy link
Contributor

@winglian winglian commented Apr 8, 2025

What does this PR do?

Currently, low rank optimizers like Apollo can't be used with FSDP with the error below which is caused by copying the param, causing a view/leaf of the parameter. This PR fixes that and allows apollo_adamw optimizer to be used with FSDP(1)

[rank0]:   File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/transformers/trainer.py", line 1246, in create_optimizer
[rank0]:     self.optimizer = optimizer_cls(optimizer_grouped_parameters, **optimizer_kwargs)       
[rank0]:                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 745, in _fn
[rank0]:     return fn(*args, **kwargs)                                                                                       
[rank0]:            ^^^^^^^^^^^^^^^^^^^                    
[rank0]:   File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/apollo_torch/apollo.py", line 74, in __init__
[rank0]:     super().__init__(params, defaults)                                                                               
[rank0]:   File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/torch/optim/optimizer.py", line 377, in __init__
[rank0]:     self.add_param_group(cast(dict, param_group))
[rank0]:   File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/torch/_compile.py", line 32, in inner
[rank0]:     return disable_fn(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 745, in _fn
[rank0]:     return fn(*args, **kwargs)  
[rank0]:            ^^^^^^^^^^^^^^^^^^^  
[rank0]:   File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/torch/optim/optimizer.py", line 1062, in add_param_group
[rank0]:     param.is_leaf or param.retains_grad
[rank0]:     ^^^^^^^^^^^^^                                                                                                    
[rank0]: RuntimeError: Output 0 of ViewBackward0 is a view and its base or another view of its base has been modified inplace. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@SunMarc @ArthurZucker
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@github-actions github-actions bot marked this pull request as draft April 8, 2025 23:58
Copy link
Contributor

github-actions bot commented Apr 8, 2025

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@winglian winglian marked this pull request as ready for review April 8, 2025 23:59
@winglian winglian force-pushed the low-rank-optim-fsdp branch from f002426 to 30cd54f Compare April 9, 2025 00:01
@winglian
Copy link
Contributor Author

winglian commented Apr 9, 2025

/cc @zhuhanqing maintainer of Apollo optimizer

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks !

@ArthurZucker ArthurZucker merged commit 6a75528 into huggingface:main Apr 11, 2025
18 checks passed
cyr0930 pushed a commit to cyr0930/transformers that referenced this pull request Apr 18, 2025
…ggingface#37379)

prevent creating a view/leaf param for low rank optimizers:
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 14, 2025
…ggingface#37379)

prevent creating a view/leaf param for low rank optimizers:
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.

3 participants