Native DP model format for multiple backends.
See issue #2982 for more information.Module Contents
Attributes
- deepmd.dpmodel.utils.network.__version__ = 'unknown'[source]
- class deepmd.dpmodel.utils.network.Identity[source]
Bases: deepmd.dpmodel.NativeOP
The unit operation of a native model.
- call(x: numpy.ndarray) → numpy.ndarray[source]
The Identity operation layer.
- serialize() → dict[source]
- classmethod deserialize(data: dict) → Identity[source]
- class deepmd.dpmodel.utils.network.NativeLayer(num_in, num_out, bias: bool = True, use_timestep: bool = False, activation_function: str | None = None, resnet: bool = False, precision: str = DEFAULT_PRECISION)[source]
Bases: deepmd.dpmodel.NativeOP
Native representation of a layer.
- Parameters:
- w
np.ndarray
, optional
The weights of the layer.
- b
np.ndarray
, optional
The biases of the layer.
- idt
np.ndarray
, optional
The identity matrix of the layer.
- activation_function
str
, optional
The activation function of the layer.
- resnetbool,
optional
Whether the layer is a residual layer.
- serialize() → dict[source]
Serialize the layer to a dict.
- Returns:
dict
The serialized layer.
- classmethod deserialize(data: dict) → NativeLayer[source]
Deserialize the layer from a dict.
- Parameters:
- data
dict
The dict to deserialize from.
- check_shape_consistency()[source]
- check_type_consistency()[source]
- __setitem__(key, value)[source]
- __getitem__(key)[source]
- dim_in() → int[source]
- dim_out() → int[source]
- call(x: numpy.ndarray) → numpy.ndarray[source]
Forward pass.
- Parameters:
- x
np.ndarray
The input.
- Returns:
np.ndarray
The output.
- deepmd.dpmodel.utils.network.get_activation_fn(activation_function: str) → Callable[[numpy.ndarray], numpy.ndarray][source]
- class deepmd.dpmodel.utils.network.LayerNorm(num_in: int, eps: float = 1e-05, uni_init: bool = True, trainable: bool = True, precision: str = DEFAULT_PRECISION)[source]
Bases: NativeLayer
Implementation of Layer Normalization layer.
- Parameters:
- num_in
int
The input dimension of the layer.
- eps
float
, optional
A small value added to prevent division by zero in calculations.
- uni_initbool,
optional
If initialize the weights to be zeros and ones.
- serialize() → dict[source]
Serialize the layer to a dict.
- Returns:
dict
The serialized layer.
- classmethod deserialize(data: dict) → LayerNorm[source]
Deserialize the layer from a dict.
- Parameters:
- data
dict
The dict to deserialize from.
- _check_shape_consistency()[source]
- __setitem__(key, value)[source]
- __getitem__(key)[source]
- dim_out() → int[source]
- call(x: numpy.ndarray) → numpy.ndarray[source]
Forward pass.
- Parameters:
- x
np.ndarray
The input.
- Returns:
np.ndarray
The output.
- static layer_norm_numpy(x, shape, weight=None, bias=None, eps=1e-05)[source]
- deepmd.dpmodel.utils.network.make_multilayer_network(T_NetworkLayer, ModuleBase)[source]
- deepmd.dpmodel.utils.network.NativeNet[source]
- deepmd.dpmodel.utils.network.make_embedding_network(T_Network, T_NetworkLayer)[source]
- deepmd.dpmodel.utils.network.EmbeddingNet[source]
- deepmd.dpmodel.utils.network.make_fitting_network(T_EmbeddingNet, T_Network, T_NetworkLayer)[source]
- deepmd.dpmodel.utils.network.FittingNet[source]
- class deepmd.dpmodel.utils.network.NetworkCollection(ndim: int, ntypes: int, network_type: str = 'network', networks: List[NativeNet | dict] = [])[source]
A collection of networks for multiple elements.
The number of dimesions for types might be 0, 1, or 2. - 0: embedding or fitting with type embedding, in () - 1: embedding with type_one_side, or fitting, in (type_i) - 2: embedding without type_one_side, in (type_i, type_j)
- Parameters:
- ndim
int
The number of dimensions.
- network_type
str
, optional
The type of the network.
- networks
dict
, optional
The networks to initialize with.
- NETWORK_TYPE_MAP: ClassVar[Dict[str, type]][source]
- check_completeness()[source]
Check whether the collection is complete.
- Raises:
RuntimeError
If the collection is incomplete.
- _convert_key(key)[source]
- __getitem__(key)[source]
- __setitem__(key, value)[source]
- serialize() → dict[source]
Serialize the networks to a dict.
- Returns:
dict
The serialized networks.
- classmethod deserialize(data: dict) → NetworkCollection[source]
Deserialize the networks from a dict.
- Parameters:
- data
dict
The dict to deserialize from.