Train from a pre-defined Dataset. Dataset is defined in paddle.base.dataset. Given a program, either a program or compiled program, train_from_dataset will consume all data samples in dataset. Input scope can be given by users. By default, scope is global_scope(). Th
(
self,
program: Program | CompiledProgram | None = None,
dataset: DatasetBase | _FleetDatasetBase | None = None,
scope: core._Scope | None = None,
thread: int = 0,
debug: bool = False,
fetch_list: list[Tensor] | None = None,
fetch_info: list[str] | None = None,
print_period: int = 100,
fetch_handler: FetchHandler | None = None,
)
| 3009 | return trainer_instance |
| 3010 | |
| 3011 | def train_from_dataset( |
| 3012 | self, |
| 3013 | program: Program | CompiledProgram | None = None, |
| 3014 | dataset: DatasetBase | _FleetDatasetBase | None = None, |
| 3015 | scope: core._Scope | None = None, |
| 3016 | thread: int = 0, |
| 3017 | debug: bool = False, |
| 3018 | fetch_list: list[Tensor] | None = None, |
| 3019 | fetch_info: list[str] | None = None, |
| 3020 | print_period: int = 100, |
| 3021 | fetch_handler: FetchHandler | None = None, |
| 3022 | ) -> None: |
| 3023 | """ |
| 3024 | Train from a pre-defined Dataset. Dataset is defined in paddle.base.dataset. |
| 3025 | Given a program, either a program or compiled program, train_from_dataset will |
| 3026 | consume all data samples in dataset. Input scope can be given by users. By default, |
| 3027 | scope is global_scope(). The total number of thread run in training is `thread`. |
| 3028 | Thread number used in training will be minimum value of threadnum in Dataset and |
| 3029 | the value of thread in this interface. Debug can be set so that executor will display |
| 3030 | Run-Time for all operators and the throughputs of current training task. |
| 3031 | |
| 3032 | Note: train_from_dataset will destroy all resources created within executor for each run. |
| 3033 | |
| 3034 | Args: |
| 3035 | program(Program|CompiledProgram): the program that needs to be run, |
| 3036 | if not provided, then default_main_program (not compiled) will be used. |
| 3037 | dataset(paddle.base.Dataset): dataset created outside this function, |
| 3038 | a user should provide a well-defined dataset before calling this function. |
| 3039 | Please check the document of Dataset if needed. |
| 3040 | scope(Scope): the scope used to run this program, you can switch it to different scope |
| 3041 | for each run. default is global_scope |
| 3042 | thread(int): number of thread a user wants to run in this function. Default is 0, which |
| 3043 | means using thread num of dataset |
| 3044 | debug(bool): whether a user wants to run train_from_dataset |
| 3045 | fetch_list(Tensor List): fetch Tensor list, each variable will be printed |
| 3046 | during training |
| 3047 | fetch_info(String List): print information for each Tensor, its length should be equal |
| 3048 | to fetch_list |
| 3049 | print_period(int): the number of mini-batches for each print, default is 100 |
| 3050 | fetch_handler(FetchHandler): a user define class for fetch output. |
| 3051 | |
| 3052 | Returns: |
| 3053 | None |
| 3054 | |
| 3055 | Examples: |
| 3056 | |
| 3057 | .. code-block:: pycon |
| 3058 | |
| 3059 | >>> # doctest: +SKIP("This does not supported in PIR mode") |
| 3060 | |
| 3061 | >>> import paddle |
| 3062 | |
| 3063 | >>> paddle.enable_static() |
| 3064 | >>> place = paddle.CPUPlace() # you can set place = paddle.CUDAPlace(0) to use gpu |
| 3065 | >>> exe = paddle.static.Executor(place) |
| 3066 | >>> x = paddle.static.data(name="x", shape=[None, 10, 10], dtype="int64") |
| 3067 | >>> y = paddle.static.data(name="y", shape=[None, 1], dtype="int64", lod_level=1) |
| 3068 | >>> dataset = paddle.base.DatasetFactory().create_dataset() |