Basic loop to train a model. Calls `train_step_fn` in a loop to train a model. The function is called as: ```python train_step_fn(session, *args, **kwargs) ``` It is passed a `tf.compat.v1.Session` in addition to `args` and `kwargs`. The function typically runs one training step i
(supervisor,
train_step_fn,
args=None,
kwargs=None,
master="")
| 23 | |
| 24 | @tf_export(v1=["train.basic_train_loop"]) |
| 25 | def basic_train_loop(supervisor, |
| 26 | train_step_fn, |
| 27 | args=None, |
| 28 | kwargs=None, |
| 29 | master=""): |
| 30 | """Basic loop to train a model. |
| 31 | |
| 32 | Calls `train_step_fn` in a loop to train a model. The function is called as: |
| 33 | |
| 34 | ```python |
| 35 | train_step_fn(session, *args, **kwargs) |
| 36 | ``` |
| 37 | |
| 38 | It is passed a `tf.compat.v1.Session` in addition to `args` and `kwargs`. The |
| 39 | function |
| 40 | typically runs one training step in the session. |
| 41 | |
| 42 | Args: |
| 43 | supervisor: `tf.compat.v1.train.Supervisor` to run the training services. |
| 44 | train_step_fn: Callable to execute one training step. Called repeatedly as |
| 45 | `train_step_fn(session, *args **kwargs)`. |
| 46 | args: Optional positional arguments passed to `train_step_fn`. |
| 47 | kwargs: Optional keyword arguments passed to `train_step_fn`. |
| 48 | master: Master to use to create the training session. Defaults to `""` |
| 49 | which causes the session to be created in the local process. |
| 50 | """ |
| 51 | if args is None: |
| 52 | args = [] |
| 53 | if kwargs is None: |
| 54 | kwargs = {} |
| 55 | should_retry = True |
| 56 | while should_retry: |
| 57 | try: |
| 58 | should_retry = False |
| 59 | with supervisor.managed_session(master) as sess: |
| 60 | while not supervisor.should_stop(): |
| 61 | train_step_fn(sess, *args, **kwargs) |
| 62 | except errors.AbortedError: |
| 63 | # Always re-run on AbortedError as it indicates a restart of one of the |
| 64 | # distributed tensorflow servers. |
| 65 | should_retry = True |
nothing calls this directly
no test coverage detected