Skip to content

Conversation

@RobotSail
Copy link
Member

@RobotSail RobotSail commented May 13, 2025

This PR fixes an issue where if we get 0% on a particular benchmark, the entire evaluation fails due to how the null check is currently being performed.

Signed-off-by: Oleg Silkin [email protected]

Summary by Sourcery

Improve the evaluation CLI by adding tasks support, new commands for single/evaluation and best-checkpoint discovery, refine output formatting, and correct a zero-score null-check bug

New Features:

  • Add 'find_best' subcommand to locate and compare leaderboard results across checkpoints

Bug Fixes:

  • Fix null check in get_score_by_metric to correctly handle zero scores

Enhancements:

  • Enhance CLI output formatting with percent scores, best-checkpoint labeling, and rich printing

@mergify mergify bot added the ci-failure label May 13, 2025
@RobotSail
Copy link
Member Author

@mergify rebase

Signed-off-by: Oleg Silkin <[email protected]>
@mergify
Copy link
Contributor

mergify bot commented Jun 2, 2025

rebase

✅ Branch has been successfully rebased

@RobotSail
Copy link
Member Author

@sourcery-ai review

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 8, 2025

Reviewer's Guide

This PR fixes the 0% benchmark failure by switching to an explicit None check in get_score_by_metric, and extends the evaluate_best_checkpoint CLI—renaming the main command, adding task filtering, enriching output formatting, and introducing two new subcommands for standalone evaluation and best‐checkpoint discovery.

Sequence diagram for the new 'evaluate' CLI command

sequenceDiagram
    actor User
    participant CLI as Typer CLI
    participant Evaluator as LeaderboardV2Evaluator
    participant FileSystem
    User->>CLI: Run 'evaluate' with input_dir and optional tasks
    CLI->>FileSystem: Check input_dir exists and is directory
    CLI->>Evaluator: Instantiate with input_dir, num_gpus, eval_config
    CLI->>Evaluator: Set tasks (if provided)
    CLI->>Evaluator: Call run()
    Evaluator-->>CLI: Return result
    CLI->>FileSystem: Write leaderboard_results.json
    CLI->>User: Print formatted results
Loading

Sequence diagram for the new 'find_best' CLI command

sequenceDiagram
    actor User
    participant CLI as Typer CLI
    participant FileSystem
    User->>CLI: Run 'find_best' with input_dir and show_all
    CLI->>FileSystem: Check input_dir exists and is directory
    CLI->>FileSystem: Find all leaderboard_results.json files
    loop For each result file
        CLI->>FileSystem: Read and parse JSON
        CLI->>CLI: Track best score and checkpoint
    end
    CLI->>User: Print best checkpoint and/or all results
Loading

Class diagram for updated CLI commands in evaluate_best_checkpoint.py

classDiagram
    class LeaderboardV2Evaluator {
        +tasks: list[str]
        +run()
    }
    class TyperApp {
        +best_checkpoint(input_dir, output_file, tasks)
        +evaluate(input_dir, tasks)
        +find_best(input_dir, show_all)
    }
    TyperApp --> LeaderboardV2Evaluator : uses
Loading

File-Level Changes

Change Details Files
Fix null‐check logic to handle zero scores correctly
  • Replaced falsy check with explicit 'is None' guard for extracted_value
  • Updated alias fallback to a default '[no-alias]' when none is provided
src/instructlab/eval/leaderboard.py
Refactor primary CLI entrypoint and add task filtering
  • Renamed 'main' command to 'best_checkpoint'
  • Added Annotated tasks option and propagate tasks to the evaluator
scripts/evaluate_best_checkpoint.py
Enhance CLI output with rich styling and per‐metric percentages
  • Enumerate sorted checkpoints and highlight the best with bold/green labels
  • Display overall and individual metric scores as percentages
  • Integrate rich print styling for headers and colored emphasis
scripts/evaluate_best_checkpoint.py
Add standalone 'evaluate' and 'find_best' subcommands
  • Implemented 'evaluate' to run a single-directory evaluation and dump JSON results
  • Implemented 'find_best' to scan subdirectories for leaderboard_results.json and compare scores
  • Added input-dir existence and type checks with proper exit on failure
scripts/evaluate_best_checkpoint.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @RobotSail - I've reviewed your changes - here's some feedback:

  • Factor out the repeated metric‐printing logic into a shared helper to avoid duplicating all those if "leaderboard_*" in result blocks across commands.
  • Add a descriptive help= string to the new tasks option and update the docstring for the best_checkpoint command (formerly main) to accurately describe its behavior.
  • Consider making num_gpus a configurable CLI option instead of hardcoding it to 8 to give users more flexibility.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Factor out the repeated metric‐printing logic into a shared helper to avoid duplicating all those `if "leaderboard_*" in result` blocks across commands.
- Add a descriptive `help=` string to the new `tasks` option and update the docstring for the `best_checkpoint` command (formerly `main`) to accurately describe its behavior.
- Consider making `num_gpus` a configurable CLI option instead of hardcoding it to 8 to give users more flexibility.

## Individual Comments

### Comment 1
<location> `scripts/evaluate_best_checkpoint.py:158` </location>
<code_context>
+    if "leaderboard_musr" in result:
+        print(f"MUSR: {result['leaderboard_musr']['score'] * 100:.2f}%")
+
+    output_file = input_dir / "leaderboard_results.json"
+    output_file.write_text(json.dumps(result, indent=2))
+
</code_context>

<issue_to_address>
Writing output file directly to input_dir may overwrite existing results.

Consider checking if 'leaderboard_results.json' already exists before writing, or allow users to specify a custom output path to avoid accidental overwrites.
</issue_to_address>

### Comment 2
<location> `src/instructlab/eval/leaderboard.py:254` </location>
<code_context>
             extracted_value = value
             break

-    if not extracted_value:
-        if alias := score_dict.get("alias", None):
+    if extracted_value is None:
+        if alias := score_dict.get("alias", "[no-alias]"):
</code_context>

<issue_to_address>
Changing the check from 'not extracted_value' to 'extracted_value is None' improves correctness.

This prevents valid falsy values from being misclassified as missing, improving edge case handling.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

if "leaderboard_musr" in result:
print(f"MUSR: {result['leaderboard_musr']['score'] * 100:.2f}%")

output_file = input_dir / "leaderboard_results.json"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Writing output file directly to input_dir may overwrite existing results.

Consider checking if 'leaderboard_results.json' already exists before writing, or allow users to specify a custom output path to avoid accidental overwrites.

Comment on lines -254 to -255
if not extracted_value:
if alias := score_dict.get("alias", None):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Changing the check from 'not extracted_value' to 'extracted_value is None' improves correctness.

This prevents valid falsy values from being misclassified as missing, improving edge case handling.



@app.command()
def find_best(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Low code quality found in find_best - 19% (low-code-quality)


ExplanationThe quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

@mergify mergify bot added ci-failure and removed ci-failure labels Jul 8, 2025
@mergify mergify bot removed the ci-failure label Jul 8, 2025
@RobotSail RobotSail merged commit 34e878c into instructlab:main Jul 8, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant