Skip to content

Enable User-Driven Early Termination and Caching in Autotuning#1361

Open
hinriksnaer wants to merge 2 commits intopytorch:mainfrom
hinriksnaer:feat-early-exit
Open

Enable User-Driven Early Termination and Caching in Autotuning#1361
hinriksnaer wants to merge 2 commits intopytorch:mainfrom
hinriksnaer:feat-early-exit

Conversation

@hinriksnaer
Copy link
Copy Markdown
Collaborator

Implements #1331

Summary

Adds support for gracefully terminating autotuning early (via CTRL+C) while saving the best configuration found so far. This allows users to stop autotuning when they see diminishing returns without losing progress.

Implementation

  • Added _handle_early_termination() method to AutotuneCacheBase that extracts the best benchmarked config
  • Wrapped autotuner.autotune() calls in both code paths (skip_cache and normal) with try/except KeyboardInterrupt
  • Config is automatically saved to cache before exiting
  • Future runs will use the cached config, skipping autotuning entirely

Users who want immediate termination can press CTRL+C twice or use kill -9.

Discussion

Using try like this never feels elegant enough to me. I did consider making this cleaner with a decorator, but I'd rather keep things simple for now and get some feedback before overcomplicating this.

Are we good on CTRL+C invoking this or do we want to consider something else? I am also not sure if we should prompt the user for this or guard this behind a flag.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 29, 2026
Copy link
Copy Markdown
Contributor

@oulgen oulgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm not entirely convinced that we should cache keyboard interrupted configs by default. Maybe we should prompt the user to ask whether they want to save it. Or maybe some checkpoint system similar to what @yf225 was thinking.

If I ctrl-C during autotune, i dont always want to keep that and having to find and delete the cache file might be annoying

@hinriksnaer
Copy link
Copy Markdown
Collaborator Author

Thanks @oulgen, these are all solid points. I will see what I can do. In the meantime, could you reference whatever @yf225 had in mind?

@oulgen
Copy link
Copy Markdown
Contributor

oulgen commented Jan 29, 2026

Thanks @oulgen, these are all solid points. I will see what I can do. In the meantime, could you reference whatever @yf225 had in mind?

#1348

@hinriksnaer
Copy link
Copy Markdown
Collaborator Author

Thanks for sharing @oulgen. Given that this is still in active development, I assume the best thing to do is to wait until the changes land and leverage that functionality to support early stopping. What do you think?

@yf225
Copy link
Copy Markdown
Contributor

yf225 commented Jan 30, 2026

Yes I think once the auto-checkpoint feature is in, we can build on top of it to automatically trigger a checkpoint save when user hits Ctrl-C, which will also print instructions on how to resume from the saved checkpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants