Skip to content

Discover TPU logs in Ray Dashboard - #47737

Merged
edoakes merged 9 commits into
ray-project:masterfrom
ryanaoleary:tpu-logs
Mar 6, 2025
Merged

edoakes merged 9 commits into
ray-project:masterfrom
ryanaoleary:tpu-logs

Conversation

@ryanaoleary

Copy link
Copy Markdown
Contributor

Why are these changes needed?

TPU device logs for k8s containers that request google.com/tpu resources are written to the /tmp/tpu_logs directory. This PR adds a symlink to the /tmp/tpu_logs directory when the TPU_WORKER_ID env var is set, TPU log files are then added to monitor_log_paths. The logs are then viewable from the Ray Dashboard:

Create a file in /tmp/tpu_logs and view symlink:
command-line-logging

The tpu_logs directory is added to the 'Logs' tab on a TPU Ray worker:
tpu_logs_dir

The log file we created is ingested/viewable:
tpu-device-log-file

Related issue number

Checks

Signed-off-by: Ryan O'Leary <[email protected]>
@ryanaoleary

Copy link
Copy Markdown
Contributor Author

cc: @andrewsykim @kevin85421

@kevin85421 kevin85421 self-assigned this Sep 18, 2024
@ryanaoleary

Copy link
Copy Markdown
Contributor Author

These are what actual log files when running a Serve application on TPUs look like:

actual-tpu-logs

@ryanaoleary

Copy link
Copy Markdown
Contributor Author

@kevin85421 can we include this in the next release if possible?

@stale

stale Bot commented Feb 24, 2025

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

  • If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@stale stale Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Feb 24, 2025
@stale stale Bot removed the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Feb 24, 2025
@ryanaoleary

Copy link
Copy Markdown
Contributor Author

@kevin85421 This PR would be helpful to add since TPU logs currently aren't discoverable from the Ray dashboard, making it necessary for users to exec into the Pod containers to view relevant logs to their workloads.

Comment thread python/ray/_private/log_monitor.py Resolved
Comment thread python/ray/_private/log_monitor.py Resolved
Comment thread python/ray/_private/log_monitor.py Resolved
Comment thread python/ray/_private/node.py Resolved
@ryanaoleary

Copy link
Copy Markdown
Contributor Author

@kevin85421 I fixed the first round of comments and re-tested it with the unit test and by manually deploying in my cluster. We now check for the TPU logs directory before creating a symlink and adding it to the monitor path.

Comment thread python/ray/_private/node.py Resolved
Comment thread python/ray/_private/node.py Outdated
try_to_create_directory(self._runtime_env_dir)
# Create a symlink to the libtpu tpu_logs directory if it exists.
user_temp_dir = ray._private.utils.get_user_temp_dir()
tpu_log_dir = os.environ.get("TPU_LOG_DIR", f"{user_temp_dir}/tpu_logs")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is {user_temp_dir}/tpu_logs created? Is it guaranteed to exist before this function is called?

@ryanaoleary ryanaoleary Feb 26, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my manual testing /tmp/tpu_logs existed when the Ray node initialized so I think it's beforehand, but I'm not sure how to check if it's guaranteed. The directory contains libtpu logs, so I believe it's created when libtpu is installed in the container.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any update on this?

@ryanaoleary ryanaoleary Mar 4, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran some manual tests, I created a RayCluster with the following manifest:

apiVersion: ray.io/v1
kind: RayCluster
metadata:
  name: raycluster-tpu-v4-singlehost
spec:
  headGroupSpec:
    rayStartParams: {}
    template:
      spec:
        containers:
          - name: ray-head
            image: us-central1-docker.pkg.dev/ryanaoleary-gke-dev/ryanaoleary-ray/tpu-logs:latest
            imagePullPolicy: IfNotPresent
            resources:
              limits:
                cpu: "500m"
                memory: "512Mi"
              requests:
                cpu: "500m"
                memory: "512Mi"
            env:
              - name: RAY_memory_monitor_refresh_ms
                value: "0"
              - name: RAY_GRAFANA_IFRAME_HOST
                value: http://${grafana_host}
              - name: RAY_GRAFANA_HOST
                value: http://grafana:80
              - name: RAY_PROMETHEUS_HOST
                value: http://frontend:9090
            ports:
              - containerPort: 6379
                name: gcs
              - containerPort: 8265
                name: dashboard
              - containerPort: 10001
                name: client
              - containerPort: 8000
                name: serve
  workerGroupSpecs:
  - rayStartParams: {}
    replicas: 1
    minReplicas: 1
    maxReplicas: 1
    numOfHosts: 1
    groupName: tpu-group
    template:
      spec:
        initContainers:
          - name: check-folder
            image: busybox
            command:
              - /bin/sh
              - -c
              - 'if [ -d "/tmp/tpu_logs" ]; then echo "Folder exists"; else echo "Folder does not exist"; fi'
        containers:
          - name: ray-worker
            image: us-central1-docker.pkg.dev/ryanaoleary-gke-dev/ryanaoleary-ray/tpu-logs:latest
            imagePullPolicy: IfNotPresent
            resources:
              limits:
                cpu: "1"
                ephemeral-storage: 20Gi
                google.com/tpu: "4"
                memory: 40G
              requests:
                cpu: "1"
                ephemeral-storage: 10Gi
                google.com/tpu: "4"
                memory: 40G
        nodeSelector:
          cloud.google.com/gke-tpu-accelerator: tpu-v4-podslice
          cloud.google.com/gke-tpu-topology: 2x2x1

when I check the logs of check-folder, I can see that the /tmp/tpu_logs folder is not present in the initContainer:

kubectl logs raycluster-tpu-v4-singlehost-tpu-group-worker-cdwkg -c check-folder
Folder does not exist

This makes sense since the TPU node hasn't started initializing, which is when it starts making calls to libtpu and writing logs. I'm not sure if this is an issue though, the folder is only added in _init_temp if the path exists (so it won't cause an error) and from manually tests it's consistently showing up in the dashboard - so the libtpu calls must be occurring immediately when the Ray container is created.

@kevin85421 kevin85421 Mar 5, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, we can delegate the responsibility to users to ensure that /tmp/tpu_logs is created before running ray start.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to add documentation for it. It's not necessary to include it in this PR, but it would be helpful to document it. Would you mind opening an issue to track the progress?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, here's the issue: #51102

@kevin85421 kevin85421 added the go add ONLY when ready to merge, run all tests label Mar 5, 2025

@kevin85421 kevin85421 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@edoakes edoakes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@edoakes
edoakes merged commit c953682 into ray-project:master Mar 6, 2025
park12sj pushed a commit to park12sj/ray that referenced this pull request Mar 18, 2025
TPU device logs for k8s containers that request `google.com/tpu`
resources are written to the `/tmp/tpu_logs` directory. This PR adds a
symlink to the `/tmp/tpu_logs` directory when the `TPU_WORKER_ID` env
var is set, TPU log files are then added to `monitor_log_paths`. The
logs are then viewable from the Ray Dashboard:

Create a file in /tmp/tpu_logs and view symlink:

![command-line-logging](https://github.com/user-attachments/assets/c50915ad-8382-4af7-a398-40d5a249e8c8)

The tpu_logs directory is added to the 'Logs' tab on a TPU Ray worker:

![tpu_logs_dir](https://github.com/user-attachments/assets/394133b0-be70-4b98-9e86-dcad50c1b4fd)

The log file we created is ingested/viewable:

![tpu-device-log-file](https://github.com/user-attachments/assets/c42ab96a-f88b-4959-adf2-8650fd75c773)

---------

Signed-off-by: Ryan O'Leary <[email protected]>
Co-authored-by: Kai-Hsun Chen <[email protected]>
dhakshin32 pushed a commit to dhakshin32/ray that referenced this pull request Mar 27, 2025
TPU device logs for k8s containers that request `google.com/tpu`
resources are written to the `/tmp/tpu_logs` directory. This PR adds a
symlink to the `/tmp/tpu_logs` directory when the `TPU_WORKER_ID` env
var is set, TPU log files are then added to `monitor_log_paths`. The
logs are then viewable from the Ray Dashboard:

Create a file in /tmp/tpu_logs and view symlink:

![command-line-logging](https://github.com/user-attachments/assets/c50915ad-8382-4af7-a398-40d5a249e8c8)

The tpu_logs directory is added to the 'Logs' tab on a TPU Ray worker:

![tpu_logs_dir](https://github.com/user-attachments/assets/394133b0-be70-4b98-9e86-dcad50c1b4fd)

The log file we created is ingested/viewable:

![tpu-device-log-file](https://github.com/user-attachments/assets/c42ab96a-f88b-4959-adf2-8650fd75c773)

---------

Signed-off-by: Ryan O'Leary <[email protected]>
Co-authored-by: Kai-Hsun Chen <[email protected]>
Signed-off-by: Dhakshin Suriakannu <[email protected]>
dstrodtman added a commit that referenced this pull request Oct 26, 2026
## Description

A batch of 15 small docs fixes. Most close an open docs issue, listed
under Related issues. Each fix is its own commit, so a reviewer can drop
any one without touching the rest. Batching follows the "No low-value
busywork PRs" rule in `AGENTS.md`, which allows mechanical fixes when
they're bundled.

The changes are prose and one notebook install cell, all under `doc/`.
Each fix was checked against the current source on master.

| Area | Change | Source checked |
|---|---|---|
| Core | The memory-aware scheduling examples said 2.5 GiB and 1 GiB but
computed 2500 MiB and 1000 MiB. The examples now use exact binary
multiples, and the text says `memory` is in bytes. | `ray.remote`
docstring in `_private/worker.py` (memory request in bytes) |
| Cluster | Link the cluster application guide to the Ray Serve
development and deployment guides. | Existing `serve-dev-workflow`,
`serve-in-production-deploying`, and `serve-in-production-kubernetes`
labels |
| Train | Link the Lightning getting-started guide to the PyTorch data
loading comparison. | `train-datasets-pytorch` section |
| Tune | Pin the hidden install cell of `ax-example.ipynb` to
`ax-platform==1.2.1`, the version in `tune-requirements.txt`, and drop
the cell's stale pip output. #60522 moved `AxSearch` to the Ax 1.0 API.
| `python/requirements/ml/tune-requirements.txt`, `ax_search.py` |
| Train | The fault-tolerance deprecation section called the deprecated
argument `restore_from_checkpoint`. The trainer parameter is
`resume_from_checkpoint`. |
`python/ray/train/v2/api/data_parallel_trainer.py` |
| Tune | The BayesOpt example pinned `bayesian-optimization==1.2.0`,
which uses `np.float` and fails in `tuner.fit()` on current NumPy. Pin
1.4.0, the version in `python/requirements_compiled.txt`. Executing the
notebook with `jupyter nbconvert --execute` on Ray 2.59.0 and NumPy
2.4.6 runs clean with 1.4.0 and reproduces `AttributeError: module
'numpy' has no attribute 'float'` with 1.2.0. |
`python/requirements_compiled.txt` |
| Cluster | Add a manual-configuration tab with SSH port forwarding to
the dashboard access section. | `ray start --dashboard-port`, default
8265 |
| Cluster | Document `RAY_OVERRIDE_DASHBOARD_URL` for reverse proxies. |
`ray_constants.py`, `worker.py` (`get_dashboard_url` and the connect
log) |
| Serve | Note that KubeRay creates `<name>-head-svc` and
`<name>-serve-svc` only after every Serve application is `RUNNING`. |
KubeRay `rayservice_controller.go` (`reconcileServe`,
`getAndCheckServeStatus`) |
| Cluster | Replace the hardcoded Homebrew Grafana path with `$(brew
--prefix)/etc/grafana/grafana.ini`. | The Homebrew `grafana` formula's
service passes `--config etc/grafana/grafana.ini` |
| Cluster | A node type's `worker_setup_commands` replaces both the
general `setup_commands` and `worker_setup_commands`. It doesn't replace
only the latter. | `merge_setup_commands` in
`autoscaler/_private/util.py`, `_get_node_type_specific_fields` in
`autoscaler.py`, `ray-schema.json` |
| Cluster | Add next-steps links to log and metrics persistence on the
VM and KubeRay quickstarts. | Existing persistence guides |
| Cluster | Add a port requirements section to the manual on-premises
setup that links the ports reference. | `core/configure.md` ports
reference |
| Data | Rename the `S3` and `GCS` cloud storage tabs to `Amazon S3` and
`Google Cloud Storage`. In Ray docs, GCS means the Global Control
Service. | `writing-style.md` term table |
| KubeRay | Document where `libtpu` logs appear (`tpu_logs` in the node
log directory and the dashboard Logs view). Link to it from the Logs
view section. | `_private/node.py` (`_init_temp`),
`_private/log_monitor.py`, #47737 |

## Related issues

Closes #42681
Closes #38545
Closes #48024
Closes #54968
Closes #37804
Closes #46794
Closes #50958
Closes #42430
Closes #37831
Closes #37631
Closes #24491
Closes #51102

## Not a duplicate

For each linked issue, `gh pr list --repo ray-project/ray --state open
--search "<issue> in:body"` returned no open PRs. A content search
turned up three open PRs that edit the same pages: #66289 (OCI
provider), #66958 (Grafana annotations), and #66920 (NPU observability).
They touch different hunks and don't overlap these changes. The data tab
rename has no linked issue, and no open PR touches those tabs.

## Testing

- `make -C doc rtd-build` (the RtD-faithful clean build: Python 3.11,
`doc/requirements-doc.lock.txt`, `-W --keep-going`): `build succeeded.`
with exit code 0 and zero Sphinx warnings. The only `WARNING` lines are
two RLlib logger messages printed at import time.
- Vale, run on the changed pages and limited to the added lines: no
findings remain beyond spelling hits on `proxied` (the page already uses
it) and `libtpu`, which is now in backticks.
- Pre-commit hooks passed on every commit.
- Every `{ref}` target added in this PR resolves to exactly one label
under `doc/source/`.
- I didn't execute the Ax notebook. Its only change is the hidden
install cell. CI already tests the Ax integration at
`ax-platform==1.2.1` through `python/ray/tune/examples/ax_example.py`.

## AI assistance

Drafted with AI assistance (Claude Code). Each technical claim was
checked against the source cited in the table.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
justinyeh1995 pushed a commit to justinyeh1995/ray that referenced this pull request Oct 28, 2026
## Description

A batch of 15 small docs fixes. Most close an open docs issue, listed
under Related issues. Each fix is its own commit, so a reviewer can drop
any one without touching the rest. Batching follows the "No low-value
busywork PRs" rule in `AGENTS.md`, which allows mechanical fixes when
they're bundled.

The changes are prose and one notebook install cell, all under `doc/`.
Each fix was checked against the current source on master.

| Area | Change | Source checked |
|---|---|---|
| Core | The memory-aware scheduling examples said 2.5 GiB and 1 GiB but
computed 2500 MiB and 1000 MiB. The examples now use exact binary
multiples, and the text says `memory` is in bytes. | `ray.remote`
docstring in `_private/worker.py` (memory request in bytes) |
| Cluster | Link the cluster application guide to the Ray Serve
development and deployment guides. | Existing `serve-dev-workflow`,
`serve-in-production-deploying`, and `serve-in-production-kubernetes`
labels |
| Train | Link the Lightning getting-started guide to the PyTorch data
loading comparison. | `train-datasets-pytorch` section |
| Tune | Pin the hidden install cell of `ax-example.ipynb` to
`ax-platform==1.2.1`, the version in `tune-requirements.txt`, and drop
the cell's stale pip output. ray-project#60522 moved `AxSearch` to the Ax 1.0 API.
| `python/requirements/ml/tune-requirements.txt`, `ax_search.py` |
| Train | The fault-tolerance deprecation section called the deprecated
argument `restore_from_checkpoint`. The trainer parameter is
`resume_from_checkpoint`. |
`python/ray/train/v2/api/data_parallel_trainer.py` |
| Tune | The BayesOpt example pinned `bayesian-optimization==1.2.0`,
which uses `np.float` and fails in `tuner.fit()` on current NumPy. Pin
1.4.0, the version in `python/requirements_compiled.txt`. Executing the
notebook with `jupyter nbconvert --execute` on Ray 2.59.0 and NumPy
2.4.6 runs clean with 1.4.0 and reproduces `AttributeError: module
'numpy' has no attribute 'float'` with 1.2.0. |
`python/requirements_compiled.txt` |
| Cluster | Add a manual-configuration tab with SSH port forwarding to
the dashboard access section. | `ray start --dashboard-port`, default
8265 |
| Cluster | Document `RAY_OVERRIDE_DASHBOARD_URL` for reverse proxies. |
`ray_constants.py`, `worker.py` (`get_dashboard_url` and the connect
log) |
| Serve | Note that KubeRay creates `<name>-head-svc` and
`<name>-serve-svc` only after every Serve application is `RUNNING`. |
KubeRay `rayservice_controller.go` (`reconcileServe`,
`getAndCheckServeStatus`) |
| Cluster | Replace the hardcoded Homebrew Grafana path with `$(brew
--prefix)/etc/grafana/grafana.ini`. | The Homebrew `grafana` formula's
service passes `--config etc/grafana/grafana.ini` |
| Cluster | A node type's `worker_setup_commands` replaces both the
general `setup_commands` and `worker_setup_commands`. It doesn't replace
only the latter. | `merge_setup_commands` in
`autoscaler/_private/util.py`, `_get_node_type_specific_fields` in
`autoscaler.py`, `ray-schema.json` |
| Cluster | Add next-steps links to log and metrics persistence on the
VM and KubeRay quickstarts. | Existing persistence guides |
| Cluster | Add a port requirements section to the manual on-premises
setup that links the ports reference. | `core/configure.md` ports
reference |
| Data | Rename the `S3` and `GCS` cloud storage tabs to `Amazon S3` and
`Google Cloud Storage`. In Ray docs, GCS means the Global Control
Service. | `writing-style.md` term table |
| KubeRay | Document where `libtpu` logs appear (`tpu_logs` in the node
log directory and the dashboard Logs view). Link to it from the Logs
view section. | `_private/node.py` (`_init_temp`),
`_private/log_monitor.py`, ray-project#47737 |

## Related issues

Closes ray-project#42681
Closes ray-project#38545
Closes ray-project#48024
Closes ray-project#54968
Closes ray-project#37804
Closes ray-project#46794
Closes ray-project#50958
Closes ray-project#42430
Closes ray-project#37831
Closes ray-project#37631
Closes ray-project#24491
Closes ray-project#51102

## Not a duplicate

For each linked issue, `gh pr list --repo ray-project/ray --state open
--search "<issue> in:body"` returned no open PRs. A content search
turned up three open PRs that edit the same pages: ray-project#66289 (OCI
provider), ray-project#66958 (Grafana annotations), and ray-project#66920 (NPU observability).
They touch different hunks and don't overlap these changes. The data tab
rename has no linked issue, and no open PR touches those tabs.

## Testing

- `make -C doc rtd-build` (the RtD-faithful clean build: Python 3.11,
`doc/requirements-doc.lock.txt`, `-W --keep-going`): `build succeeded.`
with exit code 0 and zero Sphinx warnings. The only `WARNING` lines are
two RLlib logger messages printed at import time.
- Vale, run on the changed pages and limited to the added lines: no
findings remain beyond spelling hits on `proxied` (the page already uses
it) and `libtpu`, which is now in backticks.
- Pre-commit hooks passed on every commit.
- Every `{ref}` target added in this PR resolves to exactly one label
under `doc/source/`.
- I didn't execute the Ax notebook. Its only change is the hidden
install cell. CI already tests the Ax integration at
`ax-platform==1.2.1` through `python/ray/tune/examples/ax_example.py`.

## AI assistance

Drafted with AI assistance (Claude Code). Each technical claim was
checked against the source cited in the table.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants