Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Inferensi MaxDiffusion di TPU v6e
Tutorial ini menunjukkan cara menayangkan model MaxDiffusion di TPU v6e. Dalam tutorial
ini, Anda akan membuat gambar menggunakan model Stable Diffusion XL.
Sebelum memulai
Bersiap untuk menyediakan TPU v6e dengan 4 chip:
Ikuti panduan Menyiapkan lingkungan Cloud TPU untuk menyiapkan Google Cloud project, mengonfigurasi Google Cloud CLI, mengaktifkan Cloud TPU API, dan memastikan Anda memiliki akses untuk menggunakan Cloud TPU.
Lakukan autentikasi dengan Google Cloud dan konfigurasikan project dan zona default untuk Google Cloud CLI.
Jika Anda siap untuk mengamankan kapasitas TPU, lihat Kuota Cloud TPU untuk mengetahui informasi selengkapnya tentang kuota Cloud TPU. Jika ada pertanyaan tambahan tentang cara mendapatkan kapasitas, hubungi tim akun atau tim penjualan Cloud TPU Anda.
Pastikan project Anda memiliki kuota TPUS_PER_TPU_FAMILY yang cukup,
yang menentukan jumlah maksimum chip yang dapat Anda akses dalam
projectGoogle Cloud .
Pastikan project Anda memiliki cukup kuota TPU untuk:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-18 UTC."],[],[],null,["# MaxDiffusion inference on v6e TPUs\n==================================\n\nThis tutorial shows how to serve MaxDiffusion models on TPU v6e. In this\ntutorial, you generate images using the Stable Diffusion XL model.\n| **Note:** After you complete the inference benchmark, be sure to [clean up](#clean-up) the TPU resources.\n\nBefore you begin\n----------------\n\nPrepare to provision a TPU v6e with 4 chips:\n\n1. Follow [Set up the Cloud TPU environment](/tpu/docs/setup-gcp-account)\n guide to set up a Google Cloud project, configure the Google Cloud CLI,\n enable the Cloud TPU API, and ensure you have access to use\n Cloud TPUs.\n\n2. Authenticate with Google Cloud and configure the default project and\n zone for Google Cloud CLI.\n\n ```bash\n gcloud auth login\n gcloud config set project PROJECT_ID\n gcloud config set compute/zone ZONE\n ```\n\n### Secure capacity\n\nWhen you are ready to secure TPU capacity, see [Cloud TPU\nQuotas](/tpu/docs/quota) for more information about the Cloud TPU quotas. If\nyou have additional questions about securing capacity, contact your Cloud TPU\nsales or account team.\n\n### Provision the Cloud TPU environment\n\nYou can provision TPU VMs with\n[GKE](/tpu/docs/tpus-in-gke), with GKE and\n[XPK](https://github.com/google/xpk/tree/main),\nor as [queued resources](/tpu/docs/queued-resources).\n| **Note:** This document describes how to provision TPUs using queued resources. If you are provisioning your TPUs using [XPK](https://github.com/AI-Hypercomputer/xpk/blob/main/README.md) (a wrapper CLI tool over GKE), set up XPK permissions on your user account for GKE.\n\n### Prerequisites\n\n| **Note:** This tutorial has been tested with Python 3.10 or later.\n\n- Verify that your project has enough `TPUS_PER_TPU_FAMILY` quota, which specifies the maximum number of chips you can access within your Google Cloud project.\n- Verify that your project has enough TPU quota for:\n - TPU VM quota\n - IP address quota\n - Hyperdisk Balanced quota\n- User project permissions\n - If you are using GKE with XPK, see [Cloud Console Permissions on\n the user or service account](https://github.com/AI-Hypercomputer/xpk/blob/main/README.md#cloud-console-permissions-on-the-user-or-service-account-needed-to-run-xpk) for the permissions needed to run XPK.\n\nProvision a TPU v6e\n-------------------\n\n```bash\n gcloud alpha compute tpus queued-resources create QUEUED_RESOURCE_ID \\\n --node-id TPU_NAME \\\n --project PROJECT_ID \\\n --zone ZONE \\\n --accelerator-type v6e-4 \\\n --runtime-version v2-alpha-tpuv6e \\\n --service-account SERVICE_ACCOUNT\n```\n\nUse the `list` or `describe` commands\nto query the status of your queued resource. \n\n```bash\n gcloud alpha compute tpus queued-resources describe QUEUED_RESOURCE_ID \\\n --project=PROJECT_ID --zone=ZONE\n```\n\nFor a complete list of queued resource request statuses, see the\n[Queued Resources](/tpu/docs/queued-resources) documentation.\n\nConnect to the TPU using SSH\n----------------------------\n\n```bash\n gcloud compute tpus tpu-vm ssh TPU_NAME\n```\n\nCreate a Conda environment\n--------------------------\n\n1. Create a directory for Miniconda:\n\n ```bash\n mkdir -p ~/miniconda3\n ```\n2. Download the Miniconda installer script:\n\n ```bash\n wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh\n ```\n3. Install Miniconda:\n\n ```bash\n bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3\n ```\n4. Remove the Miniconda installer script:\n\n ```bash\n rm -rf ~/miniconda3/miniconda.sh\n ```\n5. Add Miniconda to your `PATH` variable:\n\n ```bash\n export PATH=\"$HOME/miniconda3/bin:$PATH\"\n ```\n6. Reload `~/.bashrc` to apply the changes to the `PATH` variable:\n\n ```bash\n source ~/.bashrc\n ```\n7. Create a new Conda environment:\n\n ```bash\n conda create -n tpu python=3.10\n ```\n8. Activate the Conda environment:\n\n ```bash\n source activate tpu\n ```\n\nSet up MaxDiffusion\n-------------------\n\n1. Clone the MaxDiffusion GitHub repository and navigate to the MaxDiffusion directory:\n\n ```bash\n git clone https://github.com/google/maxdiffusion.git && cd maxdiffusion\n ```\n2. Switch to the `mlperf-4.1` branch:\n\n ```bash\n git checkout mlperf4.1\n ```\n3. Install MaxDiffusion:\n\n ```bash\n pip install -e .\n ```\n4. Install dependencies:\n\n ```bash\n pip install -r requirements.txt\n ```\n5. Install JAX:\n\n ```bash\n pip install jax[tpu]==0.4.34 jaxlib==0.4.34 ml-dtypes==0.2.0 -i https://us-python.pkg.dev/ml-oss-artifacts-published/jax/simple/ -f https://storage.googleapis.com/jax-releases/libtpu_releases.html\n ```\n6. Install additional dependencies:\n\n ```bash\n pip install huggingface_hub==0.25 absl-py flax tensorboardX google-cloud-storage torch tensorflow transformers \n ```\n\nGenerate images\n---------------\n\n1. Set environment variables to configure the TPU runtime:\n\n ```bash\n LIBTPU_INIT_ARGS=\"--xla_tpu_rwb_fusion=false --xla_tpu_dot_dot_fusion_duplicated=true --xla_tpu_scoped_vmem_limit_kib=65536\"\n ```\n2. Generate images using the prompt and configurations defined in\n [`src/maxdiffusion/configs/base_xl.yml`](https://github.com/AI-Hypercomputer/maxdiffusion/blob/main/src/maxdiffusion/configs/base_xl.yml):\n\n ```bash\n python -m src.maxdiffusion.generate_sdxl src/maxdiffusion/configs/base_xl.yml run_name=\"my_run\"\n ```\n\n When the images have been generated, be sure to [clean up](#clean-up)\n the TPU resources.\n\nClean up\n--------\n\nDelete the TPU: \n\n```bash\ngcloud compute tpus queued-resources delete QUEUED_RESOURCE_ID \\\n --project PROJECT_ID \\\n --zone ZONE \\\n --force \\\n --async\n```"]]