Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: Train and deploy XGBoost models on Google Cloud C4A Axion VM

draft: true
cascade:
draft: true

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.

minutes_to_complete: 30

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.

learning_objectives:
- Install and configure XGBoost on Google Cloud C4A Axion processors for Arm64
- Train and evaluate machine learning models using XGBoost
- Tune model hyperparameters and benchmark large-scale datasets
- Deploy trained XGBoost models as REST APIs and validate inference workflows

prerequisites:
- A [Google Cloud Platform (GCP)](https://cloud.google.com/free) account with billing enabled
- Basic familiarity with Python and machine learning concepts

author: Pareena Verma

##### Tags
skilllevels: Introductory
subjects: ML
cloud_service_providers:
- Google Cloud

armips:
- Neoverse

tools_software_languages:
- XGBoost
- Python
- scikit-learn
- Flask

operatingsystems:
- Linux

# ================================================================================
# FIXED, DO NOT MODIFY
# ================================================================================

further_reading:
- resource:
title: XGBoost official documentation
link: https://xgboost.readthedocs.io/en/stable/
type: documentation

- resource:
title: XGBoost GitHub repository
link: https://github.com/dmlc/xgboost
type: documentation

- resource:
title: Scikit-learn documentation
link: https://scikit-learn.org/stable/
type: documentation

- resource:
title: Flask documentation
link: https://flask.palletsprojects.com/
type: documentation

weight: 1
layout: "learningpathall"
learning_path_main_page: yes
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# ================================================================================
# FIXED, DO NOT MODIFY THIS FILE
# ================================================================================
weight: 21 # Set to always be larger than the content in this path to be at the end of the navigation.
title: "Next Steps" # Always the same, html page title.
layout: "learningpathall" # All files under learning paths have this same wrapper for Hugo processing.
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: Learn about XGBoost and Google Axion C4A for machine learning
weight: 2

layout: "learningpathall"
---

## Google Axion C4A Arm instances for machine learning

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.

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.

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).

## XGBoost for scalable machine learning on Arm

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.

XGBoost provides features such as:

* Parallelized tree boosting for fast model training
* Built-in regularization to reduce overfitting
* Hyperparameter tuning support for performance optimization
* Efficient handling of large-scale datasets
* Optimized CPU execution for multi-core systems
* Model export and deployment for inference workloads

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.

Common use cases include:

* Fraud detection
* Recommendation systems
* Customer churn prediction
* Financial forecasting
* Classification and regression workloads
* Large-scale tabular data training
* Real-time inference APIs

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.

To learn more, see the [XGBoost documentation](https://xgboost.readthedocs.io/en/stable/) and the [XGBoost GitHub repository](https://github.com/dmlc/xgboost).

## What you've learned and what's next

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.

Next, you'll install XGBoost and configure a Python 3.11 environment on a GCP Axion Arm64 VM for model training and benchmarking.
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
---
title: Deploy and access XGBoost inference API
weight: 8

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## Deploy XGBoost inference API on SUSE Linux

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.

You'll use:

**Terminal A** → API server

**Terminal B** → API testing

## Connect to the VM
Connect to the VM where the trained XGBoost model and Python environment were created. This VM will host the inference API service.

```bash
ssh <your-user>@<your-vm-ip>
```

Navigate to the XGBoost project directory that contains the trained model files and scripts.

```bash
cd ~/xgboost-learning-path
```

Activate the Python virtual environment to load all required Python packages and dependencies.

```bash
source xgb-env/bin/activate
```

## Install Flask
Flask is used to create the lightweight REST API that serves XGBoost predictions through HTTP requests.

Create an updated requirements file containing all required Python dependencies.

```bash
cat > requirements.txt <<'EOF'
xgboost
numpy
pandas
scikit-learn
matplotlib
joblib
flask
EOF
```

Install all dependencies including Flask inside the Python virtual environment.

```bash
pip install -r requirements.txt
```

Verify that Flask is installed successfully.

```bash
pip list | grep Flask
```

The output is similar to:

```output
Flask 3.1.3
```

## Create inference API
In this step, you'll create a Flask-based API that loads the trained XGBoost model and exposes prediction endpoints over HTTP.

The `/` endpoint is used for browser validation, while the `/predict` endpoint handles prediction requests using JSON input data.

```bash
cat > inference_api.py <<'EOF'
from flask import Flask, request, jsonify
import numpy as np
import joblib

app = Flask(__name__)

model = joblib.load("xgboost-model.pkl")

@app.route("/", methods=["GET"])
def home():
return """
<h1>XGBoost API Running on GCP Axion Arm64</h1>
<p>Inference API Status : Active</p>
<p>Use POST /predict endpoint for predictions.</p>
"""

@app.route("/predict", methods=["POST"])
def predict():

try:
data = request.json["features"]

prediction = model.predict(np.array([data]))

return jsonify({
"prediction": int(prediction[0])
})

except Exception as e:
return jsonify({
"error": str(e)
})

if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
EOF
```

## Start the inference API
Start the Flask application so the API becomes accessible locally and externally through the VM public IP address.

```bash
python inference_api.py
```

The output is similar to:

```output
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:8080
* Running on http://10.128.15.209:8080
```

Leave this terminal running because the Flask server must remain active to handle incoming requests.

## Access API from browser
The Flask API can now be accessed externally from your browser using the VM public IP and port `8080`.

Open:

```text
http://<VM-PUBLIC-IP>:8080
```

Example:

```text
http://35.xxx.xxx.xxx:8080
```

The output is similar to:

```output
XGBoost Inference API is Running
API Status: Active

This API is running on Google Cloud Axion Arm64.

Use the POST /predict endpoint to send prediction requests.
```

The following screenshot shows the XGBoost inference API successfully running and accessible from the browser.

![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")

## Test inference locally
Open terminal B and activate the same Python virtual environment used for the API server.

```bash
cd ~/xgboost-learning-path
source xgb-env/bin/activate
```

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.

```bash
curl -X POST http://127.0.0.1:8080/predict \
-H "Content-Type: application/json" \
-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]}'
```

The output is similar to:

```output
{"prediction":0}
```
This confirms that the trained XGBoost model successfully received the input features and generated an inference response through the REST API.

## What you've accomplished

You've successfully:

* Deployed XGBoost inference API on GCP Axion Arm64
* Exposed the API externally
* Accessed the API using the VM public IP
* Performed inference using REST API requests
* Validated real-time predictions using Flask and XGBoost
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Configure Google Cloud firewall rules for XGBoost
weight: 3

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## Allow inbound access to the XGBoost inference API

Create a firewall rule in Google Cloud Console to expose the required port for the XGBoost inference API and browser-based access.

{{% 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 %}}

## Configure the firewall rule in Google Cloud Console

To configure a firewall rule for the XGBoost inference API:

1. Navigate to the [Google Cloud Console](https://console.cloud.google.com/), go to **VPC Network > Firewall**, and select **Create firewall rule**.

![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")

2. Create a firewall rule that exposes the ports required for XGBoost.

3. Set **Name** to `allow-xgboost-8080`, then select the network you want to bind to your virtual machine.

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**.

![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")

5. Under **Protocols and ports**, select **Specified protocols and ports**.
6. Select the **TCP** checkbox and enter:

```text
8080
```

Port 8080 is used for:

* XGBoost inference API access
* Browser-based API validation
* External REST API requests
* Remote inference testing from local systems

![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")

7. Select **Create**.

## What you've accomplished and what's next

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.

Next, you'll create a Google Axion C4A Arm virtual machine and attach it to this firewall rule.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading