-
Notifications
You must be signed in to change notification settings - Fork 289
add gsmk test script #1136
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?
add gsmk test script #1136
Conversation
Summary of ChangesHello @sufubao, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request adds a comprehensive benchmarking script for the LightLLM API, specifically targeting its performance on the GSM8K mathematical reasoning dataset. The script streamlines the process of data acquisition, prompt engineering with few-shot examples, parallel execution of API requests, and detailed performance analysis, including accuracy and latency metrics. This addition is crucial for systematically evaluating and monitoring the model's capabilities in solving complex math problems. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a new test script for benchmarking the GSM8K task. The script is well-structured, leveraging ThreadPoolExecutor for concurrent requests and tqdm for progress indication. My review focuses on improving the script's robustness, portability, and maintainability. Key suggestions include properly handling the --data-path argument, avoiding hardcoded paths for better portability, adding type hints for clarity, and refining some implementation details for better adherence to Python best practices.
|
|
||
| # Read data | ||
| url_data = "https://raw.githubusercontent.com/openai/grade-school-math/master/grade_school_math/data/test.jsonl" | ||
| filename = download_and_cache_file(url_data) |
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.
The --data-path command-line argument is defined but is not being used. The script currently ignores it and always attempts to download the data. To allow users to specify a local data file or a custom cache path, you should pass this argument to the download_and_cache_file function.
| filename = download_and_cache_file(url_data) | |
| filename = download_and_cache_file(url_data, args.data_path) |
| def download_and_cache_file(url: str, filename: Optional[str] = None): | ||
| """Read and cache a file from a url.""" | ||
| if filename is None: | ||
| filename = os.path.join("/tmp", url.split("/")[-1]) |
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.
Hardcoding the /tmp directory is not portable and will fail on non-Unix systems like Windows. It's better to use the tempfile module to get the path to the system's temporary directory. You'll need to add import tempfile at the top of the file.
| filename = os.path.join("/tmp", url.split("/")[-1]) | |
| filename = os.path.join(tempfile.gettempdir(), url.split("/")[-1]) |
| return filename | ||
|
|
||
|
|
||
| def call_generate_lightllm(prompt, temperature, max_tokens, stop=None, url=None): |
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.
Adding type hints to function signatures improves code clarity, makes it easier to understand for other developers, and enables static analysis tools to catch potential bugs.
| def call_generate_lightllm(prompt, temperature, max_tokens, stop=None, url=None): | |
| def call_generate_lightllm(prompt: str, temperature: float, max_tokens: int, stop: Optional[list] = None, url: Optional[str] = None) -> str: |
|
|
||
| def call_generate_lightllm(prompt, temperature, max_tokens, stop=None, url=None): | ||
| """Call LightLLM API for text generation.""" | ||
| assert url is not None |
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.
Using assert for input validation is not ideal, as assertions can be disabled in optimized builds (e.g., running with python -O). It's more robust to raise a ValueError to ensure the check is always performed.
| assert url is not None | |
| if url is None: | |
| raise ValueError("The 'url' parameter must be provided.") |
| ret = "Question: " + lines[i]["question"] + "\nAnswer:" | ||
| if include_answer: | ||
| ret += " " + lines[i]["answer"] | ||
| return ret |
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.
Using f-strings is generally more readable and can be more performant than repeated string concatenation with +.
| ret = "Question: " + lines[i]["question"] + "\nAnswer:" | |
| if include_answer: | |
| ret += " " + lines[i]["answer"] | |
| return ret | |
| ret = f"Question: {lines[i]['question']}\nAnswer:" | |
| if include_answer: | |
| ret += f" {lines[i]['answer']}" | |
| return ret |
| ret = "" | ||
| for i in range(k): | ||
| ret += get_one_example(lines, i, True) + "\n\n" | ||
| return ret |
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.
Building a string in a loop using += can be inefficient for a large number of iterations. A more Pythonic and performant approach is to use a generator expression with str.join().
| ret = "" | |
| for i in range(k): | |
| ret += get_one_example(lines, i, True) + "\n\n" | |
| return ret | |
| return "".join(get_one_example(lines, i, True) + "\n\n" for i in range(k)) |
| print(f"Latency: {latency:.3f} s") | ||
|
|
||
| # Dump results | ||
| dump_state_text("tmp_output_lightllm.txt", states) |
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.
| "other": { | ||
| "num_questions": args.num_questions, | ||
| "parallel": args.parallel, | ||
| }, |
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.
No description provided.