cloud-diagnostics-xprof
This repository contains 2 tools:
- xprofiler: Simplify profiling experience for XLA workloads!
Documentation below.
- mltrace: Visualize your Cloud logs and debug faster! Follow the
documentation at mltrace-README.md.
xprofiler
The xprofiler tool aims to simplify profiling experience for XLA workloads.
It provides an abstraction over profile sessions and manages
xprof hosting experience.
This includes allowing users to create and manage VM instances that
are preprovisioned with TensorBoard and latest profiling tools.
For more information about profiling with xprof, please see the xprof
documentation.
Quickstart
Xprofiler can be setup on user's workstation/cloudtop, on your TPU VM or Kubernetes.
Note:
Before setting up xprofiler, users will need to enable profile collection
for their workload by starting the profile server
(see section on enabling this collector)
or capturing programmatically
(see section on programmatic profile capture).
Install Dependencies
gcloud
xprofiler relies on using gcloud.
The first step is to follow the documentation to install.
Running the initial gcloud setup will ensure things like your default project
ID are set.
# setup project context
gcloud init
# setup auth for gcloud
gcloud auth login
# Setup auth for client libraries
gcloud auth application-default login
kubectl
Required only if xprofiler will be used in GKE mode. How to install kubectl
Setup cloud-diagnostic-xprof Package
Use a virtual environment (as best practice).
python3 -m venv venv
source venv/bin/activate
# Install package
pip install cloud-diagnostics-xprof
# Confirm installed with pip
pip show cloud-diagnostics-xprof
Name: cloud-diagnostics-xprof
Version: X.Y.Z
Summary: Abstraction over profile session locations and infrastructure running the analysis.
Home-page: https://github.com/AI-Hypercomputer/cloud-diagnostics-xprof
Author: Author-email: Hypercompute Diagon <hypercompute-diagon@google.com>
Permissions
xprofiler relies on project level IAM permissions.
- VM's service account must have required permissions.
<project-number>-compute@developer.gserviceaccount.com is the default
service account. Users can also use custom Service Accounts for their setup.
- Service Account must have
Storage Object User role on input GCS bucket.
This is needed to read/write profile traces to GCS.
- Users must have
Service Account User role on above service account. This is
needed to access reverse proxy URL link for visualization.
- Users must have
Storage Object User role on input GCS bucket. This is
needed to validate xprofiler instance state during setup.
Summary:
Users need to ensure when using xprofiler that it's in the same project as
their GCS bucket.
Users also need to ensure they put the required permissions for their GCS
bucket so the xprofiler VM can access the bucket.
Recommendations
GCS Paths
xprofiler uses a specific path pattern to locate and manage multiple profiling
sessions stored within a Google Cloud Storage (GCS) bucket. This enables the
visualization of various profiling sessions from different runs using a single
xprofiler instance.
GCS Paths for xprofiler create
It's recommended when using the xprofiler create subcommand to specify only
the root GCS bucket, without any subdirectories:
This approach allows xprofiler to discover and load profiles from multiple
runs and sessions stored under that bucket.
For instance, all the profile as organized below would be loaded in our example:
gs://<bucket-name>/run1/plugins/profile/session1/<profile.xplane.pb
gs://<bucket-name>/run1/plugins/profile/session2/<profile.xplane.pb
gs://<bucket-name>/run2/plugins/profile/session1/<profile.xplane.pb
Specifying gs://<bucket-name> during xprofiler create will allow users to
view all of these profiles in TensorBoard. They will see all runs in the
dropdown menu as run1/session1, run1/session2, and run2/session1.
GCS Paths for Profile Capture
When users programmatically capture profiles or use the xprofiler capture
subcommand with a GCS bucket path like gs://<bucket-name>/<run-name>, all
profiling data will be collected in a structured subdirectory:
gs://<bucket-name>/<run-name>/tensorboard/plugins/profile/<session-id>/
Users will see the run in the dropdown menu as
<run-name>/tensorboard/<session-id>/.
Here, the <session-id> uniquely identifies a specific profiling session within
that run.
Note:
As long as users have xplane files that follow the pattern
.../plugins/profile/<session> under the bucket path from
xprofiler create, all the profiles will be picked up in any subdirectories.
Examples of proper and improper GCS paths
Quick note on examples of proper and improper GCS paths (for log directory
parameter):
# Proper path (note forward slash at end is optional)
gs://my-bucket/main_directory/sub-a/sub-b/
# Proper path
gs://my_other_bucket/main_directory/sub-1/sub-2
# Improper path: does not start with gs://
my_other_bucket/main_directory/sub-1/sub-2
Machine Types
During creation, users have the option to specify the VM machine type.
The selection of a machine type can impact both performance and cost, and the
optimal choice often correlates with the size of the profiles users anticipate
working with.
By default, xprofiler utilizes the c4-highmem-8 machine type. This
configuration is generally robust and should provide sufficient resources for a
wide range of common profile sizes.
However, users may find it beneficial to select a different machine type based
on their specific needs:
- For workloads involving relatively small profiles (e.g., under approximately
100MB), a less powerful machine like
e2-highmem-4 might be a cost-effective
alternative without significantly compromising performance for those tasks.
- Conversely, users with particularly large profiles can opt for a more capable
machine (such as
c4-highmem-32) could lead to faster processing times.
- Although the default machine type should be sufficient for most users, if
users find it taking more than 3 minutes for profiles to load then they
may want to try a more powerful machine type for the
xprofiler VM.
The following table offers some general suggestions.
Please consider these as rough guidelines rather than strict prescriptions, as
the ideal machine type can depend on multiple factors specific to users'
profile data. Users may want to try more powerful machine types if it takes more
than 3 minutes to load.
| Profile Size |
Suggested Machine Type |
Primary Consideration |
| Small (< ~100 MB) |
e2-highmem-4 |
Cost-effectiveness |
| Medium / Typical |
c4-highmem-8 (Default) |
Balanced performance & cost |
| Large (> 1 GB) |
c4-highmem-32 |
Higher processing power |
While we generally recommend utilizing a
general-purpose machine type,
users are free to explore and specify other machine types that better suit their
requirements. A comprehensive list of machine types can be found in the
Google Cloud documentation.
For more information about specifying a machine type for xprofiler create,
please refer to the section below on
xprofiler create --machine-type.
Create xprofiler Instance
To create a xprofiler instance, you must provide a path to a GCS bucket and
zone. Project information will be retrieved from gcloud's config.
ZONE="<some zone>"
GCS_PATH="gs://<some-bucket>"
xprofiler create -z $ZONE -l $GCS_PATH
When the command completes, you will see it return information about the
instance created, similar to below:
Waiting for instance to be created. It can take a few minutes.
Instance for gs://<some-bucket> has been created.
You can access it via following,
1. https://<id>-dot-us-<region>.notebooks.googleusercontent.com.
2. xprofiler connect -z <some zone> -l gs://<some-bucket> -m ssh
Instance is hosted at xprof-97db0ee6-93f6-46d4-b4c4-6d024b34a99f VM.
Note: Depending on availability, the zone specified might not have the default
machine type for the VM. In that case, you instead might see an error followed
by potential zones that the machine type is available.
For more details, see section on machine
types when using xprofiler create.
This will create a VM instance with xprofiler packages installed. The setup
can take up to a few minutes. The link above is shareable with anyone with IAM
permissions.
By default, xprofiler instances will be hosted on a c4-highmem machine. Users
can also specify a machine type of their choice using the -m flag.
During create, users will be prompted if they would like to create a second
instance for the same GCS path. Pressing anything but Y or y will exit the
program.
$ xprofiler create -z <zone> -l gs://<some-bucket>
Instance for gs://<some-bucket> already exists.
Log_Directory URL Name Zone
------------------ ------------------------------------------------------------ ------------------------------------------ -------
gs://<some-bucket> https://<id>-dot-us-<region>.notebooks.googleusercontent.com xprof-97db0ee6-93f6-46d4-b4c4-6d024b34a99f <zone>
Do you want to continue to create another instance with the same log directory? (y/n)
y
Waiting for instance to be created. It can take a few minutes.
Instance for gs://<some-bucket> has been created.
You can access it via following,
1. https://<id>-dot-us-<region>.notebooks.googleusercontent.com.
2. xprofiler connect -z <zone> -l gs://<some-bucket> -m ssh
Instance is hosted at xprof-<uuid> VM.
Create Xprofiler - GKE
Setup
Prepare Cluster
xprofiler in GKE mode uses capacity provided by cluster. xprofiler auto
scale pods with Tensorboard but cluster is responsible to provide capacity
predefined or auto scaled as well.
Current xprofiler GKE setup does not post any memory constraints to pods but
required at least 1 cpu. Please select capacity with at least 16 gb of RAM
per cluster node.
Cluster to GCS Permissions
- If existing Nodes used validate that it has
Access Scope with Read Write
permissions for Storage
- If new will be created follow
https://screenshot.googleplex.com/3wuEqq7tUbKxPNP
Todo: b/433155299 In this guide we configure both Access Scope and IAM to
allow xprofiler access storage, in theory only second is required but it does
not work for all cases.
Create Namespace
Note: Assume kubectl configured with specific testing cluster
kubectl create namespace xprofiler
Create Service Account
Create Account:
kubectl --namespace=xprofiler create serviceaccount xprofiler
Create Service account on GCP:
# Define your project or use below to set to current project
PROJECT_ID=$(gcloud config get-value project)
echo "${PROJECT_ID}"
# Creates service account for xprofiler on project
gcloud iam service-accounts create xprofiler --project="${PROJECT_ID}"
Add GKE permissions: