aitune.torch.kernel_forge.kernel_optimizer
aitune.torch.kernel_forge.kernel_optimizer
Kernel optimizer based on module function kernel profiling.
Module Contents
Classes
Data
API
Profiles and replaces eligible torch.nn.functional kernels in a module.
make_plan(function, data, module=...) profiles forwards, starts asynchronous
generators, benchmarks static providers while generation runs, collects and
benchmarks generated candidates, and returns the selected runtime plan.
Run the common correctness validation and benchmark for one candidate.
Evaluate one completed generation result.
Evaluate generated candidates sequentially as their futures finish.
Prepare and benchmark all provider candidates while generators run.
Return dynamic generators supporting one function.
Return all available static and dynamic kernel sources.
Return sources supporting one function.
Log candidate latencies and their improvement over the baseline.
Log profiler results with markers for the selected kernel sources.
Evaluate kernel candidates and return the best providers.
All generator tasks are scheduled first. While asynchronous generation is running, candidates from static providers are prepared and benchmarked. Generated results are then collected and evaluated using the same validation and benchmarking path. Finally, the fastest candidate for each function is selected when it outperforms the original PyTorch function.
Parameters:
Collected input samples for each supported function.
Profiled functions in descending kernel-time order.
Profiled functions selected for static providers.
Profiled functions selected for asynchronous generators.
Returns: KernelOptimizationPlan
A runtime plan containing the fastest providers that outperform their baselines.
Return unique validation samples and a GCD-reduced benchmark distribution.
By dividing counters by the GCD of the counters, we can reduce the number of samples to a minimum while maintaining the same distribution.
Parameters:
the function data to prepare the provider samples for
Returns: tuple[list[Sample], list[Sample]]
a tuple of unique validation samples and a GCD-reduced benchmark distribution
Prepare each selected function’s samples exactly once.
Return static providers supporting one function.
Select the fastest valid candidate when it beats the single baseline measurement.
Select functions supported by a source and meeting its time-share threshold.
Submit all supported generator-function pairs before static work.
Return function names supported by providers or generators.
Return function names supported by a provider or generator.
Optimize a module by replacing eligible kernels with the best ones.
Parameters:
the function to run inference with
the data to use for optimization, if None the function will be called without arguments
the module whose hierarchy should be optimized. If omitted and function is an nn.Module,
function is used as the module.
Returns: KernelOptimizationPlan
A plan containing the selected runtime kernel providers.
Raises:
ValueError: If the module scope cannot be resolved.
Samples and accumulated candidates for one PyTorch function.
One submitted generator task and its expected function.
A kernel candidate.
The description of the candidate.
The latency of the candidate.
The selected runtime kernel provider.