Skip to content

Latest commit

 

History

History
103 lines (75 loc) · 3.13 KB

File metadata and controls

103 lines (75 loc) · 3.13 KB

amdshark Tuner

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.


Prerequisites

[Optional] Using virtual environments:

cd amdsharktuner
python -m venv .venv
source .venv/bin/activate

Install python dependencies:

Runtime dependencies:

pip install -r requirements.txt

Note

These dependencies include IREE packages

Development dependencies:

pip install -r requirements-dev.txt
pip install -r requirements-test.txt

IREE's Python bindings setup:

Option 1: Using local IREE Python bindings

Configuring python

Uninstall existing packages:

pip uninstall iree-base-compiler iree-base-runtime

Build with CMake

# 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.

Extend environment variables

source ../iree-build/.env && export PYTHONPATH
export PATH="$(realpath ../iree-build/tools):$PATH"

For more details, refer to the IREE Python bindings guide.


Option 2: Using nightly IREE Python bindings

pip install --upgrade -r requirements-iree.txt

Tuning Algorithm

For a detailed explanation, see the IREE Tuning Overview.

  1. Generate candidate specs

    • Uses the Z3 solver to generate all potential tuning candidate configurations, where libtuner applies looser constraints than the IREE compiler.
    • libtuner shuffles 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-seed to apply a non-deterministic shuffle seed.
  2. Compile candidates

  3. Benchmark

    • Runs a baseline benchmark, executed serially across all specified devices.
    • Runs candidate benchmarks in parallel across all devices. By default, libtuner automatically 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.

Examples

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.