Skip to content

Commit 98e96a5

Browse files
committed
Train and deploy XGBoost models on Google Cloud C4A Axion VM
Signed-off-by: odidev <odidev@puresoftware.com>
1 parent d721ee4 commit 98e96a5

14 files changed

Lines changed: 742 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: Train and deploy XGBoost models on Google Cloud C4A Axion VM
3+
4+
description: Set up XGBoost on Google Cloud C4A Axion Arm VMs running SUSE Linux to train machine learning models, tune model performance, benchmark large-scale datasets, and deploy trained models as REST APIs.
5+
6+
minutes_to_complete: 30
7+
8+
who_is_this_for: This is an introductory topic for DevOps engineers, ML engineers, data engineers, and software developers who want to train and deploy XGBoost machine learning models on SUSE Linux Enterprise Server (SLES) Arm64, optimize model performance, benchmark training workloads, and expose models through scalable inference APIs.
9+
10+
learning_objectives:
11+
- Install and configure XGBoost on Google Cloud C4A Axion processors for Arm64
12+
- Train and evaluate machine learning models using XGBoost
13+
- Tune model hyperparameters and benchmark large-scale datasets
14+
- Deploy trained XGBoost models as REST APIs and validate inference workflows
15+
16+
prerequisites:
17+
- A [Google Cloud Platform (GCP)](https://cloud.google.com/free) account with billing enabled
18+
- Basic familiarity with Python and machine learning concepts
19+
20+
author: Pareena Verma
21+
22+
##### Tags
23+
skilllevels: Introductory
24+
subjects: ML
25+
cloud_service_providers:
26+
- Google Cloud
27+
28+
armips:
29+
- Neoverse
30+
31+
tools_software_languages:
32+
- XGBoost
33+
- Python
34+
- scikit-learn
35+
- Flask
36+
37+
operatingsystems:
38+
- Linux
39+
40+
# ================================================================================
41+
# FIXED, DO NOT MODIFY
42+
# ================================================================================
43+
44+
further_reading:
45+
- resource:
46+
title: XGBoost official documentation
47+
link: https://xgboost.readthedocs.io/en/stable/
48+
type: documentation
49+
50+
- resource:
51+
title: XGBoost GitHub repository
52+
link: https://github.com/dmlc/xgboost
53+
type: documentation
54+
55+
- resource:
56+
title: Scikit-learn documentation
57+
link: https://scikit-learn.org/stable/
58+
type: documentation
59+
60+
- resource:
61+
title: Flask documentation
62+
link: https://flask.palletsprojects.com/
63+
type: documentation
64+
65+
weight: 1
66+
layout: "learningpathall"
67+
learning_path_main_page: yes
68+
---
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# ================================================================================
3+
# FIXED, DO NOT MODIFY THIS FILE
4+
# ================================================================================
5+
weight: 21 # Set to always be larger than the content in this path to be at the end of the navigation.
6+
title: "Next Steps" # Always the same, html page title.
7+
layout: "learningpathall" # All files under learning paths have this same wrapper for Hugo processing.
8+
---
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Learn about XGBoost and Google Axion C4A for machine learning
3+
weight: 2
4+
5+
layout: "learningpathall"
6+
---
7+
8+
## Google Axion C4A Arm instances for machine learning
9+
10+
Google Axion C4A is a family of Arm-based virtual machines built on Google’s custom Axion CPU, which is based on Arm Neoverse V2 cores. Designed for high-performance and energy-efficient computing, these virtual machines offer strong performance for modern cloud workloads such as CI/CD pipelines, microservices, media processing, and general-purpose applications.
11+
12+
The C4A series provides a cost-effective alternative to x86 virtual machines while using the scalability and performance benefits of the Arm architecture in Google Cloud.
13+
14+
To learn more, see the Google blog [Introducing Google Axion Processors, our new Arm-based CPUs](https://cloud.google.com/blog/products/compute/introducing-googles-new-arm-based-cpu).
15+
16+
## XGBoost for scalable machine learning on Arm
17+
18+
XGBoost (Extreme Gradient Boosting) is a high-performance machine learning library designed for supervised learning tasks such as classification, regression, and ranking. It's widely used for tabular machine learning workloads because of its speed, scalability, and strong predictive accuracy.
19+
20+
XGBoost provides features such as:
21+
22+
* Parallelized tree boosting for fast model training
23+
* Built-in regularization to reduce overfitting
24+
* Hyperparameter tuning support for performance optimization
25+
* Efficient handling of large-scale datasets
26+
* Optimized CPU execution for multi-core systems
27+
* Model export and deployment for inference workloads
28+
29+
Running XGBoost on Google Axion C4A Arm-based infrastructure enables efficient execution of machine learning workloads by using the high core-count architecture and optimized memory bandwidth available on Arm processors. This helps improve performance-per-watt, reduce infrastructure costs, and scale machine learning pipelines efficiently.
30+
31+
Common use cases include:
32+
33+
* Fraud detection
34+
* Recommendation systems
35+
* Customer churn prediction
36+
* Financial forecasting
37+
* Classification and regression workloads
38+
* Large-scale tabular data training
39+
* Real-time inference APIs
40+
41+
XGBoost integrates easily with Python machine learning ecosystems such as Scikit-learn, NumPy, and Pandas, making it suitable for both experimentation and production deployment workflows.
42+
43+
To learn more, see the [XGBoost documentation](https://xgboost.readthedocs.io/en/stable/) and the [XGBoost GitHub repository](https://github.com/dmlc/xgboost).
44+
45+
## What you've learned and what's next
46+
47+
You've now learned about Google Axion C4A Arm-based virtual machines and their performance advantages for machine learning workloads. You were also introduced to XGBoost and its capabilities for scalable training, hyperparameter tuning, and high-performance inference on Arm processors.
48+
49+
Next, you'll install XGBoost and configure a Python 3.11 environment on a GCP Axion Arm64 VM for model training and benchmarking.
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
---
2+
title: Deploy and access XGBoost inference API
3+
weight: 8
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Deploy XGBoost inference API on SUSE Linux
10+
11+
In this section, you'll deploy the trained XGBoost model as a Flask-based inference API on a GCP Axion Arm64 VM. You'll expose the API externally and access it from a browser using the VM public IP.
12+
13+
You'll use:
14+
15+
**Terminal A** → API server
16+
17+
**Terminal B** → API testing
18+
19+
## Connect to the VM
20+
Connect to the VM where the trained XGBoost model and Python environment were created. This VM will host the inference API service.
21+
22+
```bash
23+
ssh <your-user>@<your-vm-ip>
24+
```
25+
26+
Navigate to the XGBoost project directory that contains the trained model files and scripts.
27+
28+
```bash
29+
cd ~/xgboost-learning-path
30+
```
31+
32+
Activate the Python virtual environment to load all required Python packages and dependencies.
33+
34+
```bash
35+
source xgb-env/bin/activate
36+
```
37+
38+
## Install Flask
39+
Flask is used to create the lightweight REST API that serves XGBoost predictions through HTTP requests.
40+
41+
Create an updated requirements file containing all required Python dependencies.
42+
43+
```bash
44+
cat > requirements.txt <<'EOF'
45+
xgboost
46+
numpy
47+
pandas
48+
scikit-learn
49+
matplotlib
50+
joblib
51+
flask
52+
EOF
53+
```
54+
55+
Install all dependencies including Flask inside the Python virtual environment.
56+
57+
```bash
58+
pip install -r requirements.txt
59+
```
60+
61+
Verify that Flask is installed successfully.
62+
63+
```bash
64+
pip list | grep Flask
65+
```
66+
67+
The output is similar to:
68+
69+
```output
70+
Flask 3.1.3
71+
```
72+
73+
## Create inference API
74+
In this step, you'll create a Flask-based API that loads the trained XGBoost model and exposes prediction endpoints over HTTP.
75+
76+
The `/` endpoint is used for browser validation, while the `/predict` endpoint handles prediction requests using JSON input data.
77+
78+
```bash
79+
cat > inference_api.py <<'EOF'
80+
from flask import Flask, request, jsonify
81+
import numpy as np
82+
import joblib
83+
84+
app = Flask(__name__)
85+
86+
model = joblib.load("xgboost-model.pkl")
87+
88+
@app.route("/", methods=["GET"])
89+
def home():
90+
return """
91+
<h1>XGBoost API Running on GCP Axion Arm64</h1>
92+
<p>Inference API Status : Active</p>
93+
<p>Use POST /predict endpoint for predictions.</p>
94+
"""
95+
96+
@app.route("/predict", methods=["POST"])
97+
def predict():
98+
99+
try:
100+
data = request.json["features"]
101+
102+
prediction = model.predict(np.array([data]))
103+
104+
return jsonify({
105+
"prediction": int(prediction[0])
106+
})
107+
108+
except Exception as e:
109+
return jsonify({
110+
"error": str(e)
111+
})
112+
113+
if __name__ == "__main__":
114+
app.run(host="0.0.0.0", port=8080)
115+
EOF
116+
```
117+
118+
## Start the inference API
119+
Start the Flask application so the API becomes accessible locally and externally through the VM public IP address.
120+
121+
```bash
122+
python inference_api.py
123+
```
124+
125+
The output is similar to:
126+
127+
```output
128+
* Running on all addresses (0.0.0.0)
129+
* Running on http://127.0.0.1:8080
130+
* Running on http://10.128.15.209:8080
131+
```
132+
133+
Leave this terminal running because the Flask server must remain active to handle incoming requests.
134+
135+
## Access API from browser
136+
The Flask API can now be accessed externally from your browser using the VM public IP and port `8080`.
137+
138+
Open:
139+
140+
```text
141+
http://<VM-PUBLIC-IP>:8080
142+
```
143+
144+
Example:
145+
146+
```text
147+
http://35.xxx.xxx.xxx:8080
148+
```
149+
150+
The output is similar to:
151+
152+
```output
153+
XGBoost Inference API is Running
154+
API Status: Active
155+
156+
This API is running on Google Cloud Axion Arm64.
157+
158+
Use the POST /predict endpoint to send prediction requests.
159+
```
160+
161+
The following screenshot shows the XGBoost inference API successfully running and accessible from the browser.
162+
163+
![Browser window showing the XGBoost Inference API homepage running on a Google Cloud Axion Arm64 virtual machine. The page confirms that the inference API is active and accessible externally through port 8080 using the VM public IP address.#center](images/xgboost-api.png "XGBoost inference API running on Google Cloud Axion Arm64")
164+
165+
## Test inference locally
166+
Open terminal B and activate the same Python virtual environment used for the API server.
167+
168+
```bash
169+
cd ~/xgboost-learning-path
170+
source xgb-env/bin/activate
171+
```
172+
173+
In this step, you'll send a prediction request to the XGBoost API using `curl`. The input data is passed as JSON to the `/predict` endpoint.
174+
175+
```bash
176+
curl -X POST http://127.0.0.1:8080/predict \
177+
-H "Content-Type: application/json" \
178+
-d '{"features":[17.99,10.38,122.8,1001.0,0.1184,0.2776,0.3001,0.1471,0.2419,0.07871,1.095,0.9053,8.589,153.4,0.006399,0.04904,0.05373,0.01587,0.03003,0.006193,25.38,17.33,184.6,2019.0,0.1622,0.6656,0.7119,0.2654,0.4601,0.1189]}'
179+
```
180+
181+
The output is similar to:
182+
183+
```output
184+
{"prediction":0}
185+
```
186+
This confirms that the trained XGBoost model successfully received the input features and generated an inference response through the REST API.
187+
188+
## What you've accomplished
189+
190+
You've successfully:
191+
192+
* Deployed XGBoost inference API on GCP Axion Arm64
193+
* Exposed the API externally
194+
* Accessed the API using the VM public IP
195+
* Performed inference using REST API requests
196+
* Validated real-time predictions using Flask and XGBoost
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: Configure Google Cloud firewall rules for XGBoost
3+
weight: 3
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Allow inbound access to the XGBoost inference API
10+
11+
Create a firewall rule in Google Cloud Console to expose the required port for the XGBoost inference API and browser-based access.
12+
13+
{{% notice Note %}} For help with GCP setup, see the Learning Path [Getting started with Google Cloud Platform](/learning-paths/servers-and-cloud-computing/csp/google/).{{% /notice %}}
14+
15+
## Configure the firewall rule in Google Cloud Console
16+
17+
To configure a firewall rule for the XGBoost inference API:
18+
19+
1. Navigate to the [Google Cloud Console](https://console.cloud.google.com/), go to **VPC Network > Firewall**, and select **Create firewall rule**.
20+
21+
![Google Cloud Console VPC Network Firewall page showing the Create firewall rule button in the top menu bar#center](images/firewall-rule.png "Create a firewall rule in Google Cloud Console")
22+
23+
2. Create a firewall rule that exposes the ports required for XGBoost.
24+
25+
3. Set **Name** to `allow-xgboost-8080`, then select the network you want to bind to your virtual machine.
26+
27+
4. Set **Direction of traffic** to **Ingress**, set **Action on match** to **Allow**, set **Targets** to **All instances in the network**, and set **Source IPv4 ranges** to **0.0.0.0/0**.
28+
29+
![Google Cloud Console Create firewall rule form with Name set to allow-xgboost-8080 and Direction of traffic set to Ingress#center](images/network-rule.png "Configuring the allow-xgboost-8080 firewall rule")
30+
31+
5. Under **Protocols and ports**, select **Specified protocols and ports**.
32+
6. Select the **TCP** checkbox and enter:
33+
34+
```text
35+
8080
36+
```
37+
38+
Port 8080 is used for:
39+
40+
* XGBoost inference API access
41+
* Browser-based API validation
42+
* External REST API requests
43+
* Remote inference testing from local systems
44+
45+
![Google Cloud Console Protocols and ports section with TCP selected and port 8080 entered#center](images/network-port.png "Setting XGBoost ports in the firewall rule")
46+
47+
7. Select **Create**.
48+
49+
## What you've accomplished and what's next
50+
51+
You've created a firewall rule to expose the XGBoost inference API externally. You also enabled browser access and remote API connectivity for inference testing.
52+
53+
Next, you'll create a Google Axion C4A Arm virtual machine and attach it to this firewall rule.
179 KB
Loading
23.5 KB
Loading
22.3 KB
Loading
261 KB
Loading
297 KB
Loading

0 commit comments

Comments
 (0)