pytorch - 在 SageMaker 的训练脚本中调用 PyTorch Estimator 超参数
问题描述
在 [PyTorch Estimator for SageMaker][1] 中,它说如下。
hyperparameters (dict) -- 将用于训练的超参数(默认值:无)。超参数可作为 dict[str, str] 访问 SageMaker 上的训练代码。为方便起见,它接受其他类型的键和值,但在训练之前会调用 str() 来转换它们。
estimator = PyTorch(entry_point='test_trainer.py',
source_dir = 'code',
role = role,
framework_version = '1.5.0',
py_version = 'py3',
instance_count = 1,
instance_type = 'ml.g4dn.2xlarge',
hyperparameters={"epochs": 1,
"num_labels": 2,
"backend": "gloo"
}}
所以,如果我如上所述声明我的估计器并通过我的 test_trainer.py 拟合估计器,我应该能够在我的 test_trainer.py 中访问这些超参数值。但是我应该如何调用这个超参数才能访问这些超参数值?
任何资源将不胜感激。[1]:https ://sagemaker.readthedocs.io/en/stable/frameworks/pytorch/sagemaker.pytorch.html
解决方案
SM_HPS='{"batch-size": "256", "learning-rate": "0.0001","communicator": "pure_nccl"}'
Contains a JSON encoded dictionary with the user provided hyperparameters. Example usage:
import os
import json
hyperparameters = json.loads(os.environ['SM_HPS']))
# {"batch-size": 256, "learning-rate": 0.0001, "communicator": "pure_nccl"}
推荐阅读
- python - Keras ImageDataGenerator + imgaug
- autokey - 哪个库用于在 linux python 中读取窗口标题
- bash - Shell 脚本 - 如何将脚本导出为字符串?
- javascript - 如何使用纯 JS 导入 2 个或更多 Angular 组件?
- python - 如何从 AHK 脚本中调用 python 函数?
- python - grpclib 如何管理 not recv 消息
- ruby - 如何将特定值传递给 Ruby 中池的每个线程?
- python - 为雷达数据的 x 轴添加时间刻度
- c# - 我无法修复“错误 CS1514:{ 预期的”
- angularjs - 在 IONIC 中使用谷歌 API 比较多个地址时如何获取关闭地址