[fastcore][Feature Request] sort_by_run support numerical order

Currently fastcore’s [sort_by_run](https://github.com/fastai/fastcore/blob/4d5efa5c96f3f036e3ce54da8e5bdcc9e3c9855f/nbs/03_xtras.ipynb) only supports towards_end,run_before, and run_after. This has allows callbacks to be ordered, but requires the developer to always implement the correct run_before or run_after.

Add a numerical order concept similar to transforms, lower order goes first, higher order goes last. Default non-implmented order could be 15. towards_end could be 50, run_before and run_after could be target.order ±1. Exact implementation details left up to contributor.


  • Maybe this order logic could be shared between callbacks and transforms?
  • There is no towards_begin, maybe set this to a low number

Example where this would be useful: https://github.com/fastai/fastai/pull/2944
Instead of every callback needing to specify run_before, they could specify a very lower order. Numerical order allows for fine-tuned control.

1 Like

I can 100% agree to this, as callbacks can already run after transforms! One already runs after Normalize :slight_smile: