tf.contrib.opt.ElasticAverageCustomGetter
Stay organized with collections
Save and categorize content based on your preferences.
Custom_getter class is used to do:
tf.contrib.opt.ElasticAverageCustomGetter(
worker_device
)
- Change trainable variables to local collection and place them at worker
device
- Generate global variables(global center variables)
- Generate local variables(local center variables) which record the global
variables and place them at worker device
Notice that the class should be used with tf.replica_device_setter,
so that the global center variables and global step variable can be placed
at ps device. Besides, use 'tf.compat.v1.get_variable' instead of
'tf.Variable' to
use this custom getter.
For example,
ea_custom_getter = ElasticAverageCustomGetter(worker_device)
with tf.device(
tf.compat.v1.train.replica_device_setter(
worker_device=worker_device,
ps_device="/job:ps",
cluster=cluster)),
tf.compat.v1.variable_scope('',custom_getter=ea_custom_getter):
...
create your model here
...
with tf.device(worker_device):
opt = tf.compat.v1.train.MomentumOptimizer(...)
optimizer = ElasticAverageOptimizer(
opt,
num_worker=2,
moving_rate=0.01, # or use default value
communication_period=20,
ea_custom_getter=ea_custom_getter)
...
train_op = optimizer.apply_gradients(
grads_vars,
global_step=global_step)
...
hooks = [optimizer.make_session_run_hook(is_chief, task_index)]
...
with tf.compat.v1.train.MonitoredTrainingSession(master=server.target,
is_chief=is_chief,
checkpoint_dir=("...),
save_checkpoint_secs=600,
hooks=hooks) as mon_sess:
Args |
worker_device
|
String. Name of the worker job.
|
Methods
__call__
View source
__call__(
getter, name, trainable, collections, *args, **kwargs
)
Call self as a function.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.contrib.opt.ElasticAverageCustomGetter\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/opt/python/training/elastic_average_optimizer.py#L40-L140) |\n\nCustom_getter class is used to do: \n\n tf.contrib.opt.ElasticAverageCustomGetter(\n worker_device\n )\n\n1. Change trainable variables to local collection and place them at worker device\n2. Generate global variables(global center variables)\n3. Generate local variables(local center variables) which record the global variables and place them at worker device Notice that the class should be used with tf.replica_device_setter, so that the global center variables and global step variable can be placed at ps device. Besides, use 'tf.compat.v1.get_variable' instead of 'tf.Variable' to use this custom getter.\n\nFor example,\nea_custom_getter = ElasticAverageCustomGetter(worker_device)\nwith tf.device(\ntf.compat.v1.train.replica_device_setter(\nworker_device=worker_device,\nps_device=\"/job:ps\",\ncluster=cluster)),\ntf.compat.v1.variable_scope('',custom_getter=ea_custom_getter):\n...\ncreate your model here\n...\nwith tf.device(worker_device):\nopt = tf.compat.v1.train.MomentumOptimizer(...)\noptimizer = ElasticAverageOptimizer(\nopt,\nnum_worker=2,\nmoving_rate=0.01, # or use default value\ncommunication_period=20,\nea_custom_getter=ea_custom_getter)\n...\ntrain_op = optimizer.apply_gradients(\ngrads_vars,\nglobal_step=global_step)\n...\nhooks = \\[optimizer.make_session_run_hook(is_chief, task_index)\\]\n...\nwith tf.compat.v1.train.MonitoredTrainingSession(master=server.target,\nis_chief=is_chief,\ncheckpoint_dir=(\"...),\nsave_checkpoint_secs=600,\nhooks=hooks) as mon_sess:\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|-----------------------------------|\n| `worker_device` | String. Name of the `worker` job. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `__call__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/opt/python/training/elastic_average_optimizer.py#L97-L140) \n\n __call__(\n getter, name, trainable, collections, *args, **kwargs\n )\n\nCall self as a function."]]