|
1 |
| -# `Intel® Python XGBoost Performance Sample` |
2 |
| -This sample code illustrates how to analyze the performance benefit from using Intel optimizations upstreamed by Intel to latest XGBoost compared to un-optimized XGBoost 0.81. It demonstrates how to use software products that can be found in the [Intel® AI Analytics Toolkit (AI Kit)](https://software.intel.com/content/www/us/en/develop/tools/oneapi/ai-analytics-toolkit.html). |
| 1 | +# `Intel® Python XGBoost Performance` Sample |
3 | 2 |
|
4 |
| -| Optimized for | Description |
5 |
| -| :--- | :--- |
6 |
| -| OS | 64-bit Linux: Ubuntu 18.04 or higher |
7 |
| -| Hardware | Intel Atom® Processors; Intel® Core™ Processor Family; Intel® Xeon® Processor Family; Intel® Xeon® Scalable processor family |
8 |
| -| Software | XGBoost, Intel® AI Analytics Toolkit |
9 |
| -| What you will learn | How to analyze the performance benefit from using Intel optimizations upstreamed by Intel to the latest XGBoost compared to un-optimized XGBoost 0.81 |
10 |
| -| Time to complete | 10-15 minutes |
| 3 | +This `Intel® Python XGBoost Performance` sample illustrates how to analyze the performance benefit from using Intel optimizations upstreamed by Intel to latest XGBoost compared to un-optimized XGBoost 0.81. It demonstrates how to use software products that can be found in the [Intel® AI Analytics Toolkit (AI Kit)](https://software.intel.com/content/www/us/en/develop/tools/oneapi/ai-analytics-toolkit.html). |
| 4 | + |
| 5 | +| Area | Description |
| 6 | +| :--- | :--- |
| 7 | +| What you will learn | How to analyze the performance benefit from using Intel optimizations upstreamed by Intel to the latest XGBoost compared to un-optimized XGBoost 0.81 |
| 8 | +| Time to complete | 10-15 minutes |
| 9 | +| Category | Code Optimization |
11 | 10 |
|
12 | 11 | ## Purpose
|
13 | 12 |
|
14 |
| -XGBoost is a widely used gradient boosting library in the classical ML area. Designed for flexibility, performance, and portability, XGBoost includes optimized distributed gradient boosting frameworks and implements Machine Learning algorithms underneath. |
| 13 | +XGBoost is a widely used gradient boosting library in the classical machine learning (ML) area. Designed for flexibility, performance, and portability, XGBoost includes optimized distributed gradient boosting frameworks and implements Machine Learning algorithms underneath. |
| 14 | + |
| 15 | +## Prerequisites |
15 | 16 |
|
16 |
| -In this sample, you will an XGBoost model and prediction using Intel optimizations upstreamed by Intel to the latest XGBoost package and the un-optimized XGBoost 0.81 for comparison. |
| 17 | +| Optimized for | Description |
| 18 | +|:--- |:--- |
| 19 | +| OS | Ubuntu* 18.04 or higher |
| 20 | +| Hardware | Intel Atom® processors <br> Intel® Core™ processor family <br> Intel® Xeon® processor family <br> Intel® Xeon® Scalable processor family |
| 21 | +| Software | XGBoost <br> Intel® AI Analytics Toolkit (AI Kit) |
17 | 22 |
|
18 | 23 | ## Key Implementation Details
|
19 |
| -This XGBoost sample code is implemented for the CPU using the Python language. The example assumes you XGBoost installed inside a conda environment, similar to what is delivered with the installation of the Intel® Distribution for Python* as part of the [Intel® AI Analytics Toolkit](https://software.intel.com/en-us/oneapi/ai-kit). It also assumes you have set up an additional XGBoost 0.81 conda environment, with details on how to do so explained within the sample and this README. |
20 | 24 |
|
21 |
| -## License |
22 |
| -Code samples are licensed under the MIT license. See |
23 |
| -[License.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/License.txt) for details. |
| 25 | +In this sample, you will use a XGBoost model and prediction using Intel optimizations upstreamed by Intel to the latest XGBoost package and the un-optimized XGBoost 0.81 for comparison. |
24 | 26 |
|
25 |
| -Third-party program Licenses can be found here: [third-party-programs.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/third-party-programs.txt) |
| 27 | +This XGBoost sample code is implemented for the CPU using the Python language. The example assumes you XGBoost installed inside a conda environment, similar to what is delivered with the installation of the Intel® Distribution for Python* as part of the [Intel® AI Analytics Toolkit](https://software.intel.com/en-us/oneapi/ai-kit). It also assumes you have set up an additional XGBoost 0.81 conda environment, with details on how to do so explained within the sample and this README. |
26 | 28 |
|
27 |
| -## Building XGBoost for CPU |
| 29 | +## Set Environment Variables |
28 | 30 |
|
29 |
| -XGBoost is ready for use once you finish the Intel® AI Analytics Toolkit installation and have run the post installation script. |
| 31 | +When working with the command-line interface (CLI), you should configure the oneAPI toolkits using environment variables. Set up your CLI environment by sourcing the `setvars` script every time you open a new terminal window. This practice ensures that your compiler, libraries, and tools are ready for development. |
30 | 32 |
|
31 |
| -You can refer to the oneAPI [main page](https://software.intel.com/en-us/oneapi) for toolkit installation and the Toolkit [Getting Started Guide for Linux](https://software.intel.com/en-us/get-started-with-intel-oneapi-linux-get-started-with-the-intel-ai-analytics-toolkit) for post-installation steps and scripts. |
| 33 | +## Run the `Intel® Python XGBoost Performance` Sample |
| 34 | + |
| 35 | +### On Linux* |
32 | 36 |
|
33 | 37 | > **Note**: If you have not already done so, set up your CLI
|
34 |
| -> environment by sourcing the `setvars` script located in |
35 |
| -> the root of your oneAPI installation. |
36 |
| -> |
37 |
| -> Linux Sudo: . /opt/intel/oneapi/setvars.sh |
38 |
| -> |
39 |
| -> Linux User: . ~/intel/oneapi/setvars.sh |
| 38 | +> environment by sourcing the `setvars` script in the root of your oneAPI installation. |
40 | 39 | >
|
41 |
| -> Windows: C:\Program Files(x86)\Intel\oneAPI\setvars.bat |
| 40 | +> Linux*: |
| 41 | +> - For system wide installations: `. /opt/intel/oneapi/setvars.sh` |
| 42 | +> - For private installations: ` . ~/intel/oneapi/setvars.sh` |
| 43 | +> - For non-POSIX shells, like csh, use the following command: `bash -c 'source <install-dir>/setvars.sh ; exec csh'` |
42 | 44 | >
|
43 |
| ->For more information on environment variables, see Use the setvars Script for [Linux or macOS](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-linux-or-macos.html), or [Windows](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-windows.html). |
| 45 | +> For more information on configuring environment variables, see *[Use the setvars Script with Linux* or macOS*](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-linux-or-macos.html)*. |
44 | 46 |
|
45 |
| -### Activate conda environment With Root Access |
| 47 | +XGBoost is ready for use once you finish the Intel® AI Analytics Toolkit installation and have run the post installation script. |
46 | 48 |
|
47 |
| -Intel Python environment will be active by default. However, if you activated another environment, you can return with the following command: |
| 49 | +You can refer to the oneAPI [main page](https://software.intel.com/en-us/oneapi) for toolkit installation and the Toolkit [Getting Started Guide for Linux](https://software.intel.com/en-us/get-started-with-intel-oneapi-linux-get-started-with-the-intel-ai-analytics-toolkit) for post-installation steps and scripts. |
| 50 | + |
| 51 | +#### Activate Conda with Root Access |
| 52 | + |
| 53 | +By default, the AI Kit is installed in the `/opt/intel/oneapi` folder and requires root privileges to manage it. However, if you activated another environment, you can return with the following command. |
48 | 54 |
|
49 |
| -#### On a Linux* System |
50 | 55 | ```
|
51 | 56 | source activate base
|
52 | 57 | ```
|
53 | 58 |
|
54 |
| -### Activate conda environment Without Root Access (Optional) |
| 59 | +#### Activate Conda without Root Access (Optional) |
55 | 60 |
|
56 |
| -By default, the Intel® AI Analytics Toolkit is installed in the inteloneapi folder, which requires root privileges to manage it. If you would like to bypass using root access to manage your conda environment, then you can clone your desired conda environment using the following command: |
| 61 | +You can choose to activate Conda environment without root access. To bypass root access to manage your Conda environment, clone and activate your desired Conda environment using the following commands similar to the following. |
57 | 62 |
|
58 |
| -#### On a Linux* System |
59 | 63 | ```
|
60 | 64 | conda create --name usr_intelpython --clone base
|
61 |
| -``` |
62 |
| - |
63 |
| -Then activate your conda environment with the following command: |
64 |
| - |
65 |
| -``` |
66 | 65 | source activate usr_intelpython
|
67 | 66 | ```
|
68 | 67 |
|
69 |
| -### Install Jupyter Notebook |
| 68 | +#### Install Jupyter Notebook |
| 69 | + |
70 | 70 | ```
|
71 | 71 | conda install jupyter nb_conda_kernels
|
72 | 72 | ```
|
73 | 73 |
|
74 |
| -### Building XGBoost 0.81 Conda Environment |
| 74 | +### Build Another XGBoost 0.81 Conda Environment |
75 | 75 |
|
76 |
| -To see the performance comparison to the latest XGBoost with Intel optimizations and un-optimized XGBoost 0.81, you will be required to run this sample in a second conda environment with XGBoost 0.81 installed. |
77 |
| - |
78 |
| -### View in Jupyter Notebook |
79 |
| - |
80 |
| -_Note: This distributed execution cannot be launched from the jupyter notebook version, but you can still view inside the notebook to follow the included write-up and description._ |
81 |
| - |
82 |
| -Launch Jupyter Notebook in the directory housing the code example |
83 |
| - |
84 |
| -``` |
85 |
| -jupyter notebook |
86 |
| -``` |
| 76 | +To see the performance comparison to the latest XGBoost with Intel optimizations and un-optimized XGBoost 0.81, you must run this sample in a second conda environment with **XGBoost 0.81** installed. |
87 | 77 |
|
88 |
| -## Running the Sample |
| 78 | +See the information in the Jupyter Notebook on how to set up and run the different conda environments. |
89 | 79 |
|
90 |
| -### Running the Sample as a Jupyter Notebook |
| 80 | +### View in Jupyter Notebook |
91 | 81 |
|
92 |
| -Open .pynb file and run cells in Jupyter Notebook using the "Run" button (see the image using "Modin Getting Started" sample) |
| 82 | +> **Note**: This distributed sample cannot be executed from the Jupyter Notebook, but you can read the description and follow the program flow in the Notebook. |
93 | 83 |
|
94 |
| - |
| 84 | +#### Open Jupyter Notebook |
95 | 85 |
|
96 |
| -##### Expected Printed Output for Cells (with similar numbers): |
97 |
| -``` |
98 |
| -[CODE_SAMPLE_COMPLETED_SUCCESFULLY] |
99 |
| -``` |
| 86 | +> **Note**: This distributed sample cannot be executed from the Jupyter Notebook, but you can read the description and follow the program flow in the Notebook. |
100 | 87 |
|
101 |
| -### Running the Sample as a Python File |
| 88 | +1. Change to the sample directory. |
| 89 | +2. Launch Jupyter Notebook. |
| 90 | + ``` |
| 91 | + jupyter notebook |
| 92 | + ``` |
| 93 | +3. Locate and select the Notebook. |
| 94 | + ``` |
| 95 | + IntelPython_XGBoost_Performance.ipynb |
| 96 | + ``` |
| 97 | +4. Click the **Run** button to move through the cells in sequence. |
102 | 98 |
|
103 |
| -Open notebook in Jupyter and download as python file (see the image using "daal4py Hello World" sample) |
| 99 | +### Run the Python Script |
104 | 100 |
|
105 |
| - |
| 101 | +1. Change to the sample directory. |
| 102 | +2. Locate and run the script. |
| 103 | + ``` |
| 104 | + python IntelPython_XGBoost_Performance.py |
| 105 | + ``` |
106 | 106 |
|
107 |
| -Run the Program |
| 107 | +#### Troubleshooting |
108 | 108 |
|
109 |
| -`python IntelPython_XGBoost_Performance.py` |
| 109 | +If you receive an error message, troubleshoot the problem using the **Diagnostics Utility for Intel® oneAPI Toolkits**. The diagnostic utility provides configuration and system checks to help find missing dependencies, permissions errors, and other issues. See the *[Diagnostics Utility for Intel® oneAPI Toolkits User Guide](https://www.intel.com/content/www/us/en/develop/documentation/diagnostic-utility-user-guide/top.html)* for more information on using the utility. |
110 | 110 |
|
111 |
| -The output files of the script will be saved in the included models and result directories. |
| 111 | +## Example Output |
112 | 112 |
|
113 |
| -##### Expected Printed Output (with similar numbers): |
114 | 113 | ```
|
115 | 114 | [CODE_SAMPLE_COMPLETED_SUCCESFULLY]
|
116 | 115 | ```
|
117 |
| -### Using Visual Studio Code* (VS Code) |
118 | 116 |
|
119 |
| -You can use VS Code extensions to set your environment, create launch configurations, |
120 |
| -and browse and download samples. |
121 |
| - |
122 |
| -The basic steps to build and run a sample using VS Code include: |
123 |
| - - Download a sample using the extension **Code Sample Browser for Intel oneAPI Toolkits**. |
124 |
| - - Configure the oneAPI environment with the extension **Environment Configurator for Intel oneAPI Toolkits**. |
125 |
| - - Open a Terminal in VS Code (**Terminal>New Terminal**). |
126 |
| - - Run the sample in the VS Code terminal using the instructions below. |
| 117 | +## License |
127 | 118 |
|
128 |
| -To learn more about the extensions and how to configure the oneAPI environment, see |
129 |
| -[Using Visual Studio Code with Intel® oneAPI Toolkits](https://software.intel.com/content/www/us/en/develop/documentation/using-vs-code-with-intel-oneapi/top.html). |
| 119 | +Code samples are licensed under the MIT license. See |
| 120 | +[License.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/License.txt) for details. |
130 | 121 |
|
131 |
| -After learning how to use the extensions for Intel oneAPI Toolkits, return to this readme for instructions on how to build and run a sample. |
| 122 | +Third-party program Licenses can be found here: [third-party-programs.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/third-party-programs.txt). |
0 commit comments