-
Notifications
You must be signed in to change notification settings - Fork 453
[Feat] fix tasks and vllm to reproduce better results. #774
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
Changes from 12 commits
85e3984
2d77ad6
a77a4fc
917b05f
972187c
384e22a
e91efa7
b3fede5
84517d4
4909b13
8369252
62c9a6a
8e68a18
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||
| import pandas as pd | ||||||
| import requests | ||||||
| from loguru import logger as eval_logger | ||||||
| from openai import AzureOpenAI, OpenAI | ||||||
| from tqdm import tqdm | ||||||
|
|
||||||
| DEMO_PROMPT_EXTRACT = """ | ||||||
|
|
@@ -74,67 +75,45 @@ | |||||
|
|
||||||
| class MathVerseEvaluator: | ||||||
| API_TYPE = os.getenv("API_TYPE", "openai") | ||||||
|
|
||||||
| if API_TYPE == "openai": | ||||||
| API_URL = os.getenv("OPENAI_API_URL", "https://api.openai.com/v1/chat/completions") | ||||||
| API_KEY = os.getenv("OPENAI_API_KEY", "YOUR_API_KEY") | ||||||
| headers = { | ||||||
| "Authorization": f"Bearer {API_KEY}", | ||||||
| "Content-Type": "application/json", | ||||||
| } | ||||||
| client = OpenAI(api_key=API_KEY, base_url=API_URL.rstrip("chat/completions")) | ||||||
|
Contributor
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. Incorrect use of The Use - client = OpenAI(api_key=API_KEY, base_url=API_URL.rstrip("chat/completions"))
+ client = OpenAI(api_key=API_KEY, base_url=API_URL.removesuffix("/chat/completions"))Or for older Python versions: - client = OpenAI(api_key=API_KEY, base_url=API_URL.rstrip("chat/completions"))
+ base_url = API_URL[:-len("/chat/completions")] if API_URL.endswith("/chat/completions") else API_URL
+ client = OpenAI(api_key=API_KEY, base_url=base_url)📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.12.2)85-85: Using (B005) 🤖 Prompt for AI Agents |
||||||
|
|
||||||
| elif API_TYPE == "azure": | ||||||
| API_URL = os.getenv("AZURE_ENDPOINT", "https://api.cognitive.microsoft.com/sts/v1.0/issueToken") | ||||||
| API_KEY = os.getenv("AZURE_API_KEY", "YOUR_API_KEY") | ||||||
| headers = { | ||||||
| "api-key": API_KEY, | ||||||
| "Content-Type": "application/json", | ||||||
| } | ||||||
| API_VERSION = os.getenv("AZURE_API_VERSION", "2023-07-01-preview") | ||||||
| client = AzureOpenAI(azure_endpoint=API_URL, api_version=API_VERSION, api_key=API_KEY) | ||||||
| gpt_model = os.getenv("MODEL_VERSION", "gpt-4o-2024-11-20") | ||||||
|
|
||||||
| def __init__(self, api_key, gpt_model="gpt-3.5-turbo", quick_extract=False): | ||||||
| self.api_key = api_key | ||||||
| self.gpt_model = gpt_model | ||||||
| def __init__(self, quick_extract=False): | ||||||
| self.quick_extract = quick_extract | ||||||
|
|
||||||
| def _post_request(self, payload): | ||||||
| headers = { | ||||||
| "Authorization": f"Bearer {self.api_key}", | ||||||
| "Content-Type": "application/json", | ||||||
| } | ||||||
| response = requests.post(self.API_URL, headers=headers, json=payload, timeout=30) | ||||||
| response.raise_for_status() | ||||||
| return response.json() | ||||||
|
|
||||||
| def get_chat_response(self, prompt, temperature=0, max_tokens=256, n=1, patience=10000000, sleep_time=0): | ||||||
| def get_chat_response(self, prompt, temperature=0, max_tokens=256, n=1, patience=5, sleep_time=0): | ||||||
| messages = [ | ||||||
| {"role": "user", "content": prompt}, | ||||||
| ] | ||||||
| payload = {"model": self.gpt_model, "messages": messages, "temperature": temperature, "max_tokens": max_tokens, "n": n} | ||||||
| payload = {"model": self.gpt_model, "messages": messages, "temperature": temperature, "max_tokens": max_tokens} | ||||||
|
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. Bug: API Type Mismatch Causes Undefined AttributeThe Locations (1) |
||||||
|
|
||||||
| while patience > 0: | ||||||
| patience -= 1 | ||||||
| try: | ||||||
| response = self._post_request(payload) | ||||||
| response = self.client.chat.completions.create(**payload) | ||||||
| if n == 1: | ||||||
| prediction = response["choices"][0]["message"]["content"].strip() | ||||||
| prediction = response.choices[0].message.content.strip() | ||||||
| if prediction and prediction != "": | ||||||
| return prediction | ||||||
| else: | ||||||
| prediction = [choice["message"]["content"].strip() for choice in response["choices"]] | ||||||
| prediction = [choice.message.content.strip() for choice in response.choices] | ||||||
| if prediction and prediction[0] != "": | ||||||
| return prediction | ||||||
|
|
||||||
| except Exception as e: | ||||||
| # some model may output repetitive answer, which ChatGPT will throw an error. | ||||||
| if "repetitive patterns" in str(e): | ||||||
| print(str(e)) | ||||||
| print("Continue with empty answer") | ||||||
| return "" | ||||||
| # some answer may contain some sensitive words, like 'test' | ||||||
| if "sensitive" in str(e) or "400" in str(e): | ||||||
| print(str(e)) | ||||||
| print("Continue with empty answer") | ||||||
| return "0" | ||||||
|
|
||||||
| if "Rate limit" not in str(e): | ||||||
| eval_logger.error(e) | ||||||
|
|
||||||
|
|
||||||
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.
Bug: Duplicate and conflicting chat_template initialization.
The
self.chat_templateis assigned the parameter value on line 166 but then immediately set toNoneon line 173, discarding the initial assignment. This appears to be an error.Remove the redundant assignment:
self.model = model self.max_frame_num = max_frame_num - self.chat_template = chat_template self.min_image_pixels = min_image_pixels self.data_parallel_size = data_parallel_size # Qwen 2/2.5-VL models enforce minimum image dimensions self._enforce_image_resize = self._is_qwen_vl_model(model) # Load chat template during initialization self.chat_template = None📝 Committable suggestion
🤖 Prompt for AI Agents