Tune kernel with customized cost function

I’m using Ansor to tune kernels, but I want to customize some policies to generate the kernels I want. How should I modify the cost function, or which part of the code does it correspond to?

1 Like

You could implement your own search policy inherited class SearchPolicy like class SketchPolicy, and you could implement your own cost model like class XGBModel

1 Like

For example, the current default evaluation strategy in Ansor is to tune kernels towards minimizing kernel execution time. If I want to change it to a custom target, so that Ansor tunes in that direction, what should I do? Do I just need to modify the cost model?

1 Like

Right. If you think xgb is suitable, you could maybe modify its related part, for example maybe you think pack sum is not suitable.

1 Like

Got it, I should not need to customize search policy if I understand correctly

1 Like

I cannot find related cost function code snippets and could you give me some suggestions … Thanks so much

1 Like

@wxthu https://github.com/apache/tvm/blob/main/python/tvm/auto_scheduler/cost_model/xgb_model.py

1 Like

To customize kernel tuning in Ansor, you’ll typically modify the cost_model.py file in the Ansor source code. The cost function can be adapted within this file to prioritize specific policies, making Ansor generate kernels that align with your desired criteria, such as execution time, memory usage, or other parameters. names cluster

regards Isabella Jhon

1 Like

I think we should modify ProgramRunner and add customized metric into MeasureResult

1 Like

To tune the kernel with a customized cost function, you need to modify the kernel function or the optimization process to minimize your specific cost measure, improving model performance