Skip to content

Conversation

@cyyever
Copy link
Contributor

@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
Contributor 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
Contributor Author

cyyever commented Feb 20, 2025

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

@qgallouedec qgallouedec added the 😴 stale No update from the author, will be closed soon label Mar 16, 2025
@qgallouedec qgallouedec closed this Apr 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

😴 stale No update from the author, will be closed soon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants