libtuner.py is the core Python script that provides the fundamental functions
for the tuning loop. It imports candidate_gen.py for candidate generation.
To implement the full tuning loop, libtuner.py requires a separate Python script
that uses the provided TuningClient API from libtuner.py.
cd amdsharktuner
python -m venv .venv
source .venv/bin/activateRuntime dependencies:
pip install -r requirements.txtNote
These dependencies include IREE packages
Development dependencies:
pip install -r requirements-dev.txt
pip install -r requirements-test.txtUninstall existing packages:
pip uninstall iree-base-compiler iree-base-runtime# Configure (include other options as needed)
cmake -G Ninja -B ../iree-build/ \
-DIREE_BUILD_PYTHON_BINDINGS=ON \
-DPython3_EXECUTABLE="$(which python3)" \
.
# Build
cmake --build ../iree-build/Important
Make sure to enable the ROCM and HIP in your cmake configuration. See IREE documentation for the details.
source ../iree-build/.env && export PYTHONPATH
export PATH="$(realpath ../iree-build/tools):$PATH"For more details, refer to the IREE Python bindings guide.
pip install --upgrade -r requirements-iree.txtFor a detailed explanation, see the IREE Tuning Overview.
-
Generate candidate specs
- Uses the Z3 solver to generate all potential tuning candidate configurations, where
libtunerapplies looser constraints than the IREE compiler. libtunershuffles the Z3 solutions using a default random seed (42) to prevent the search from getting trapped in a limited subtree.- You can control the randomization seed with
--search-space-shuffle-seed <SEED>, or use--enable-random-seedto apply a non-deterministic shuffle seed.
- Uses the Z3 solver to generate all potential tuning candidate configurations, where
-
Compile candidates
-
Benchmark
- Runs a baseline benchmark, executed serially across all specified devices.
- Runs candidate benchmarks in parallel across all devices.
By default,
libtunerautomatically sets the benchmark timeout for each candidate to the maximum baseline result. - Performs a second baseline run to check for regressions.
- Returns the top-performing candidate indices.
If no candidate outperforms the baseline, an empty list (
[]) is returned.
For a concrete example, check the model_tuner directory for a sample tuner implemented with libtuner.
The dispatch example should be a good starting point for most users.