使用 Vertex AI Experiments 手动记录指标

您可以通过 Vertex AI Experiments 运行作业手动记录 TensorBoard 时序指标。这些指标会在 Vertex AI Experiments 控制台或 Vertex AI TensorBoard 实验 Web 应用中直观呈现。

如需详细了解日志记录指标和参数,请参阅手动将数据记录到实验运行作业中

Python

from typing import Dict, Optional

from google.cloud import aiplatform
from google.protobuf import timestamp_pb2


def log_time_series_metrics_sample(
    experiment_name: str,
    run_name: str,
    metrics: Dict[str, float],
    step: Optional[int],
    wall_time: Optional[timestamp_pb2.Timestamp],
    project: str,
    location: str,
):
    aiplatform.init(experiment=experiment_name, project=project, location=location)

    aiplatform.start_run(run=run_name, resume=True)

    aiplatform.log_time_series_metrics(metrics=metrics, step=step, wall_time=wall_time)

  • experiment_name:提供实验的名称。
  • run_name:提供运行名称。
  • metrics:其中键为指标名称且值为指标值的字典。
  • step:可选。运行作业中此数据点的步骤索引。
  • wall_time:可选。最终用户生成此数据点时的实际时间戳。如果未提供,则系统会根据 time.time() 中的值生成 wall_time
  • project:您的项目 ID。 您可以在 Google Cloud 控制台的欢迎页面中找到这些 ID。
  • location:实验和 TensorBoard 实例的位置。如果实验或 TensorBoard 实例尚不存在,则系统会在该位置创建它们。