Skip to content

feat: add GCP Vertex.AI hyperparameter tuning handler#3762

Draft
Aanushka001 wants to merge 2 commits into
pytorch:masterfrom
Aanushka001:gcp-vertex-unlock-handler
Draft

feat: add GCP Vertex.AI hyperparameter tuning handler#3762
Aanushka001 wants to merge 2 commits into
pytorch:masterfrom
Aanushka001:gcp-vertex-unlock-handler

Conversation

@Aanushka001
Copy link
Copy Markdown

Description

This PR adds a new event handler VertexAILogger that enables PyTorch Ignite training code to report metrics to GCP Vertex AI's hyperparameter tuning service.

Fixes #3023

What's included:

  • VertexAILogger - A BaseLogger subclass that writes metrics in the format expected by Vertex AI's hyperparameter tuning service. It reads the CLOUD_ML_HP_METRIC_FILE environment variable (default: /tmp/hypertune/output.metrics) and writes newline-delimited JSON metric entries, following the same protocol as the official cloudml-hypertune library.
  • OutputHandler - Helper handler to log engine output/metrics via report_hyperparameter_tuning_metric().
  • OptimizerParamsHandler - Helper handler to log optimizer parameters (e.g., learning rate).

Usage example

from ignite.handlers.gcp_vertex_logger import VertexAILogger
from ignite.engine import Events

vertex_logger = VertexAILogger()

# Report accuracy after each epoch
vertex_logger.attach_output_handler(
    trainer,
    event_name=Events.EPOCH_COMPLETED,
    tag="training",
    metric_names=["accuracy"],
    global_step_transform=lambda engine, event_name: engine.state.epoch,
)

# Report at the end of training
vertex_logger.attach_output_handler(
    trainer,
    event_name=Events.COMPLETED,
    tag="training",
    metric_names=["accuracy"],
    global_step_transform=lambda engine, event_name: engine.state.epoch,
)

How it works

Vertex AI hyperparameter tuning works by reading metric values from a file at the path specified by the CLOUD_ML_HP_METRIC_FILE environment variable. This handler writes the metrics in the correct newline-delimited JSON format, allowing Vertex AI to evaluate trial performance. No external dependencies are required.

Checklist

  • Handler follows the existing BaseLogger pattern (like WandBLogger, MLflowLogger)
  • Exported via ignite/handlers/__init__.py
  • Full type hints and docstrings
  • No new external dependencies

@github-actions github-actions Bot added the module: handlers Core Handlers module label May 31, 2026
@vfdev-5 vfdev-5 marked this pull request as draft May 31, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: handlers Core Handlers module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Event handler to "unlock" GCPs Vertex.AI hyperparameter tuning service

1 participant