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

Gradients are None after booster.backward #5792

Open
ArnaudFickinger opened this issue Jun 11, 2024 · 10 comments
Open

Gradients are None after booster.backward #5792

ArnaudFickinger opened this issue Jun 11, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@ArnaudFickinger
Copy link

ArnaudFickinger commented Jun 11, 2024

After calling booster.backward(loss=loss, optimizer=optimizer), all gradients of model.module are None. Is there a way to access the gradients?

@ArnaudFickinger ArnaudFickinger added the bug Something isn't working label Jun 11, 2024
@B-Soul
Copy link

B-Soul commented Jun 11, 2024

I meet the same problem,have you found a solution?

@botbw
Copy link
Contributor

botbw commented Jun 11, 2024

hey @ArnaudFickinger @B-Soul , could you please share the settings of your scripts?

@B-Soul
Copy link

B-Soul commented Jun 11, 2024

My code is related to my own ongoing research, so it is not convenient to share. But I just changed the distributed framework used to Huggingface Accelerate, and gradients are not None. So, I think there is a bug in colossalai framwork.

@botbw
Copy link
Contributor

botbw commented Jun 11, 2024

My code is related to my own ongoing research, so it is not convenient to share. But I just changed the distributed framework used to Huggingface Accelerate, and gradients are not None. So, I think there is a bug in colossalai framwork.

hi @B-Soul , a snippet of optimizer/plugin settings will help. Besides, the gradient accessing API might be different due to optimization, if you are using LowLevelZeroOptimizer or GeminiOptimizer, you could check those tests for gradient accessing: genimi and low-level

@ArnaudFickinger
Copy link
Author

ArnaudFickinger commented Jun 11, 2024

@botbw thank you the low-level snippet is working! By the way which of gemini or low-level should I use for best performance with 1 to 8 A100 GPUs and 500M to 2B trainable parameters?

@botbw
Copy link
Contributor

botbw commented Jun 12, 2024

@botbw thank you the low-level snippet is working! By the way which of gemini or low-level should I use for best performance with 1 to 8 A100 GPUs and 500M to 2B trainable parameters?

@ArnaudFickinger Glad to hear that! And we might work on the API to make it more intuitive.

Regarding the performance, LowLevelZeroOptimizer implements zero-1 and zero-2 and GeminiOptimizer implements zero-3 together with continuous memory optimization (i.e. memory locality, you may check this doc for more information) to reduce communication cost.

Generally speaking, you should choose the plugin by the intended zero-n parallel strategy, the real-world performance might be case-by-case and depend on the trade-off between computation and communication.

Do let us know if you have further doubts :p

@ArnaudFickinger
Copy link
Author

@botbw when I define 2 param_groups the id() of the parameters of the second group do not match any keys of optimizer._grad_store._grads_of_params[1]

@botbw
Copy link
Contributor

botbw commented Jun 15, 2024

@botbw when I define 2 param_groups the id() of the parameters of the second group do not match any keys of optimizer._grad_store._grads_of_params[1]

@ArnaudFickinger I guess it's unexpected since each group is handled separately in the same way (like a for loop), would you mind sharing the version (or commit) you are using and a min repro if possible?

@ArnaudFickinger
Copy link
Author

@botbw I have written a min repro with a simple network and in this case the keys actually match! I will take a closer look at my code and get back to you if I believe the issue might still be ColossalAI related.

@botbw
Copy link
Contributor

botbw commented Jun 15, 2024

@botbw I have written a min repro with a simple network and in this case the keys actually match! I will take a closer look at my code and get back to you if I believe the issue might still be ColossalAI related.

@ArnaudFickinger Sure, feel free to ask here or raise a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants