set_config

paddle.incubate.autotune. set_config ( config=None ) [source]

Set the configuration for kernel, layout and dataloader auto-tuning.

1. kernel: When it is enable, exhaustive search method will be used to select and cache the best algorithm for the operator in the tuning iteration. Tuning parameters are as follows:

  • enable(bool): Whether to enable kernel tuning.

  • tuning_range(list): Start and end iteration for auto-tuning. Default: [1, 10].

2. layout: When it is enable, the best data layout such as NCHW or NHWC will be determined based on the device and data type. When the origin layout setting is not best, layout transformation will be automaticly performed to improve model performance. Layout auto-tuning only supports dygraph mode currently. Tuning parameters are as follows:

  • enable(bool): Whether to enable layout tuning.

3. dataloader: When it is enable, the best num_workers will be selected to replace the origin dataloader setting. Tuning parameters are as follows:

  • enable(bool): Whether to enable dataloader tuning.

Parameters

config (dict|str|None, optional) – Configuration for auto-tuning. If it is a dictionary, the key is the tuning type, and the value is a dictionary of the corresponding tuning parameters. If it is a string, the path of a json file will be specified and the tuning configuration will be set by the the json file. Default: None, auto-tuning for kernel, layout and dataloader will be enabled.

Examples

import paddle
import json

# config is a dict.
config = {
    "kernel": {
        "enable": True,
        "tuning_range": [1, 5],
    },
    "layout": {
        "enable": True,
    },
    "dataloader": {
        "enable": True,
    }
}
paddle.incubate.autotune.set_config(config)

# config is the path of json file.
config_json = json.dumps(config)
with open('config.json', 'w') as json_file:
    json_file.write(config_json)
paddle.incubate.autotune.set_config('config.json')