-
Notifications
You must be signed in to change notification settings - Fork 1
Change finetuning eval code to use single AsyncOpenAI Client #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -171,14 +171,10 @@ def load_hermes_dataset(max_samples=500): | |||||
| return samples | ||||||
|
|
||||||
|
|
||||||
| async def get_model_response_async(model, system_prompt, user_query, semaphore): | ||||||
| async def get_model_response_async(model, system_prompt, user_query, semaphore, client): | ||||||
| """Get OpenAI model response asynchronously with rate limiting.""" | ||||||
|
|
||||||
| async with semaphore: | ||||||
| client = AsyncOpenAI( | ||||||
| api_key=API_KEY, | ||||||
| base_url=BASE_URL, # Adjust if using a different endpoint | ||||||
| ) | ||||||
| messages = [] | ||||||
| if system_prompt: | ||||||
| messages.append({"role": "system", "content": system_prompt}) | ||||||
|
|
@@ -346,12 +342,12 @@ def print_model_summary(model, results): | |||||
| print(f"Format Valid: {format_valid:.3f}") | ||||||
|
|
||||||
|
|
||||||
| async def process_single_sample(sample: Dict[str, Any], model: str, semaphore: asyncio.Semaphore) -> Dict[str, Any]: | ||||||
| async def process_single_sample(sample: Dict[str, Any], model: str, semaphore: asyncio.Semaphore, client) -> Dict[str, Any]: | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new
Suggested change
|
||||||
| """Process a single sample asynchronously.""" | ||||||
|
|
||||||
| # Get model response | ||||||
| response = await get_model_response_async( | ||||||
| model, sample["system_prompt"], sample["user_query"], semaphore | ||||||
| model, sample["system_prompt"], sample["user_query"], semaphore, client | ||||||
| ) | ||||||
|
|
||||||
| # print(f"Sample {sample['id']} response: {response}") | ||||||
|
|
@@ -386,6 +382,12 @@ async def run_benchmark_async(eval_samples: List[Dict[str, Any]], models: List[s | |||||
|
|
||||||
| all_results = [] | ||||||
|
|
||||||
| # Create shared client for all requests | ||||||
| client = AsyncOpenAI( | ||||||
| api_key=API_KEY, | ||||||
| base_url=BASE_URL | ||||||
| ) | ||||||
|
Comment on lines
+385
to
+389
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The newly created shared async with AsyncOpenAI(
api_key=API_KEY,
base_url=BASE_URL
) as client: |
||||||
|
|
||||||
| for model in models: | ||||||
| print(f"\nEvaluating {model}...") | ||||||
| start_time = time.time() | ||||||
|
|
@@ -397,7 +399,7 @@ async def run_benchmark_async(eval_samples: List[Dict[str, Any]], models: List[s | |||||
| tasks = [] | ||||||
| for sample in eval_samples: | ||||||
| task = asyncio.create_task( | ||||||
| process_single_sample(sample, model, semaphore) | ||||||
| process_single_sample(sample, model, semaphore, client) | ||||||
| ) | ||||||
| tasks.append(task) | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better code clarity and maintainability, please add a type hint for the new
clientparameter. This function currently lacks type hints, and adding them, starting with the new parameter, would improve readability.