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

Remove CUDA synchronization in mean_token_accuracy #2902

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cyyever
Copy link

@cyyever cyyever commented Feb 19, 2025

What does this PR do?

mean_token_accuracy computation invokes item() on token counts, which triggers CUDA to CPU synchronization. That synchronization becomes a minor performance bottleneck in LLM fine-tuning, as indicated by the following profiling snapshot from v0.15.1:

image

That bottleneck has been fixed in this PR by accumulating the correct and total token counts in tensors. item() calls are delayed until trainer.log().
The effects of the change are indicated by another profiling that the bottleneck disappears:

image

Because the metrics are cleared immediately after logging, this change should be safe and backwards-compatible.

Before submitting

Who can review?

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.

@qgallouedec
Copy link
Member

I don't understand the profiling actually. Where do you get that this line is the bottleneck?
Thank for contributing!

@cyyever cyyever changed the title Fix CUDA sync point in mean_token_accuracy Remove CUDA synchronization in mean_token_accuracy Feb 19, 2025
@cyyever
Copy link
Author

cyyever commented Feb 19, 2025

@qgallouedec It is the sixth line in the first picture. It's not a main bottleneck, however, the GPU utility rose a bit after fixing it.

@qgallouedec
Copy link
Member

This?

dequantize_4bit (bitsandbytes/functional. py:1380)

@qgallouedec
Copy link
Member

qgallouedec commented Feb 19, 2025

The comparison is not very clear to me tbh, do you have clearer results, like two trainings (one with main, one with your branch) where we can see the speedup in term of steps/sec?

@cyyever
Copy link
Author

cyyever commented Feb 20, 2025

@qgallouedec Of course, I will provide a comparison ASAP.

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.

2 participants