Skip to content

fix(calibrate): a Hugging Face snapshot is recorded as its repo id and commit - #71

Merged
rkinas merged 2 commits into
rkinas:mainfrom
pawelkiszczak:pr/calibrate-snapshot-identity
Nov 2, 2026
Merged

rkinas merged 2 commits into
rkinas:mainfrom
pawelkiszczak:pr/calibrate-snapshot-identity

Conversation

@pawelkiszczak

@pawelkiszczak pawelkiszczak commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #70

What

  • basal-calibrate records the model as model_identity(--model, md) — the pair it already used for fitted_on.revision — instead of the --model argument as given: a Hugging Face cache snapshot directory becomes its repo id and commit, as basal-serve's calibration_mismatch names the served model. Both the in-process path and --url with --model (basal/calibrate.py).
  • docs/WHATS_NEW.md: a bullet under # Unreleased.

Why

A file fitted on --model <cache>/models--Remek--x/snapshots/<commit> recorded the path; basal-serve serving that snapshot warned that it was fitted on another model (the last path segment is the commit, not the name) and refused it under --strict-calibration.

Compatibility

Repo ids resolve to the same snapshot and were already recorded as the repo id; plain directories and --url without --model are recorded exactly as before (model_identity returns the name as given and no revision). Only snapshot paths change, from the path to <org>/<name> + revision.

Tests run

  • tests/test_calibrate.py::test_a_cache_snapshot_is_recorded_as_its_repo_id_and_commit (snapshot and plain directory; the snapshot case fails without the fix: fitted_on.model was the path) — the written file is then loaded by Server with --strict-calibration, no mismatch.
  • Real model (Apple Silicon, --mode mps): basal-calibrate basal/examples/questions.jsonl --model <HF cache>/models--Remek--basal-2.0-mini/snapshots/cb81b32… writes fitted_on.model = "Remek/basal-2.0-mini", revision = "cb81b32…"; Server(--name Remek/basal-2.0-mini --model <snapshot> --calibration FILE --strict-calibration) loads it, cal_mismatch None.
  • uv run --no-sync pytest -q -x — 763 passed, 53 skipped, 1 warning.
  • uvx [email protected] check --select E9,F63,F7,F82 --target-version py310 . — only the existing F821 Undefined name kpos in untouched basal/gemma4.py:471.

Summary by Sourcery

Fix calibration model identity recording so Hugging Face cache snapshots are accepted by strict serving checks.

Bug Fixes:

  • Record Hugging Face cache snapshot models by repository ID and commit so calibration files match the model identity used by basal-serve, including URL-based calibration.
  • Preserve existing calibration identity behavior for repository IDs and plain local directories.

Documentation:

  • Document Hugging Face snapshot identity handling and add the change to the unreleased notes.

Tests:

  • Add coverage confirming snapshot calibrations pass strict model matching while plain directories retain their existing identity.

@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR fixes calibration metadata to record Hugging Face cache snapshots using the same repo ID and commit identity that basal-serve uses, while retaining existing behavior for repo IDs, plain directories, and URL-only flows. It updates both calibration execution paths, adds strict-calibration regression coverage, and documents the change.

Sequence diagram for calibration model identity recording

sequenceDiagram
    participant Calibrate as basal-calibrate
    participant Resolve as resolve
    participant Identity as model_identity
    participant File as Calibration file
    participant Server as basal-serve

    Calibrate->>Resolve: resolve(a.model, a.revision, metadata_only=True)
    Resolve-->>Calibrate: model metadata
    Calibrate->>Identity: model_identity(a.model, metadata)
    Identity-->>Calibrate: repo_id, revision
    Calibrate->>File: write fitted_on.model and fitted_on.revision
    Server->>File: load calibration
    Server->>Identity: model_identity(served_model, server_metadata)
    Identity-->>Server: repo_id, revision
    Server-->>File: strict calibration matches
Loading

File-Level Changes

Change Details Files
Normalize recorded model identity consistently for in-process and URL calibration flows.
  • Use model_identity to derive both model name and revision when metadata is available.
  • Preserve existing fallback behavior for URL-only, repo-id, and plain-directory inputs.
  • Ensure Hugging Face cache snapshots record as repo ID plus commit rather than the cache path.
basal/calibrate.py
Add regression coverage for snapshot identity and strict calibration compatibility.
  • Test snapshot paths produce the expected repo ID and commit.
  • Verify plain directories retain their path and omit revision.
  • Load the generated calibration with Server strict-calibration and assert no mismatch or warning.
tests/test_calibrate.py
Document the corrected Hugging Face snapshot recording behavior.
  • Add an Unreleased note covering both local and URL-based calibration paths and compatibility behavior.
docs/WHATS_NEW.md

Assessment against linked issues

Issue Objective Addressed Explanation
#70 When calibrating with a Hugging Face cache snapshot path, record the snapshot's repo ID as fitted_on.model and its commit as fitted_on.revision. ✅
#70 Ensure calibration files produced from a snapshot are accepted by basal-serve for that snapshot under --strict-calibration, without a mismatch warning. ✅
#70 Preserve existing fitted-model identity behavior for repo IDs, plain directories, and --url calibration without --model. ✅

Possibly linked issues


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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="basal/calibrate.py" line_range="1367" />
<code_context>
         baseline, base_file = compared(srv.md, srv.kind, a.calibration, quant, orders, a.no_calibration, preset,
                                        a.layout)
-        model, revision = a.model, model_identity(a.model, srv.md)[1]
+        model, revision = model_identity(a.model, srv.md)
         engine = mode + (f" --quant {a.quant}" if a.quant else "") + (f" --gguf {Path(a.gguf).name}" if a.gguf else "") \
             + (f" --vllm-preset {preset}" if preset not in (None, "default") else "")
</code_context>
<issue_to_address>
**Calibration docs promise original path**

When `--model` points to a Hugging Face cache snapshot directory, `model_identity` stores the repo id instead of the supplied snapshot path, contradicting the guide and leaving users or consumers that rely on the documented `fitted_on.model` value with a different identity than promised.

Update the calibration guide to explain that snapshot paths are recorded as their repo id and commit.

Also at `basal/calibrate.py:1348`.
</issue_to_address>

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

Comment thread basal/calibrate.py Resolved
@rkinas

rkinas commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Thank you, Paweł! Planned for basal 2.5: we are merging it into the 2.5 release branch now, after our checks (full CPU suite, your tests, serving code unchanged). The PR will close when 2.5 is published on main.

@rkinas
rkinas merged commit 55ff848 into rkinas:main Nov 2, 2026
1 check passed
rkinas added a commit that referenced this pull request Nov 2, 2026
… version

CONTRIBUTING.md credits the 2.5 pull requests as the release notes' community line lists them (Paweł Kiszczak
#52, #62, #64, #66, #68, #71, #73, #75; Marcin Brzeżański #56; Grzegorz Brzezinka #76, #78) and adds Dariusz
Koryto (#53, #58, #59, #60 and #55); the README's list names him too. docs/changes/README.md and the
changelog.py help use 2.5.1, the next release, as the example.
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.

basal-calibrate on a cache snapshot writes a file basal-serve calls another model's

2 participants