[Fix] Use seeded random.Random for dataset shuffling#1243
[Fix] Use seeded random.Random for dataset shuffling#1243pcabriada wants to merge 4 commits intomodelscope:mainfrom
Conversation
…mpat) Python 3.12 removed the deprecated second argument from random.shuffle(). LocalDataLoader.load() and DictDataLoader.load() both passed self.seed as the second argument, causing TypeError on Python 3.12+. Replace with random.Random(seed).shuffle(dataset) when a seed is provided, falling back to unseeded random.shuffle() when seed is None. RemoteDataLoader is unaffected (uses HuggingFace Dataset.shuffle(seed=...)). Added tests/test_loader_shuffle.py covering seeded shuffle, unseeded shuffle, reproducibility, and a guard confirming the original call fails on 3.12+. Made-with: Cursor
Summary of ChangesHello, 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 addresses a compatibility issue with Python 3.12 by updating how datasets are shuffled within Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request correctly fixes a TypeError when shuffling datasets on Python 3.11+ by using random.Random(seed).shuffle() for seeded shuffles. The changes in evalscope/api/dataset/loader.py are correct. The new test file tests/test_loader_shuffle.py provides good coverage for the fix, including checks for reproducibility. I've made a couple of suggestions for improvement: one to refactor duplicated code into a helper function for better maintainability, and another to correct the Python version check in a test case.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Address reviewer feedback: extract the shuffle logic shared by LocalDataLoader.load() and DictDataLoader.load() into a private module-level helper function. Made-with: Cursor
…briada/evalscope into bugfix/fix-shuffle-python312
Python 3.12 removed the deprecated second argument from random.shuffle(). LocalDataLoader.load() and DictDataLoader.load() both passed self.seed as the second argument, causing TypeError on Python 3.12+.
Replace with random.Random(seed).shuffle(dataset) when a seed is provided, falling back to unseeded random.shuffle() when seed is None.
RemoteDataLoader is unaffected (uses HuggingFace Dataset.shuffle(seed=...)).
Added tests/test_loader_shuffle.py covering seeded shuffle, unseeded shuffle, reproducibility, and a guard confirming the original call fails on 3.12+.