<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kirill Shvets on Medium]]></title>
        <description><![CDATA[Stories by Kirill Shvets on Medium]]></description>
        <link>https://medium.com/@kirshvets?source=rss-84f83bb0f1a6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Kirill Shvets on Medium</title>
            <link>https://medium.com/@kirshvets?source=rss-84f83bb0f1a6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 02:36:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kirshvets/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Optimizing CatBoost Performance]]></title>
            <link>https://medium.com/intel-analytics-software/optimizing-catboost-performance-4f73f0593071?source=rss-84f83bb0f1a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f73f0593071</guid>
            <category><![CDATA[catboost]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[xeon]]></category>
            <category><![CDATA[intel]]></category>
            <category><![CDATA[data-analytics]]></category>
            <dc:creator><![CDATA[Kirill Shvets]]></dc:creator>
            <pubDate>Mon, 19 Apr 2021 19:11:15 GMT</pubDate>
            <atom:updated>2021-04-20T06:56:21.836Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qqxDd6Z2CDdfzrKX" /><figcaption>Photo by <a href="https://unsplash.com/@the_gerbs1?utm_source=medium&amp;utm_medium=referral">Jean Gerber</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Tricks to Improve Machine Learning Training Performance by Up to 4x</h4><h3>Gradient Boosting for Data Science</h3><p>There are plenty of well-known gradient boosting frameworks that deliver accuracy and efficiency in real-world applications. They are regarded as a multipurpose tool to deal with many types of machine learning problems.</p><p>According to the latest <a href="https://storage.googleapis.com/kaggle-media/surveys/Kaggle%20State%20of%20Machine%20Learning%20and%20Data%20Science%202020.pdf">Kaggle 2020 survey</a>, 61.4% of data scientists use gradient boosting (XGBoost, CatBoost, LightGBM) on a regular basis, and these frameworks are more commonly used than the various types of neural networks. Therefore, reducing the computational cost of gradient boosting is critical. Previous blogs have already covered Intel optimizations to XGBoost training and model converters that speed up LightGBM and XGBoost inference with no loss in accuracy.</p><ul><li><a href="https://medium.com/intel-analytics-software/new-optimizations-for-cpu-in-xgboost-1-1-81144ea21115">Optimizing XGBoost Training Performance</a></li><li><a href="https://medium.com/intel-analytics-software/improving-the-performance-of-xgboost-and-lightgbm-inference-3b542c03447e">Improving the Performance of XGBoost and LightGBM Inference</a></li></ul><p>This blog covers the CatBoost gradient boosting library. Compared to other libraries, CatBoost effectively handles categorical features and provides a larger variety of growing policies. For example, the SymmetricTree policy reduces the variance of a trained model and significantly improves training time. CatBoost v0.25 introduces optimizations that accelerate training up to 4x compared to the previous release (Figure 1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*QO6zhiYQd84J1D8VbfQfJw.png" /><figcaption>Figure 1. Relative speedup of CatBoost v0.25 over v0.24.3 for the Higgs1m and Airline1m datasets [1] and the Epsilon dataset [2]</figcaption></figure><p>Let’s have a closer look at these latest CatBoost optimizations.</p><h3>Optimization Details</h3><p>The training stage of gradient boosting is quite complex. There are many computational kernels requiring specific optimizations to mitigate irregular memory access patterns, parallelize loops with dependencies, and eliminate branch misprediction. Some optimizations for memory-bound workloads (e.g., using the smallest integer type, int8) were already implemented in earlier versions of CatBoost. However, there were still opportunities for enhancement, i.e.: using subtraction for histogram calculation, reducing threading overheads, and introducing a more effective default threading layer backend. Let’s go through these latest optimizations.</p><h4>The Subtraction Trick</h4><p>With the Depthwise growing policy, a tree is built level by level in each training iteration. This common approach can be parallelized efficiently over the feature columns and over node construction for nodes on the same tree level. Before training, CatBoost performs a quantization of feature columns to bins. The number of bins is controlled by the max_bin parameter. During training, CatBoost computes a histogram for each decision tree node. Histogram calculations consist of finding the sum of gradients and Hessians for each bin.</p><p>Histogram calculations are the most compute-intensive part of the training stage. However, a histogram’s additivity offers a solution to optimize the histogram calculation process. Because the histogram of a parent node is equal to the sum of the histograms of its child nodes, there is no need to compute the exact histogram for each node on the same level. Instead, it is possible to calculate the histogram for the smallest child of the parent node, and then compute the largest child’s histogram by subtracting the smallest child’s histogram from the previously saved parent’s histogram.</p><p>This algorithmic optimization was added to the main branch of the CatBoost GitHub repository. It significantly reduces the training time when the Depthwise growing policy is used (Table 1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*7W4JOvsgYmkxhDux2jXoFA.png" /><figcaption>Table 1. The speedup in CatBoost training with the Depthwise policy going from v0.24.3 to v0.25.</figcaption></figure><h4>Threading Layer Improvements</h4><p>The performance improvements described in the previous section would not have been possible without threading fixes made by the CatBoost maintainers. Significant threading overhead was observed with Intel VTune Profiler. Much of this overhead was eliminated by increasing the size of each task, but it did not solve the root cause of the issue.</p><p>We improved the threading layer by providing an alternative to the custom CatBoost threading layer backend: the Intel oneAPI Threading Building Blocks (oneTBB) library. Integrating the mature, well-supported, and highly optimized oneTBB library into CatBoost resolved the threading overhead problem by providing more effective task scheduling and better nested threading (Table 2).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*2ubYuNIQoBZX51XVCq76zQ.png" /><figcaption>Table 2. The performance improvements in CatBoost training with the SymmetricTree policy going from v0.24.3 to v0.25. Times are in seconds.</figcaption></figure><p>When using the SymmetricTree policy, oneTBB integration improved performance up to 1.5x over the previous threading layer. The CatBoost maintainers <a href="https://github.com/catboost/catboost/releases/tag/v0.25">report up to 2x speedups</a>. When combined with the subtraction trick, the oneTBB threading layer improved the training performance for the Depthwise policy (1.65x speedup for Higgs1m, 1.32x speedup for Airline1m, and 1.17x speedup for Epsilon) and yielded total improvements of 3.9x for Higgs1m, 4.1x for Airline1m, and 1.8x for Epsilon.</p><p>As of CatBoost v0.25, oneTBB is the default threading layer.</p><h3>Conclusions</h3><p>If you’re using CatBoost to train machine learning models, be sure to use the latest version. Up to 4x speedup can be obtained from the optimizations in v0.25, and there’s still more that can be done to improve CatBoost performance. Further core scalability improvements, better memory bandwidth utilization, and vector instructions usage are just a few examples that we expect to be added in future releases.</p><h3>Hardware and Software Configurations</h3><p>Intel Xeon Platinum 8280L (2nd generation Intel Xeon processors): 2 sockets; 28 cores per socket; HT: on; Turbo: on; total memory of 384 GB (12 slots/16 GB/2933 MHz). CatBoost 0.24.3 (before optimizations), 0.25 (after optimizations); NumPy 1.15.1; Scikit-learn 0.24.1, oneTBB 2021.2.</p><h3>Training Parameters</h3><p>Higgs1m [1] and Airline1m [1]:</p><pre>{iterations=1000, learning_rate=0.1, grow_policy=’Depthwise/SymmetricTree’, score_function=’L2&#39;, border_count=256, scale_pos_weight=2, l2_leaf_reg=1,logging_level=’Silent’, depth=8}</pre><p>Epsilon [2]:</p><pre>{max_depth: 8, learning_rate: 0.1, reg_lambda: 0, iterations=500, grow_policy=’Depthwise/SymmetricTree’, logging_level=’Silent’}</pre><h3>References</h3><ol><li>The Airline1m and Higgs1m datasets are available in the <a href="https://github.com/dmlc/xgboost-bench">dmlc xgboost benchmark repository</a>.</li><li>The Epsilon dataset is available in the <a href="https://github.com/NVIDIA/gbm-bench">Nvidia benchmark repository</a>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*fHTu7bFYhTZTKyMghrix5w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f73f0593071" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intel-analytics-software/optimizing-catboost-performance-4f73f0593071">Optimizing CatBoost Performance</a> was originally published in <a href="https://medium.com/intel-analytics-software">Intel Analytics Software</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing XGBoost Training Performance]]></title>
            <link>https://medium.com/intel-analytics-software/new-optimizations-for-cpu-in-xgboost-1-1-81144ea21115?source=rss-84f83bb0f1a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/81144ea21115</guid>
            <category><![CDATA[intel]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[xeon]]></category>
            <category><![CDATA[xgboost]]></category>
            <category><![CDATA[data-analytics]]></category>
            <dc:creator><![CDATA[Kirill Shvets]]></dc:creator>
            <pubDate>Thu, 25 Jun 2020 23:30:43 GMT</pubDate>
            <atom:updated>2021-04-08T23:31:05.727Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j2ByvvmG_D13CyXI" /><figcaption>Photo by <a href="https://unsplash.com/@i_am_g?utm_source=medium&amp;utm_medium=referral">Guillaume Jaillet</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4><em>XGBoost Just Keeps Getting Faster</em></h4><p>The gradient boosting trees algorithm has many real-world applications as a general-purpose, supervised learning technique for regression, classification, and page ranking problems. <a href="https://xgboost.readthedocs.io/en/latest/build.html">XGBoost</a>, the most popular implementation of this algorithm, gained popularity on the <a href="https://www.kaggle.com/">Kaggle</a> platform for machine learning competitions, where it was recognized for its high accuracy and efficiency.</p><p>Optimizing XGBoost training is complex because many computational kernels require specific optimization techniques for irregular memory access, loops with dependencies, and branch mispredictions. That is why starting from XGBoost version 0.9 Intel began optimizing the XGBoost training stage. These optimizations are now available as part of mainline <a href="https://github.com/dmlc/xgboost">XGBoost repository</a> as well as part of the <a href="https://software.intel.com/content/www/us/en/develop/tools/oneapi/ai-analytics-toolkit.html">Intel oneAPI AI Analytics Toolkit</a> (AI Kit). These efforts are paying off (Figure 1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*U14Opll9YyHaUGilioZiTQ.png" /><figcaption>Figure 1. Release-to-release acceleration of XGBoost training</figcaption></figure><p>In this article we are going to compare performance of XGBoost 1.1 on CPU and GPU and have a closer look at the optimizations that were introduced for this release. Let’s start with a simple example of XGBoost usage.</p><h3><em>A Practical Example of XGBoost in Action</em></h3><p>The well-known <a href="https://archive.ics.uci.edu/ml/datasets/Letter+Recognition">handwritten letters</a> data set illustrates XGBoost usage. This data set has 20,000 rows and 16 columns. Each row is described by 16 primitive numerical attributes (statistical moments and edge counts) that were scaled to fit a range of integer values from 0 through 15. Each row is associated with one of the 26 capital letters in the Latin alphabet. The XGBoost model is trained on 80% of the rows in the data set. The remaining 20% are used to test the model’s accuracy.</p><pre>import gboost <strong>as</strong> xgb<br><strong>import </strong>numpy <strong>as</strong> np</pre><pre># Set XGBoost parameters<br>xgb_params = {<br>   &#39;alpha&#39;:            0.9,<br>   &#39;max_bin&#39;:          256,<br>   &#39;scale_pos_weight&#39;: 2,<br>   &#39;learning_rate&#39;:    0.1,<br>   &#39;subsample&#39;:        1,<br>   &#39;reg_lambda&#39;:       1,<br>   &#39;min_child_weight&#39;: 0,<br>   &#39;max_depth&#39;:        8,<br>   &#39;max_leaves&#39;:       2**8,<br>   &#39;tree_method:       hist<br>}</pre><pre># Create DMatrix from the training set (in CSV format)<br>dtrain = xgb.DMatrix(&#39;letters_train.csv&#39;)</pre><pre># Train the model<br>model_xgb = xgb.train(xgb_params, dtrain, 1000)</pre><pre># Create DMatrix from the test set<br>dtest = xgb.DMatrix(&#39;letters_test.csv&#39;)<br>result_predict_xgb_test = model_xgb.predict(dtest)</pre><pre># Check model accuracy<br>acc = np.mean(y_test == result_predict_xgb_test)</pre><h3><em>Performance Comparison</em></h3><p>Training performance is critical for models that have to be retrained often (e.g., as new data becomes available). As such, training time is compared for five real-world datasets:</p><ul><li><a href="https://archive.ics.uci.edu/ml/datasets/HIGGS">Higgs</a> (1,000,000 rows, 2 classes)</li><li><a href="https://www.kaggle.com/bhoomika216/airline-dataset-for-analysis">Airline-OHE</a> (1,000,000 rows, 2 classes)</li><li><a href="https://www.microsoft.com/en-us/research/project/mslr/">MSRank</a> (3,000,000 rows, 5 classes)</li><li><a href="https://archive.ics.uci.edu/ml/datasets/Letter+Recognition">Letters</a> (20,000 rows, 26 classes)</li><li><a href="https://archive.ics.uci.edu/ml/datasets/Abalone">Abalone</a> (4,177 rows, 28 classes)</li><li><a href="https://archive.ics.uci.edu/ml/datasets/Abalone">Abalone</a> (4,177 rows, 28 classes)</li></ul><p>We use the following <a href="https://aws.amazon.com/ec2">AWS EC2</a> instances, each costs $3.06 per hour as of May 2020:</p><ul><li>Xeon: c5.18xlarge (Intel Xeon Platinum 8124M, 2 sockets, 18 cores per socket)</li><li>V100: p3.2xlarge (NVIDIA Tesla V100)</li></ul><p>Figure 2 shows that training is up to 4.5x faster on the Xeon instance compared to an equivalently priced V100 instance. A cost comparison is shown in Figure 3. What we observe is that XGBoost training is not only faster on the Xeon instances compared to the V100 instance, it is on average 2x cheaper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*M3YKlsLjlvJkUAcbW3ydUg.png" /><figcaption>Figure 2. XGBoost training time on Xeon vs. V100 AWS EC2 instances</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*hE6jXOVON_oPal0WzBDgrg.png" /><figcaption>Figure 3. Compute cost of XGBoost training on Xeon vs. V100 AWS EC2 instances</figcaption></figure><h3>Intel Optimizations in XGBoost</h3><p>The histogram tree-building method, which reduces the training time without compromising accuracy, is commonly used to solve large problems with a gradient-boosting model. Therefore, the histogram method for XGBoost training on is a prime optimization target.</p><p>Implementing this method is complex for the following reasons:</p><ul><li>It contains many kernels that impact execution time.</li><li>It does not use BLAS, LAPACK, or any other common linear algebra functions that are already highly-optimized.</li><li>Many kernels contain irregular memory access patterns, loops with dependencies, branch mispredictions, etc.</li></ul><p>Consequently, XGBoost optimization prior to version 1.0 was limited. Since then, Intel has introduced many optimizations to maximize training performance. Three hotspots were identified for tuning: building histograms, partitioning, and evaluation of split (finding the best split). These optimizations and their effects on XGBoost training performance are discussed below.</p><h4><em>Building Histograms</em></h4><p>Computation of gradients and Hessian matrices for training samples at each boosting iteration is performed by histogram building. The gradients and Hessian values can be summed into histogram bins according to the new discrete features. The task of finding the optimal splits for a decision tree is reduced to a simple problem of searching over the histogram bins in a discrete space.</p><p>XGBoost versions 0.81 and lower had a simple way to build histograms:</p><pre><strong>for </strong>(int i = 0; i &lt; n; ++i) {<br>  <strong>for </strong>(int j = 0; j &lt; p; ++j) {<br>    int bin = bins[row_idx[i] * p + j];<br>    hist[bin].g += g[i];<br>    hist[bin].h += h[i];<br>  }<br>}</pre><p>To improve performance, we should consider parallelization, batch operations, and reducing memory consumption.</p><p>The histogram computation is easily parallelized by row blocks with a simple map pattern. As a result, there are partial histograms on each thread that are merged into a single histogram before finding the best split. In the previous implementation, splitting by the number of rows was too granular, meaning that sometimes too many small tasks were created when building the lower nodes of a decision tree. This created too much threading overhead. To reduce it, we increased the minimum task size for each thread.</p><p>In the ‘<em>depthwise</em>’ building mode, tree nodes of the same level are built in parallel. Batch functions are introduced to enable parallelism by nodes on the current level of a tree. This allows nested parallelism and improves scaling.</p><p>Histogram building is a memory-bound task, so reducing memory consumption can improve performance. To achieve this, we used data types that consume less memory. Input parameters were dispatched to one of the integer types (uint8_t, uint16_t, or uint32_t) based on the user-provided max_bin value. As a result, memory usage was reduced up to 1.5x with no accuracy loss.</p><p>Before optimization, building histograms accounted for up to 82% of the training time. Now it consumes less than 50%. Table 1 shows the percent of the execution time attributed to each computational kernel in the XGBoost 1.1 release.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*WOVnauckC2zDOFPr2XSltQ.png" /><figcaption>Table 1. Percentage of the execution time of computational kernels in the XGBoost 1.1 release</figcaption></figure><p>As you can see, after BuildHist, the Partition function is another hotspot. Let’s see what could be done to optimize it.</p><h4><em>Partitioning and Finding the Best Split</em></h4><p>Partitioning works like this:</p><ol><li>After finding the best split (we have an index of the feature to split), run SplitIndex to split the sample in the current node into two descendents. This is known as SplitCondition.</li><li>Get the SplitIndex column.</li><li>Split the elements in this column into two subsets based on whether the element is less than SplitCondition. The first subset includes the indices of the elements that are less than SplitCondition, and the second contains the remaining indices.</li></ol><p>The main problem with this kernel is finding opportunities for efficient parallelization. Here is the scheme that we used:</p><ol><li>Divide the row index array among the threads.</li><li>Make a local partition in a local buffer.</li><li>Synchronize the threads to share the number of elements in each local partition.</li><li>Update the row index by copying the elements from the local buffers.</li></ol><h3>Conclusions</h3><p>As a result of the XGBoost optimizations contributed by Intel, training time is improved up to 16x compared to earlier versions (Figure 1). Currently, XGBoost training on Xeon outperforms V100 at lower computational cost (Figures 2 and 3).</p><h3>Installing the AI Kit</h3><p>The AI Kit provides a consolidated package of Intel’s latest deep and machine learning optimizations all in one place with seamless interoperability and high performance. The toolkit includes the Intel optimizations for XGBoost and also provides other Intel-optimized deep learning frameworks and Python libraries for end-to-end data science and AI workflows. The AI Kit is distributed through many common channels, including Intel’s website, YUM, APT, Anaconda, and more. <a href="https://software.intel.com/content/www/us/en/develop/tools/oneapi/ai-analytics-toolkit/download.html#operatingsystem=Linux">Select and download</a> the distribution package that you prefer and follow the <a href="https://software.intel.com/content/www/us/en/develop/documentation/get-started-with-ai-linux/top.html">Get Started Guide</a> for post-installation instructions to get all latest XGBoost optimizations for your workflows.</p><h3><em>Software and Hardware Configurations</em></h3><h4><em>Algorithm Parameters</em></h4><pre>xgb_params = {<br>  &#39;alpha&#39;:            0.9,<br>  &#39;max_bin&#39;:          256,<br>  &#39;scale_pos_weight&#39;: 2,<br>  &#39;learning_rate&#39;:    0.1,<br>  &#39;subsample&#39;:        1,<br>  &#39;reg_lambda&#39;:       1,<br>  &#39;min_child_weight&#39;: 0,<br>  &#39;max_depth&#39;:        8,<br>  &#39;max_leaves&#39;:       2**8,<br>  &#39;tree_method:       hist,<br>  &#39;n_estimators:      1000<br>}</pre><h4><em>Hardware Configuration</em></h4><p><strong>c5.metal AWS EC2 instance: </strong>Intel Xeon 8275CL processor, two sockets with 24 cores per socket, 192 GB RAM. OS: Ubuntu 18.04.2 LTS.</p><p><strong>с5.18xlarge AWS EC2 instance:</strong> Intel Xeon Platinum 8124M processor, two sockets with 18 cores per socket, 144 GB RAM. OS: Ubuntu 20.04 LTS.</p><p><strong>p3.2xlarge AWS EC2 instance:</strong> CPU: Intel Xeon E5–2686 v4 processor; GPU: Tesla V100-SXM2–16G (driver version: 410.104, CUDA version: 10.0), 61 GB RAM. OS: Ubuntu 18.04.2 LTS</p><p>Testing date: 05/18/2020</p><h4><em>Software Configuration</em></h4><p>XGBoost — release 1.1 build from sources.</p><p>Other software: Python 3.6, NumPy 1.16.4, pandas 0.25, Scikit-learn 0.21.2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*fHTu7bFYhTZTKyMghrix5w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81144ea21115" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intel-analytics-software/new-optimizations-for-cpu-in-xgboost-1-1-81144ea21115">Optimizing XGBoost Training Performance</a> was originally published in <a href="https://medium.com/intel-analytics-software">Intel Analytics Software</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>