Use AG2 to Tune ChatGPT
Python>=3.9
. To run this notebook example, please install
with the [blendsearch] option:
Note: For code corresponding to version <0.2, you can refer to the repository
autogen.ChatCompletion.tune
and to make a request with
the tuned config: autogen.ChatCompletion.create
. First, we import
autogen:
config_list_openai_aoai
function tries to create a list of Azure OpenAI endpoints and OpenAI
endpoints. It assumes the api keys and api bases are stored in the
corresponding environment variables or local txt files:
openai_api_key_file="key_openai.txt"
.aoai_api_key_file="key_aoai.txt"
. Multiple keys can be stored, one
per line.aoai_api_base_file="base_aoai.txt"
. Multiple bases can be stored,
one per line.cache_path_root
from “.cache” to a different path in set_cache()
.
The cache for different seeds are stored separately.
inference_budget
is the benchmark’s target average inference
budget per instance. For example, 0.004 means the target inference
budget is 0.004 dollars, which translates to 2000 tokens (input +
output combined) if the gpt-3.5-turbo model is used.optimization_budget
is the total budget allowed for tuning. For
example, 1 means 1 dollar is allowed in total, which translates to
500K tokens for the gpt-3.5-turbo model.num_sumples
is the number of different hyperparameter
configurations allowed to be tried. The tuning will stop after
either num_samples trials are completed or optimization_budget
dollars are spent, whichever happens first. -1 means no hard
restriction in the number of trials and the actual number is decided
by optimization_budget
.autogen.ChatCompletion.test
to evaluate the performance of
an entire dataset with the tuned config. The following code will take a
while (30 mins to 1 hour) to evaluate all the test data instances if
uncommented and run. It will cost roughly $3.