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

Class Engine

python/paddle/distributed/auto_parallel/static/engine.py:99–2649  ·  view source on GitHub ↗

An High-Level API for auto parallel, which could be used for distributed Training (engine.fit) and Inference (engine.predict). Static graph mode is supported natively, Dynamic graph mode is also supported under `@to_static <https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/p

Source from the content-addressed store, hash-verified

97
98
99class Engine:
100 """
101 An High-Level API for auto parallel, which could be used for distributed Training (engine.fit) and Inference (engine.predict).
102 Static graph mode is supported natively, Dynamic graph mode is also supported under `@to_static <https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/jit/to_static_cn.html#to-static>`_ .
103
104 Args:
105 model (paddle.nn.Layer, optional): The model is an instance of
106 paddle.nn.Layer.
107 loss (Loss|Callable|None, optional): The loss can be a `paddle.nn.Layer`
108 instance or any callable function taken the predicted values and
109 ground truth values as input. It can be None when there is no loss.
110 Default: None.
111 optimizer (Optimizer|None, optional): The optimizer need to be set in training
112 and should be None in eval and predict mode. Default: None.
113 metrics (Metric|list[Metric]|None, optional): If metrics is set, all
114 metrics will be calculated and output in train/eval mode. Default: None.
115 cluster (Cluster|None, optional): The cluster represents the topology information
116 about the used physical devices. Default: None. (Unused for now)
117 strategy (Strategy|None, optional): The strategy is used to configure the
118 parallelization and optimization behaviors. Default: None.
119
120 Examples:
121
122 .. code-block:: pycon
123
124 >>> import paddle
125 >>> import paddle.vision.transforms as T
126 >>> from paddle.distributed.fleet import auto
127 >>> from paddle.vision.datasets import MNIST
128
129 >>> transform = T.Compose([
130 ... T.Transpose(),
131 ... T.Normalize([127.5], [127.5])
132 >>> ])
133 >>> train_dataset = MNIST(mode='train', transform=transform)
134 >>> valid_dataset = MNIST(mode='test', transform=transform)
135
136 >>> model = paddle.vision.models.LeNet()
137 >>> loss = paddle.nn.CrossEntropyLoss()
138 >>> optimizer = paddle.optimizer.Adam(
139 ... learning_rate=0.001,
140 ... parameters=model.parameters(),
141 ... )
142 >>> metrics = paddle.metric.Accuracy(topk=(1, 2))
143
144 >>> engine = auto.Engine(model, loss, optimizer, metrics)
145 >>> # fit
146 >>> engine.fit(train_dataset, epochs=2, batch_size=64)
147 >>> # evaluate
148 >>> engine.evaluate(valid_dataset, batch_size=64)
149 >>> # predict
150 >>> engine.predict(valid_dataset, batch_size=64)
151 >>> # save
152 >>> engine.save("./my_model")
153 >>> # load
154 >>> engine.load("./my_model")
155
156 """

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected