MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / DistModel

Class DistModel

python/paddle/distributed/auto_parallel/api.py:2925–3651  ·  view source on GitHub ↗

`DistModel` is the model converted from a ``paddle.nn.layer`` with distributed tensors as its parameters. It contains the static graph converted from a ``paddle.nn.layer`` whose parameters are distributed tensors (constructed from ``paddle.distributed.shard_tensor``), and provides t

Source from the content-addressed store, hash-verified

2923
2924
2925class DistModel:
2926 """
2927 `DistModel` is the model converted from a ``paddle.nn.layer`` with distributed
2928 tensors as its parameters. It contains the static graph converted from a
2929 ``paddle.nn.layer`` whose parameters are distributed tensors (constructed
2930 from ``paddle.distributed.shard_tensor``), and provides the APIs for training,
2931 evaluation and prediction with the static graph.
2932
2933 It is suggested to generate DistModel by ``paddle.distributed.to_static``,
2934 not directly by ``paddle.distributed.DistModel``.
2935
2936 Please first set the DistModel to "train", "eval" or "predict" mode with
2937 ``train()/eval()/predict()`` method and then use the ``__call__`` method for
2938 training, evaluation and prediction respectively.
2939
2940 For more details of the usage, please refer to the sample code in
2941 ``paddle.distributed.to_static``.
2942
2943 Args:
2944 layer(paddle.nn.Layer): The layer in dygraph mode, whose parameters
2945 are distributed tensors generated by ``shard_tensor``.
2946 loader(ShardDataLoader|paddle.io.DataLoader): The data loader used in dygraph mode,
2947 used to infer inputs_spec and labels_spec.
2948 loss(Loss|Callable|None, optional): The loss function for training
2949 or evaluating the model. Can be a `paddle.nn.Layer` instance or
2950 any callable function. If loss is not None, DistModel will be set
2951 to "train" (when the optimizer is also not None) or "eval" mode
2952 (when optimizer is None) in default. If it is None, DistModel will
2953 be set to "predict" mode in default. Default: None.
2954 optimizer(paddle.optimizer.Optimizer|None, optional): The optimizer
2955 for training. If both optimizer and loss are set, DistModel will
2956 be set to "train" mode in default. Default: None.
2957 strategy(paddle.distributed.Strategy|None, optional): Configs for
2958 parallel strategies and optimization settings (e.g. sharding,
2959 pipeline parallelism). Default: None.
2960 input_spec(list[list[paddle.distributed.DistributedInputSpec]]|None, optional):
2961 The custom input specs specify the shape, dtype, and name information
2962 of model inputs and labels. If it is not None, the input specs and
2963 label specs will be inferred from the custom input specs. The custom
2964 input specs should be a list containing two sublists: the first
2965 sublist represents theinput specs, and the second sublist represents
2966 the label specs. Default: None.
2967 """
2968
2969 def __init__(
2970 self,
2971 layer: Layer,
2972 loader: ShardDataloader | DataLoader,
2973 loss: Layer | Callable[..., Any] | None = None,
2974 optimizer: Optimizer | None = None,
2975 strategy: Strategy | None = None,
2976 metrics: list[Metric] | None = None,
2977 input_spec: list[list[DistributedInputSpec]] | None = None,
2978 ) -> None:
2979 self._inner_strategy = self.__convert_strategy(strategy)
2980 self._structured_to_parameter_name = {
2981 k: v.name for k, v in layer.state_dict().items()
2982 }

Callers 1

to_staticFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected