Here we implement an autotuner for tuning hardware and software parameters of large-scale high performance computing (HPC) applications using OpenAI's GPT-4 language model. The system iteratively refines parameter configurations based on performance feedback to optimize for execution time.
Optimizing hardware and software parameters for HPC applications can be a complex and time-consuming task due to the vast number of possible configurations. This project aims to automate the tuning process by leveraging OpenAI's GPT-4 language model to suggest optimal parameter settings based on iterative performance feedback.
The system consists of several modules that work together in a feedback loop:
- Prompt Generator: Creates prompts for the LLM based on previous performance and parameters.
- Option Evaluator: Parses the LLM responses to extract new parameter values.
- Safety Enforcer: Ensures the suggested parameters are safe and valid.
- Performance Analyzer: Compiles and runs FFmpeg with the given parameters and measures performance.
- Main Script: Orchestrates the tuning process.
- Python 3.7 or higher
- OpenAI Python library (
openai
) - FFmpeg source code (Download and extract to
ffmpeg_source/
directory) - GCC compiler and build tools (
make
,gcc
, etc.) - An input video file
input.mp4
in the parent directory offfmpeg_source/
- OpenAI API key (with access to GPT-4 model)
Ensure you have pip
installed. Then install the OpenAI Python library:
pip install openai
Obtain your OpenAI API key from OpenAI's website and set it as an environment variable:
export OPENAI_API_KEY='your-api-key'
Alternatively, you can set the OPENAI_API_KEY
variable directly in config.py
.
Download the FFmpeg source code from https://ffmpeg.org/download.html and extract it to the ffmpeg_source/
directory.
Example using wget
:
wget https://ffmpeg.org/releases/ffmpeg-4.4.tar.gz
tar -xzf ffmpeg-4.4.tar.gz
mv ffmpeg-4.4 ffmpeg_source
Place an input video file named input.mp4
in the parent directory of ffmpeg_source/
. Alternatively, adjust the file path in performance_analyzer.py
to point to your video file.
Example:
cp /path/to/your/video.mp4 ./input.mp4
Make sure you have the necessary build tools installed (gcc
, make
, etc.).
On Debian/Ubuntu-based systems:
sudo apt update
sudo apt install build-essential
Edit the config.py
file to adjust any configuration settings if necessary. You can add or remove parameters to tune, set the maximum number of iterations, and adjust other settings.
Adjusting system parameters requires sudo privileges. You may need to run the main script with sudo:
sudo python main.py
Alternatively, you can configure your sudoers
file to allow your user to execute sysctl
commands without a password. Be cautious when editing the sudoers
file to avoid security risks.
To start the tuning process, run the main script:
sudo python main.py
The script will perform the following steps:
- Generate a prompt for the LLM based on previous parameters and performance.
- Use GPT-4 to suggest new parameter values.
- Evaluate the LLM's suggestions for safety and validity.
- Apply the new system parameters.
- Compile FFmpeg with the new compiler flags.
- Run FFmpeg and measure its performance.
- Compare the performance with previous iterations.
- Repeat the process for the specified number of iterations or until no further improvements are found.
1. config.py
Configuration settings and lists of parameters.
Generates prompts for the LLM based on previous performance and parameters.
Parses the LLM responses to extract new parameter values.
Ensures the suggested parameters are safe and valid.
Compiles FFmpeg with new compiler flags, sets system parameters, runs FFmpeg, and measures performance.
6. main.py
The main script that orchestrates the tuning process.