Skip to content

fix(calibrate): the per-type ECE of the report uses the choice bucket temperatures, as served - #24

Merged
rkinas merged 1 commit into
rkinas:mainfrom
agentGreg:fix/calibrate-type-ece-as-served
Oct 20, 2026
Merged

rkinas merged 1 commit into
rkinas:mainfrom
agentGreg:fix/calibrate-type-ece-as-served

Conversation

@agentGreg

@agentGreg agentGreg commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

For a calibration file 2 (prompt-format-2 models), basal-serve tempers a choice question with its option-count
bucket temperature before the type temperature (server.temperature). The type rows of the basal-calibrate report
measured "ECE on CERT shipped -> fitted" with the type temperature only:

ece_shipped=ece(served(cert, shipped_T)), ece=ece(served(cert, temps))

The bucket rows under it, the thresholds and the LOFO gate already pass the buckets. So the choice row disagrees
with the bucket row below it. On the 402 labelled decisions from #19 (basal-2.0-mini, shipped file,
--from-rows --report-only):

type        n   FIT  CERT  accuracy   temperature shipped -> fitted   ECE on CERT shipped -> fitted
choice    124    87    37     0.968   1.260 -> 0.738                  0.060 -> 0.027
  2-10        124          37             -> 0.738                        0.080 -> 0.027

0.060 is not what is served; 0.080 is.

Change

  • fit(): the type rows pass shipped_B / buckets to served(), like the bucket rows. For format 1 the buckets are
    empty, so nothing changes there.
  • CALIBRATION.md: one sentence that the ECE in the table uses the temperatures as basal-serve applies them.
  • tests/test_calibrate2.py::test_type_ece_uses_the_bucket_temperature_as_served: all choice rows in one bucket
    with a shipped bucket temperature that differs from the type temperature; the type row must equal the bucket row.
    It fails on main (0.123 vs 0.060) and passes here.

After the change the same report reads choice ... 0.080 -> 0.027, equal to the bucket row.

Verification

uv venv --python 3.12 ~/basal-dev-env && uv pip install --python ~/basal-dev-env/bin/python -e ".[test]"
~/basal-dev-env/bin/python -m pytest -q tests/test_calibrate.py tests/test_calibrate2.py tests/test_calibrate_gates.py \
  tests/test_calibrate_tasks.py tests/test_calibration2.py tests/test_calibration_orders.py
# 49 passed (48 on main + the new test)
~/basal-dev-env/bin/python -m pytest -q tests
# 539 passed, 18 skipped, 1 failed: tests/test_mlx.py::test_mlx_gemma4_equals_torch (0.00069 > 0.0002),
# which fails the same way on main on this Mac (Apple M5 Max, MLX 0.32.4, mlx-lm 0.32.2); unrelated
basal-calibrate rows_basal-2.0-mini.jsonl --from-rows --report-only    # the rows from #19: 0.060 -> 0.080

Refs #19

Summary by Sourcery

Measure calibration report ECE using the same temperature hierarchy that basal-serve applies.

Bug Fixes:

  • Make per-type calibration ECE reflect the bucket temperatures actually applied when serving format-2 choice questions, keeping type and bucket report rows consistent.

Enhancements:

  • Document that reported ECE uses temperatures as applied by basal-serve.

Documentation:

  • Clarify that choice-row ECE includes option-count bucket temperatures in calibration file 2.

Tests:

  • Add coverage verifying that type-level choice ECE matches the corresponding bucket ECE and differs from using only the type temperature.

… temperatures, as served

For calibration file 2 the type rows measured ECE with the type temperature only, while basal-serve applies a
choice question's option-count bucket temperature first (2.0-mini, 402 labelled decisions: choice 0.060 in the
type row, 0.080 as served and in the bucket row). test_calibrate2 checks that the type row equals the bucket row
when all choice questions fall in one bucket.
@sourcery-ai

sourcery-ai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR corrects calibration report type-level ECE to call the serving temperature logic with bucket temperatures, ensuring format-2 choice rows agree with their bucket rows and documenting the behavior. A focused regression test verifies the precedence and preserves format-1 behavior.

Sequence diagram for served temperatures in calibration ECE

sequenceDiagram
    participant Fit as fit()
    participant Served as served()
    participant ECE as ece()

    Fit->>Served: served(cert, shipped_T, shipped_B)
    Served-->>Fit: served CERT probabilities
    Fit->>ECE: ece(served CERT shipped)
    ECE-->>Fit: ece_shipped

    Fit->>Served: served(cert, temps, buckets)
    Served-->>Fit: served CERT probabilities
    Fit->>ECE: ece(served CERT fitted)
    ECE-->>Fit: ece

    alt format-2 choice question
        Served->>Served: apply option-count bucket temperature
        Served->>Served: apply type temperature
    else format-1 question
        Served->>Served: use type temperature
    end
Loading

File-Level Changes

Change Details Files
Make per-type ECE calculations match the temperatures actually applied by serving.
  • Pass shipped bucket temperatures into shipped ECE calculations.
  • Pass fitted bucket temperatures into fitted ECE calculations while retaining existing format-1 behavior through empty buckets.
  • Document that report ECE uses basal-serve temperature precedence, including choice option-count buckets.
basal/calibrate.py
docs/CALIBRATION.md
Add regression coverage for format-2 choice rows using bucket temperatures.
  • Construct a single-bucket choice dataset with distinct type and bucket temperatures.
  • Assert type-row ECE matches the bucket-row ECE for shipped and fitted values.
  • Verify the result differs from ECE calculated with the type temperature alone.
tests/test_calibrate2.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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@rkinas
rkinas merged commit 63c0638 into rkinas:main Oct 20, 2026
1 check passed
@rkinas

rkinas commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Thanks! Merged for basal 2.3.1. The per-type ECE line now uses the temperatures as basal-serve applies them, and your test fails on 2.3.0 and passes now. You are credited in the 2.3.1 release notes.

rkinas added a commit that referenced this pull request Oct 20, 2026
rkinas added a commit that referenced this pull request Oct 21, 2026
…) into 2.3.1

# Conflicts:
#	docs/WHATS_NEW.md
rkinas added a commit that referenced this pull request Nov 2, 2026
The short README drops its sections for 2.4.1 back to 2.0 and its previous-releases text. What they had and
WHATS_NEW.md did not moves here: the 2.4.1 H100 start-up numbers, the 2.3.x community credits for #18, #21, #24
and #25, the precise 2.3 eager baselines, the 2.2 calibration summary and example, the release-note links for
2.1 to 2.3, and basal-1.5 / basal-1.0 under 'Previous releases'.
@agentGreg
agentGreg deleted the fix/calibrate-type-ece-as-served branch November 16, 2026 19:55
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.

2 participants