Skip to content

Commit

Permalink
[tuner] Add abstractmethod in autotune.py. Create punet_autotune.py (#98
Browse files Browse the repository at this point in the history
)

- Rename variables/functions with "unet" in their names in `autotune.py`
and `test_autotune.py`
- Add class `TuningClient` and `DefaultTuningClient` in `autotune.py`
- Add `punet_autotune.py`
- Edit dir and path names in existing bash scripts

This PR generalized tuner by providing a basic python class API,
decoupled it from the specific model (i.e. punet). The final goal is to
make tuner support models other than SDXL.
  • Loading branch information
RattataKing authored Aug 19, 2024
1 parent 2415e86 commit 3ab8c65
Show file tree
Hide file tree
Showing 7 changed files with 721 additions and 563 deletions.
7 changes: 5 additions & 2 deletions tuning/benchmark_dispatch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ readonly NAME="$(basename "$INPUT" .mlir)"

# printf "Benchmarking $(basename ${INPUT}) on ${DEVICE}\n"

# Replace invalid characters in DEVICE variable
SANITIZED_DEVICE=$(echo "${DEVICE}" | sed 's/[^a-zA-Z0-9._-]/_/g')

timeout 16s ./tools/iree-benchmark-module --device="${DEVICE}" --module="${INPUT}" \
--hip_use_streams=true --hip_allow_inline_execution=true \
--batch_size=1000 --benchmark_repetitions=3 > "${DIR}/benchmark_log_${DEVICE}.out" 2>&1 || (mv "$INPUT" "${DIR}/benchmark_failed" && exit 0)
--batch_size=1000 --benchmark_repetitions=3 > "${DIR}/benchmark_log_${SANITIZED_DEVICE}.out" 2>&1 || (mv "$INPUT" "${DIR}/benchmark_failed" && exit 0)

MEAN_TIME="$(grep --text real_time_mean "${DIR}/benchmark_log_${DEVICE}.out" | awk '{print $2}')"
MEAN_TIME="$(grep --text real_time_mean "${DIR}/benchmark_log_${SANITIZED_DEVICE}.out" | awk '{print $2}')"
printf "%s\tMean Time: %.1f\n" "$(basename "$INPUT" .vmfb)" "$MEAN_TIME"
2 changes: 1 addition & 1 deletion tuning/tune.py → tuning/candidate_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from iree.compiler.dialects import _linalg_ops_gen, _util_ops_gen

"""
Usage: ./tune.py 121.mlir -o "tuning/candidates" -l 1024 --lhs-dims=mk --rhs-dims=nk --tile-dims=mnk
Usage: ./candidate_gen.py 121.mlir -o "tuning/candidates" -l 1024 --lhs-dims=mk --rhs-dims=nk --tile-dims=mnk
"""

tune_logger = logging.getLogger("tune")
Expand Down
4 changes: 2 additions & 2 deletions tuning/compile_candidate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ readonly DIR="$(dirname "$INPUT")"
readonly BASENAME="$(basename "$INPUT" .mlir)"
readonly OUT="${DIR}/compiled/${BASENAME}.vmfb"

mkdir -p "${DIR}/compiled" "${DIR}/failed" "${DIR}/configs"
mkdir -p "${DIR}/compiled" "${DIR}/failed" "${DIR}/specs"

timeout 4s ./punet.sh "$INPUT" -o "$OUT" --compile-from=executable-sources 2>/dev/null || (mv "$INPUT" "$DIR/failed" && exit 1)
tools/iree-dump-module "$OUT" | grep -q 'rocm-hsaco-fb' || (mv "$INPUT" "$DIR/failed" && rm -f "$OUT" && exit 1)
if [ -f "${DIR}/${BASENAME}_config.mlir" ]; then
cat "${DIR}/../config_prolog.mlir" "${DIR}/${BASENAME}_config.mlir" "${DIR}/../config_epilog.mlir" > "${DIR}/configs/${BASENAME}_spec.mlir"
cat "${DIR}/../config_prolog.mlir" "${DIR}/${BASENAME}_config.mlir" "${DIR}/../config_epilog.mlir" > "${DIR}/specs/${BASENAME}_spec.mlir"
fi
echo "Compiling ${INPUT}: success"
Loading

0 comments on commit 3ab8c65

Please sign in to comment.