neuralmonkey.tf_manager module¶
TensorFlow Manager.
TensorFlow manager is a helper object in Neural Monkey which manages TensorFlow sessions, execution of the computation graph, and saving and restoring of model variables.
-
class
neuralmonkey.tf_manager.
TensorFlowManager
(num_sessions: int, num_threads: int, save_n_best: int = 1, minimize_metric: bool = False, gpu_allow_growth: bool = True, per_process_gpu_memory_fraction: float = 1.0, enable_tf_debug: bool = False) → None¶ Bases:
object
Inteface between computational graph, data and TF sessions.
-
sessions
¶ List of active Tensorflow sessions.
-
__init__
(num_sessions: int, num_threads: int, save_n_best: int = 1, minimize_metric: bool = False, gpu_allow_growth: bool = True, per_process_gpu_memory_fraction: float = 1.0, enable_tf_debug: bool = False) → None¶ Initialize a TensorflowManager.
At this moment the graph must already exist. This method initializes required number of TensorFlow sessions and initializes them with provided variable files if they are provided.
Parameters: - num_sessions – Number of sessions to be initialized.
- num_threads – Number of threads sessions will run in.
- save_n_best – How many best models to keep
- minimize_metric – Whether the best model is the one with the lowest or the highest score
- gpu_allow_growth – TF to allocate incrementally, not all at once.
- per_process_gpu_memory_fraction – Limit TF memory use.
-
best_vars_file
¶
-
execute
(batch: neuralmonkey.dataset.Dataset, feedables: Set[neuralmonkey.model.feedable.Feedable], runners: Sequence[neuralmonkey.runners.base_runner.GraphExecutor], train: bool = False, compute_losses: bool = True, summaries: bool = True) → List[neuralmonkey.runners.base_runner.ExecutionResult]¶ Execute runners on a batch of data.
First, extract executables from the provided runners, telling the runners whether to compute also losses and summaries. Second, until all executables are satisfied (have the result attribute set), run the executables on the batch.
Parameters: - batch – A batch of data.
- execution_scripts – List of runners to execute.
- train – Training mode flag (this value is fed to the train_mode placeholders in model parts).
- compute_losses – Flag to runners whether run loss operations.
- summaries – Flag to runners whether to run summary operations.
Returns: A list of ExecutionResult tuples, one for each executable (runner).
-
init_saving
(vars_prefix: str) → None¶
-
initialize_model_parts
(runners: Sequence[neuralmonkey.runners.base_runner.GraphExecutor], save: bool = False) → None¶ Initialize model parts variables from their checkpoints.
-
initialize_sessions
() → None¶
-
restore
(variable_files: Union[str, List[str]]) → None¶
-
restore_best_vars
() → None¶
-
save
(variable_files: Union[str, List[str]]) → None¶
-
validation_hook
(score: float, epoch: int, batch: int) → None¶
-
-
neuralmonkey.tf_manager.
get_default_tf_manager
() → neuralmonkey.tf_manager.TensorFlowManager¶