opennmt.utils.compat module

Functions for compatibility with different TensorFlow versions.

opennmt.utils.compat.is_tf2()[source]

Returns True if running TensorFlow 2.0.

opennmt.utils.compat.tf_supports(symbol)[source]

Returns True if TensorFlow defines symbol.

opennmt.utils.compat.tf_any(*symbols)[source]

Returns the first supported symbol.

opennmt.utils.compat.tf_compat(v2=None, v1=None)[source]

Returns the compatible symbol based on the current TensorFlow version.

Parameters:
  • v2 – The candidate v2 symbol name.
  • v1 – The candidate v1 symbol name.
Returns:

A TensorFlow symbol.

Raises:

ValueError – if no symbol can be found.

opennmt.utils.compat.name_from_variable_scope(name='')[source]

Creates a name prefixed by the current variable scope.

opennmt.utils.compat.reuse()[source]

Returns True if the current variable scope is marked for reuse.