本文整理汇总了Python中timeout.timeout方法的典型用法代码示例。如果您正苦于以下问题:Python timeout.timeout方法的具体用法?Python timeout.timeout怎么用?Python timeout.timeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timeout
的用法示例。
在下文中一共展示了timeout.timeout方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_training
# 需要导入模块: import timeout [as 别名]
# 或者: from timeout import timeout [as 别名]
def test_training(sagemaker_session, image_uri, instance_type, instance_count):
hyperparameters = {'sagemaker_parameter_server_enabled': True} if instance_count > 1 else {}
hyperparameters['epochs'] = 1
mx = MXNet(entry_point=SCRIPT_PATH,
role='SageMakerRole',
train_instance_count=instance_count,
train_instance_type=instance_type,
sagemaker_session=sagemaker_session,
image_name=image_uri,
hyperparameters=hyperparameters)
with timeout(minutes=15):
prefix = 'mxnet_mnist/{}'.format(utils.sagemaker_timestamp())
train_input = mx.sagemaker_session.upload_data(path=os.path.join(DATA_PATH, 'train'),
key_prefix=prefix + '/train')
test_input = mx.sagemaker_session.upload_data(path=os.path.join(DATA_PATH, 'test'),
key_prefix=prefix + '/test')
job_name = utils.unique_name_from_base('test-mxnet-image')
mx.fit({'train': train_input, 'test': test_input}, job_name=job_name)
示例2: test_coach
# 需要导入模块: import timeout [as 别名]
# 或者: from timeout import timeout [as 别名]
def test_coach(sagemaker_session, ecr_image, instance_type):
source_dir = os.path.join(RESOURCE_PATH, 'coach_cartpole')
dependencies = [os.path.join(RESOURCE_PATH, 'sagemaker_rl')]
cartpole = 'train_coach.py'
estimator = RLEstimator(entry_point=cartpole,
source_dir=source_dir,
role='SageMakerRole',
train_instance_count=1,
train_instance_type=instance_type,
sagemaker_session=sagemaker_session,
image_name=ecr_image,
dependencies=dependencies,
hyperparameters={
"save_model": 1,
"RLCOACH_PRESET": "preset_cartpole_clippedppo",
"rl.agent_params.algorithm.discount": 0.9,
"rl.evaluation_steps:EnvironmentEpisodes": 1,
})
with timeout(minutes=15):
estimator.fit()
示例3: test_syslog_qfx_influx_01
# 需要导入模块: import timeout [as 别名]
# 或者: from timeout import timeout [as 别名]
def test_syslog_qfx_influx_01():
FNAME = 'test_syslog_qfx_01'
PCAP_FILE = FNAME + "/syslog_qfx_01_16000.pcap"
open_nti_input_syslog_lib.start_fluentd_syslog(output_influx='true')
open_nti_input_syslog_lib.replay_file(PCAP_FILE)
time.sleep(5)
db = open_nti_input_syslog_lib.get_influxdb_handle()
query = 'SELECT * FROM events'
result = db.query(query)
points = result.get_points()
assert len(list(points)) != 0
# @timeout(30)
# def test_syslog_qfx_kafka_01():
#
# FNAME = 'test_syslog_qfx_01'
# PCAP_FILE = FNAME + "/syslog_qfx_01_16000.pcap"
#
# open_nti_input_syslog_lib.start_fluentd_syslog(output_kafka='true')
# time.sleep(1)
# open_nti_input_syslog_lib.replay_file(PCAP_FILE)
#
# time.sleep(5)
#
# counter = open_nti_input_syslog_lib.check_kafka_msg()
#
# assert counter == 100
示例4: test_tuning
# 需要导入模块: import timeout [as 别名]
# 或者: from timeout import timeout [as 别名]
def test_tuning(sagemaker_session, image_uri, instance_type):
mx = MXNet(entry_point=SCRIPT_PATH,
role='SageMakerRole',
train_instance_count=1,
train_instance_type=instance_type,
sagemaker_session=sagemaker_session,
image_name=image_uri,
hyperparameters={'epochs': 1})
hyperparameter_ranges = {'learning-rate': ContinuousParameter(0.01, 0.2)}
objective_metric_name = 'Validation-accuracy'
metric_definitions = [
{'Name': 'Validation-accuracy', 'Regex': 'Validation-accuracy=([0-9\\.]+)'}]
tuner = HyperparameterTuner(mx,
objective_metric_name,
hyperparameter_ranges,
metric_definitions,
max_jobs=2,
max_parallel_jobs=2)
with timeout(minutes=20):
prefix = 'mxnet_mnist/{}'.format(utils.sagemaker_timestamp())
train_input = mx.sagemaker_session.upload_data(path=os.path.join(DATA_PATH, 'train'),
key_prefix=prefix + '/train')
test_input = mx.sagemaker_session.upload_data(path=os.path.join(DATA_PATH, 'test'),
key_prefix=prefix + '/test')
job_name = utils.unique_name_from_base('test-mxnet-image', max_length=32)
tuner.fit({'train': train_input, 'test': test_input}, job_name=job_name)
tuner.wait()
示例5: test_tuning
# 需要导入模块: import timeout [as 别名]
# 或者: from timeout import timeout [as 别名]
def test_tuning(sagemaker_session, image_uri, instance_type, framework_version):
resource_path = os.path.join(os.path.dirname(__file__), '..', '..', 'resources')
script = os.path.join(resource_path, 'mnist', 'mnist.py')
estimator = TensorFlow(entry_point=script,
role='SageMakerRole',
train_instance_type=instance_type,
train_instance_count=1,
sagemaker_session=sagemaker_session,
image_name=image_uri,
framework_version=framework_version,
script_mode=True)
hyperparameter_ranges = {'epochs': IntegerParameter(1, 2)}
objective_metric_name = 'accuracy'
metric_definitions = [{'Name': objective_metric_name, 'Regex': 'accuracy = ([0-9\\.]+)'}]
tuner = HyperparameterTuner(estimator,
objective_metric_name,
hyperparameter_ranges,
metric_definitions,
max_jobs=2,
max_parallel_jobs=2)
with timeout(minutes=20):
inputs = estimator.sagemaker_session.upload_data(
path=os.path.join(resource_path, 'mnist', 'data'),
key_prefix='scriptmode/mnist')
tuning_job_name = unique_name_from_base('test-tf-sm-tuning', max_length=32)
tuner.fit(inputs, job_name=tuning_job_name)
tuner.wait()
示例6: _test_mnist_train
# 需要导入模块: import timeout [as 别名]
# 或者: from timeout import timeout [as 别名]
def _test_mnist_train(sagemaker_session, ecr_image, instance_type, instance_count, script):
source_dir = 'test/resources/mnist'
with timeout(minutes=15):
data_path = 'test/resources/mnist/data'
chainer = Chainer(entry_point=script,
source_dir=source_dir,
role='SageMakerRole',
train_instance_count=instance_count,
train_instance_type=instance_type,
sagemaker_session=sagemaker_session,
image_name=ecr_image,
hyperparameters={'batch-size': 10000, 'epochs': 1})
prefix = 'chainer_mnist/{}'.format(sagemaker_timestamp())
train_data_path = os.path.join(data_path, 'train')
key_prefix = prefix + '/train'
train_input = sagemaker_session.upload_data(path=train_data_path, key_prefix=key_prefix)
test_path = os.path.join(data_path, 'test')
test_input = sagemaker_session.upload_data(path=test_path, key_prefix=prefix + '/test')
chainer.fit({'train': train_input, 'test': test_input})
示例7: test_ray
# 需要导入模块: import timeout [as 别名]
# 或者: from timeout import timeout [as 别名]
def test_ray(sagemaker_session, ecr_image, instance_type, framework):
source_dir = os.path.join(RESOURCE_PATH, 'ray_cartpole')
cartpole = 'train_ray_tf.py' if framework == 'tensorflow' else 'train_ray_torch.py'
estimator = RLEstimator(entry_point=cartpole,
source_dir=source_dir,
role='SageMakerRole',
train_instance_count=1,
train_instance_type=instance_type,
sagemaker_session=sagemaker_session,
image_name=ecr_image)
with timeout(minutes=15):
estimator.fit()
示例8: test_gym
# 需要导入模块: import timeout [as 别名]
# 或者: from timeout import timeout [as 别名]
def test_gym(sagemaker_session, ecr_image, instance_type, framework):
resource_path = os.path.join(RESOURCE_PATH, 'gym')
gym_script = 'launcher.sh' if framework == 'tensorflow' else 'gym_envs.py'
estimator = RLEstimator(entry_point=gym_script,
source_dir=resource_path,
role='SageMakerRole',
train_instance_count=1,
train_instance_type=instance_type,
sagemaker_session=sagemaker_session,
image_name=ecr_image)
with timeout(minutes=15):
estimator.fit()