add hash key and early stop mechanism for libtuner - #717
Conversation
201576b to
beef1e8
Compare
9372ec2 to
4aef712
Compare
4aef712 to
6fae18b
Compare
StrongSpoon
left a comment
There was a problem hiding this comment.
It would be beneficial if you could demonstrate a performance comparison between the matmul function before and after enabling early_stop.
| original_func = func | ||
|
|
||
| source_code = inspect.getsource(original_func) | ||
| return hashlib.md5(source_code.encode("utf-8")).hexdigest()[:8] |
There was a problem hiding this comment.
I suggest also storing the hash key of the configuration space. If the configuration space expands or shrinks, the optimal configuration may change.
| best_time = min(timing_values) | ||
| sorted_times = sorted(timing_values) | ||
|
|
||
| if configs_tested >= self.early_stop_min_configs: |
There was a problem hiding this comment.
There's no need to compare again.
| v = s(args[k]) | ||
| key.append(v) | ||
|
|
||
| key.append(f"hash_{self.kernel_hash}") |
There was a problem hiding this comment.
I prefer to apply the hash key when retrieving self.cache from libcache.
| return False | ||
|
|
||
| if len(timings) < 2: | ||
| return False |
There was a problem hiding this comment.
length of timings is equal to the value of configs_tested. I suggest maintaining two scalars optimal_perf and suboptimal_perf, instead of sorting the timings list every time.
As I mentioned earlier, by running the script above, the test results before and after opening are as follows: After: There are two running times before and after, the first time represents the running time without cache, and the second time represents the running time after tuning. In fact, this is related to the two hyperparameters early_stop_threshold and early_stop_min_comfigs. We can also consider adding a flag to choose whether to enable the early stop function. I think this function is meaningful for non long and small tasks. |
…nd suboptimal_perf
|
Based on your suggestion, I retested the end-to-end latency |
|
I have retest on the follow script: the result as follow, disable early stop: enable early stop: Therefore, we can see that early stop can greatly reduce the cost of tuning, while having a relatively small impact on the performance of the operator. |
What would happen with the increase of round number? If the selected config isn't the optimal, we may lose more than the benefits we gain from the auto-tuning. Will there be any mechanism to help decide when to enable early stopping? |
PR Category
Other
Type of Change
New Feature
Description
Issue
The current libtuner lacks a field representing the code, which may result in enabling outdated cache after modifying the code. To address this issue, this PR has added the md5 value of the source code as the hash key.
There is a phenomenon of excessive tuning in the way libtuner searches for the optimal config, which requires excessive computation to improve performance by 1%. Therefore, this PR has added an early stop mechanism.
Progress
Performance
Test by the following code on H800, Through the following code test, on H800, the first end-to-end tuning time decreased from 11.51 seconds to 8.53 seconds, while the second end-to-end inference time increased from 1.16 seconds to 1.67 seconds.