:api_attr: Static Graph An Executor in Python, supports single/multiple-GPU running, and single/multiple-CPU running. Args: place(paddle.CPUPlace()|paddle.CUDAPlace(n)|str|None): This parameter represents which device the executor runs on. When this parameter i
| 1251 | |
| 1252 | |
| 1253 | class Executor: |
| 1254 | """ |
| 1255 | :api_attr: Static Graph |
| 1256 | |
| 1257 | An Executor in Python, supports single/multiple-GPU running, |
| 1258 | and single/multiple-CPU running. |
| 1259 | |
| 1260 | Args: |
| 1261 | place(paddle.CPUPlace()|paddle.CUDAPlace(n)|str|None): This parameter represents |
| 1262 | which device the executor runs on. When this parameter is None, PaddlePaddle |
| 1263 | will set the default device according to its installation version. If Paddle |
| 1264 | is CPU version, the default device would be set to `CPUPlace()` . If Paddle is |
| 1265 | GPU version, the default device would be set to `CUDAPlace(0)` . Default is None. |
| 1266 | If ``place`` is string, it can be ``cpu``, and ``gpu:x``, where ``x`` |
| 1267 | is the index of the GPUs. Note: users only pass one Place or None to initialize |
| 1268 | Executor when using multiple-cards. Other APIs will override the cards. See |
| 1269 | `document for multiple-cards <https://www.paddlepaddle.org.cn/documentation/docs/en/develop/guides/01_paddle2.0_introduction/update_en.html#stand-alone-multi-card-launch>`_ |
| 1270 | |
| 1271 | Returns: |
| 1272 | Executor |
| 1273 | |
| 1274 | Examples: |
| 1275 | |
| 1276 | .. code-block:: pycon |
| 1277 | |
| 1278 | >>> import paddle |
| 1279 | >>> import numpy |
| 1280 | |
| 1281 | >>> # Executor is only used in static graph mode |
| 1282 | >>> paddle.enable_static() |
| 1283 | |
| 1284 | >>> # Set place explicitly. |
| 1285 | >>> # use_cuda = True |
| 1286 | >>> # place = paddle.CUDAPlace(0) if use_cuda else paddle.CPUPlace() |
| 1287 | >>> # exe = paddle.static.Executor(place) |
| 1288 | |
| 1289 | >>> # If you don't set place, PaddlePaddle sets the default device. |
| 1290 | >>> exe = paddle.static.Executor() |
| 1291 | |
| 1292 | >>> train_program = paddle.static.Program() |
| 1293 | >>> startup_program = paddle.static.Program() |
| 1294 | >>> with paddle.static.program_guard(train_program, startup_program): |
| 1295 | ... data = paddle.static.data(name='X', shape=[None, 1], dtype='float32') |
| 1296 | ... hidden = paddle.static.nn.fc(data, 10) |
| 1297 | ... loss = paddle.mean(hidden) |
| 1298 | ... paddle.optimizer.SGD(learning_rate=0.01).minimize(loss) |
| 1299 | >>> # Run the startup program once and only once. |
| 1300 | >>> # Not need to optimize/compile the startup program. |
| 1301 | >>> exe.run(startup_program) |
| 1302 | |
| 1303 | >>> # Run the main program. |
| 1304 | >>> x = numpy.random.random(size=(10, 1)).astype('float32') |
| 1305 | >>> (loss_data,) = exe.run(train_program, feed={"X": x}, fetch_list=[loss]) |
| 1306 | """ |
| 1307 | |
| 1308 | place: _Place |
| 1309 | |
| 1310 | def __init__(self, place: PlaceLike | None = None) -> None: |
no outgoing calls