python - Sagemaker 在训练期间不将 Tensorboard 日志输出到 S3

标签 python amazon-web-services tensorflow tensorboard amazon-sagemaker

我正在使用 Amazon Sagemaker 使用 Tensorflow 训练模型,我希望能够在作业运行时监控训练进度。然而,在训练期间,没有 Tensorboard 文件输出到 S3,只有在训练作业完成后,文件才会上传到 S3。训练完成后,我可以下载文件并看到 Tensorboard 在整个训练过程中一直正确记录值,尽管训练完成后仅在 S3 中更新一次。

我想知道为什么 Sagemaker 在整个训练过程中没有将 Tensorboard 信息上传到 S3?

这是我在 Sagemaker 上的笔记本中启动训练工作的代码

import sagemaker
from sagemaker.tensorflow import TensorFlow
from sagemaker.debugger import DebuggerHookConfig, CollectionConfig, TensorBoardOutputConfig

import time

bucket = 'my-bucket'
output_prefix = 'training-jobs'
model_name = 'my-model'
dataset_name = 'my-dataset'
dataset_path = f's3://{bucket}/datasets/{dataset_name}'

output_path = f's3://{bucket}/{output_prefix}'
job_name = f'{model_name}-{dataset_name}-training-{time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime())}'
s3_checkpoint_path = f"{output_path}/{job_name}/checkpoints" # Checkpoints are updated live as expected
s3_tensorboard_path = f"{output_path}/{job_name}/tensorboard" # Tensorboard data isn't appearing here until the training job has completed

tensorboard_output_config = TensorBoardOutputConfig(
    s3_output_path=s3_tensorboard_path,
    container_local_output_path= '/opt/ml/output/tensorboard' # I have confirmed this is the unaltered path being provided to tf.summary.create_file_writer()
)

role = sagemaker.get_execution_role()

estimator = TensorFlow(entry_point='main.py', source_dir='./', role=role, max_run=60*60*24*5,
                           output_path=output_path,
                           checkpoint_s3_uri=s3_checkpoint_path,
                           tensorboard_output_config=tensorboard_output_config,
                           instance_count=1, instance_type='ml.g4dn.xlarge',
                           framework_version='2.3.1', py_version='py37', script_mode=True)

dpe_estimator.fit({'train': dataset_path}, wait=True, job_name=job_name)

最佳答案

在 tensorflow github 上有一个 issue 与版本 2.3.1 中的 s3 客户端相关,这就是您正在使用的那个。如果您有类似这样的错误,请检查 cloudwatch 日志

OP_REQUIRES failed at whole_file_read_ops.cc:116 : Failed precondition: AWS Credentials have not been set properly. Unable to access the specified S3 location

那么提供的解决方案是给bucket添加GetObjectVersion权限。或者,要确认这是一个 tensorflow 问题,您可以尝试不同的版本。

关于python - Sagemaker 在训练期间不将 Tensorboard 日志输出到 S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65711587/

相关文章:

php - AWS Elastic BeanStalk php.ini 文件更新

amazon-web-services - 由于传输端点未连接,S3fs 抛出错误

regression - 理解 tf.keras 中线性回归模型调整的问题

python - 使用 Python 2.7 向 Excel 单元格添加注释

python - 如果我需要获取混合类型的列怎么办?

ruby-on-rails - 如何将 Postgres 数据库从一个 Elastic Beanstalk 环境复制到另一个 Elastic Beanstalk 环境?我正在使用 Rails 5

python - Tensorflow==2.0.0a0 - 属性错误 : module 'tensorflow' has no attribute 'global_variables_initializer'

android - 卡住 Android 的 tensor_forest 图

python - 根据 YAML 1.1 规范, 'yes' 真的是 'true' 的别名吗? 1.2规范?

python - 在Python中访问基类原始类型