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

Cleanup CPU predict function. #11139

Merged
merged 10 commits into from
Jan 11, 2025
Merged

Conversation

trivialfis
Copy link
Member

@trivialfis trivialfis commented Jan 2, 2025

  • Remove predict instance. It's dead code as we can't use it outside of XGBoost even with C++ include.
  • Remove unroll. No performance benefit.
  • Optimize dense QDM inference.
  • optimize data loading by directly copying data to feature vector instead of going through a workspace.

Partially address #10793

The optimization mostly focuses on dense data and the result varies between CPUs:

| Xeon(R) Gold 6128 |            DMatrix |    QuantileDMatrix |
|-------------------+--------------------+--------------------|
| Master            | 27.980122327804565 | 55.665775775909424 |
| PR                |  23.63674759864807 | 30.158272981643677 |

| Ryzen 9 7900X3D |            DMatrix |    QuantileDMatrix |
|-----------------+--------------------+--------------------|
| Master          | 24.764960527420044 | 31.460495710372925 |
| PR              | 22.532921314239502 | 21.412014961242676 |

@trivialfis
Copy link
Member Author

trivialfis commented Jan 6, 2025

@razdoburdin Could you please help take a look into the optimization?

I'm not an expert in CPU optimization. The changes in the predictor affects the Xeon much more significantly than the Ryzen. If I remove the dense optimization, it adds about 3 seconds to Ryzen, but 20 seconds to the Xeon.

Looking at some profiling results on Ryzen, the bottleneck seems to be in data loading (movss/movl). Would love to get some opinions.

@razdoburdin
Copy link
Contributor

@razdoburdin Could you please help take a look into the optimization?

I'm not an expert in CPU optimization. The changes in the predictor affects the Xeon much more significantly than the Ryzen. If I remove the dense optimization, it adds about 3 seconds to Ryzen, but 20 seconds to the Xeon.

Looking at some profiling results on Ryzen, the bottleneck seems to be in data loading (movss/movl). Would love to get some opinions.

It is hard to give the exact answer without deep investigation of the changes. My hypothesis are:

  1. Xeon benefits more from vectorization due to AVX512 support
  2. Xeon has much smaller L3 cache, that makes memory access optimizations more critical.

@trivialfis
Copy link
Member Author

@razdoburdin Thank you for sharing, could you please help review the changes in the CPU predictor when you are available?

It is hard to give the exact answer without deep investigation of the changes

Currently, the evaluation might be even more expensive than training for some datasets. Would be great if we could get some help on that.

Copy link
Contributor

@razdoburdin razdoburdin left a comment

Choose a reason for hiding this comment

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

The PR looks good for me.
As for future prediction optimization, I plan to work on it, but latter this year.

@trivialfis
Copy link
Member Author

As for future prediction optimization, I plan to work on it, but latter this year.

Thank you for looking into it. Feel free to ping me if there's anything I can help.

include/xgboost/tree_model.h Outdated Show resolved Hide resolved
@trivialfis
Copy link
Member Author

@hcho3 Could you please help approve the PR if there's no further change request? The CI failure is unrelated (sklearn update).

@trivialfis trivialfis merged commit 712e39d into dmlc:master Jan 11, 2025
57 of 59 checks passed
@trivialfis trivialfis deleted the cleanup-predict branch January 11, 2025 14:15
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