This tutorial provides a step-by-step guide for running supervised fine-tuning (SFT) on the Qwen3-14b model using MaxText on Cloud TPU. You'll learn how to build a specialized container image, provision a Google Kubernetes Engine (GKE) cluster with Pathways by using Accelerated Processing Kit (XPK), and execute a multi-host training workload.
Objectives
- Learn how to build a custom MaxText container image optimized for post-training.
- Provision a GKE cluster using XPK with Pathways enabled.
- Convert the Qwen3 14b model from Hugging Face format to MaxText format.
- Run a multi-host SFT training workload on Cloud TPU.
- Convert the fine-tuned model back to Hugging Face format for serving.
Costs
In this document, you use the following billable components of Google Cloud:
- Google Kubernetes Engine
- Cloud TPU
- Cloud Storage
- Artifact Registry
- Compute Engine, for the temporary build virtual machine (VM)
To generate a cost estimate based on your projected usage,
use the pricing calculator.
When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, see Clean up.
Before you begin
- Verify that your user account or service account has the following roles:
roles/compute.admin, to create the build VMroles/artifactregistry.admin, to manage the Docker repositoryroles/storage.admin, to manage the data bucketroles/container.admin, to create and manage the Google Kubernetes Engine clusterroles/iam.serviceAccountAdmin, to create the workload service accountroles/resourcemanager.projectIamAdmin, to set Identity and Access Management (IAM) policiesroles/iam.serviceAccountUser, to act as the service account
- Install and initialize the Google Cloud CLI.
- Verify that you've installed Python 3.12 or later on your workstation.
You need a Hugging Face access token to use this tutorial. You can sign up for a free account at Hugging Face. Once you have an account, generate an access token:
- On the Welcome to Hugging Face page, click your account avatar and select Access tokens.
- On the Access tokens page, click Create new token.
- Select the Read token type and enter a name for your token.
- Your access token is displayed. Save the token in a safe place.
Set up the environment
Set up your environment variables by running the following script:
Replace the following:
- YOUR_PROJECT_ID: your Google Cloud project ID
- YOUR_REGION: the region that you want to use
- YOUR_ZONE: the zone that you want to use
- YOUR_CLUSTER_NAME: a name for your Google Kubernetes Engine cluster
- YOUR_GCS_BUCKET: a unique name for your Cloud Storage bucket
- YOUR_RESERVATION_NAME: your capacity reservation
- YOUR_HF_TOKEN: your Hugging Face access token
Prepare your MaxText container image
To prepare your MaxText container image, including installing required dependencies, complete the following steps:
Create a Cloud Storage bucket:
Create an Artifact Registry repository:
Create a file in the root directory of your repository with the filename
cloudbuild.yamland the following contents:Use Cloud Build to build your MaxText Docker image:
Create your Google Kubernetes Engine cluster
To run SFT training on the Qwen3 14b model, you need a Google Kubernetes Engine cluster equipped with TPU chips. Install Accelerated Processing Kit (XPK) and create a GKE cluster with Pathways support.
Prepare the model for training
Convert the base model to MaxText format by using a CPU-based workload. Don't run this task on multiple machines in parallel. The following command includes a check to ensure that the conversion runs on only one TPU node.
Track the progress of the model conversion
To track the progress of the conversion, do the following:
- To list the pods scheduled on your GKE cluster, run the
command
kubectl get pod. - Find the pod named
qwen-hf-to-mt-slice-job-0-0-HASH. - To inspect the pod's output in real time, run the command
kubectl logs -f POD_NAME.
Start the training workload
After the conversion process has completed, you can start the SFT fine-tuning workload by using XPK.
Monitor the training workload
Monitor the status of your workload by using the XPK command-line interface (CLI).
xpk workload list --cluster ${CLUSTER_NAME} --project ${PROJECT} --zone ${ZONE}
To view logs and TPU utilization, use the Google Cloud console. You can also view logs by running the following command:
kubectl logs -f qwen-training-pathways-head-0-0-HASH
Replace HASH with the numeric hash in your pod's name. To
verify the value of this hash, run the command kubectl get pod and examine the
returned list of pods.
Convert the trained model back into Hugging Face format
After your training workload has completed, convert the checkpoints back to Hugging Face format.
To track the progress of the conversion, run the command
kubectl logs -f qwen-mt-to-hf-slice-job-0-0-HASH,
replacing HASH with the numeric hash in your pod's name.
After the conversion has completed, your tuned model stored in
gs://$GCS_BUCKET/qwen-3-14b/hf-trained/ is ready to be used.
Clean up
To avoid incurring additional charges, delete the resources created during this tutorial, including your Google Kubernetes Engine cluster, your Cloud Storage bucket, and your Artifact Registry repository.
To delete the resources that you created for this tutorial, run the following command:
What's next
- For more information about Cloud TPU, see Introduction to Cloud TPU.
- For architecture and configuration details for the
v6e-32TPU, see TPU v6e.