deepmd.tf2.common#

Attributes#

Classes#

TF2List

Built-in mutable sequence.

Functions#

to_tensorflow_array(→ Any)

Convert an object to an ndtensorflow Array.

to_tf_tensor(→ tensorflow.Tensor | None)

Unwrap a TensorFlow-backed Array to a TensorFlow tensor.

wrap_tensor(→ Any | None)

Wrap a TensorFlow tensor as an ndtensorflow Array.

wrap_value(→ Any)

Recursively wrap TensorFlow tensors as ndtensorflow Arrays.

unwrap_value(→ Any)

Recursively unwrap ndtensorflow Arrays for TensorFlow SavedModel returns.

register_dpmodel_mapping(→ None)

Register how to convert a dpmodel object to its tf2 wrapper.

_looks_like_dpmodel_class(→ bool)

_looks_like_dpmodel_object(→ bool)

_looks_like_tf2_object(→ bool)

_ensure_registrations(→ None)

try_convert_module(→ Any | None)

Convert a registered dpmodel object to its tf2 wrapper.

_auto_wrap_native_op(→ Any)

_try_convert_list(→ list[Any])

convert_tf2_value(→ Any)

tf2_setattr(→ Any)

tf2_module(→ type[T])

Wrap a dpmodel subclass as a TensorFlow tf.Module.

Module Contents#

deepmd.tf2.common.to_tensorflow_array(array: Any | None) → Any[source]#

Convert an object to an ndtensorflow Array.

Parameters:
array

The object to convert.

Returns:
ndtensorflow.Array

The TensorFlow-backed array.

deepmd.tf2.common.to_tf_tensor(array: Any | None) → tf.Tensor | None[source]#

Unwrap a TensorFlow-backed Array to a TensorFlow tensor.

deepmd.tf2.common.wrap_tensor(tensor: Any | None) → Any | None[source]#

Wrap a TensorFlow tensor as an ndtensorflow Array.

deepmd.tf2.common.wrap_value(value: Any) → Any[source]#

Recursively wrap TensorFlow tensors as ndtensorflow Arrays.

deepmd.tf2.common.unwrap_value(value: Any) → Any[source]#

Recursively unwrap ndtensorflow Arrays for TensorFlow SavedModel returns.

deepmd.tf2.common._PACKAGE_ROOT[source]#
deepmd.tf2.common._DPMODEL_TO_TF2: dict[type[Any], collections.abc.Callable[[Any], Any]][source]#
deepmd.tf2.common._AUTO_WRAPPED_CLASSES: dict[type[deepmd.dpmodel.common.NativeOP], type[Any]][source]#
deepmd.tf2.common._REGISTRATIONS_READY = False[source]#
deepmd.tf2.common._REGISTRATIONS_IN_PROGRESS = False[source]#
deepmd.tf2.common._REGISTRATION_MODULES[source]#
class deepmd.tf2.common.TF2List[source]#

Bases: list

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

append(item: Any) → None[source]#

Append object to the end of the list.

extend(items: list[Any]) → None[source]#

Extend list by appending elements from the iterable.

insert(index: int, item: Any) → None[source]#

Insert object before index.

__setitem__(index: Any, item: Any) → None[source]#

Set self[key] to value.

deepmd.tf2.common.register_dpmodel_mapping(dpmodel_cls: type[Any], converter: collections.abc.Callable[[Any], Any]) → None[source]#

Register how to convert a dpmodel object to its tf2 wrapper.

deepmd.tf2.common._looks_like_dpmodel_class(cls: type[Any]) → bool[source]#
deepmd.tf2.common._looks_like_dpmodel_object(value: Any) → bool[source]#
deepmd.tf2.common._looks_like_tf2_object(value: Any) → bool[source]#
deepmd.tf2.common._ensure_registrations() → None[source]#
deepmd.tf2.common.try_convert_module(value: Any) → Any | None[source]#

Convert a registered dpmodel object to its tf2 wrapper.

deepmd.tf2.common._auto_wrap_native_op(value: deepmd.dpmodel.common.NativeOP) → Any[source]#
deepmd.tf2.common._try_convert_list(value: list[Any], *, keep_converting: bool = False) → list[Any][source]#
deepmd.tf2.common.convert_tf2_value(value: Any) → Any[source]#
deepmd.tf2.common.tf2_setattr(obj: Any, name: str, value: Any) → Any[source]#
deepmd.tf2.common.T[source]#
deepmd.tf2.common.tf2_module(module: type[T]) → type[T][source]#

Wrap a dpmodel subclass as a TensorFlow tf.Module.