MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS / autotune

Function autotune

models/custom_autotune.py:134–167  ·  view source on GitHub ↗

Decorator for auto-tuning a :code:`triton.jit`'d function. .. highlight:: python .. code-block:: python @triton.autotune(configs=[ triton.Config(meta={'BLOCK_SIZE': 128}, num_warps=4), triton.Config(meta={'BLOCK_SIZE': 1024}, num_warps=8), ], key=['x_size'] # the two above configs

(configs, key, prune_configs_by=None, reset_to_zero=None, nearest_power_of_two=False)

Source from the content-addressed store, hash-verified

132
133
134def autotune(configs, key, prune_configs_by=None, reset_to_zero=None, nearest_power_of_two=False):
135 """
136 Decorator for auto-tuning a :code:`triton.jit`'d function.
137 .. highlight:: python
138 .. code-block:: python
139 @triton.autotune(configs=[
140 triton.Config(meta={'BLOCK_SIZE': 128}, num_warps=4),
141 triton.Config(meta={'BLOCK_SIZE': 1024}, num_warps=8),
142 ],
143 key=['x_size'] # the two above configs will be evaluated anytime
144 # the value of x_size changes
145 )
146 @triton.jit
147 def kernel(x_ptr, x_size, **META):
148 BLOCK_SIZE = META['BLOCK_SIZE']
149 :note: When all the configurations are evaluated, the kernel will run multiple time.
150 This means that whatever value the kernel updates will be updated multiple times.
151 To avoid this undesired behavior, you can use the `reset_to_zero` argument, which
152 reset the value of the provided tensor to `zero` before running any configuration.
153 :param configs: a list of :code:`triton.Config` objects
154 :type configs: list[triton.Config]
155 :param key: a list of argument names whose change in value will trigger the evaluation of all provided configs.
156 :type key: list[str]
157 :param prune_configs_by: a dict of functions that are used to prune configs, fields:
158 'perf_model': performance model used to predicate running time with different configs, returns running time
159 'top_k': number of configs to bench
160 'early_config_prune'(optional): a function used to do early prune (eg, num_stages). It take configs:List[Config] as its input, and returns pruned configs.
161 :param reset_to_zero: a list of argument names whose value will be reset to zero before evaluating any configs.
162 :type reset_to_zero: list[str]
163 """
164 def decorator(fn):
165 return Autotuner(fn, fn.arg_names, configs, key, reset_to_zero, prune_configs_by, nearest_power_of_two)
166
167 return decorator

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected