Skip to content

Musiq technical - #39

Open
sgoggins wants to merge 16 commits into
mainfrom
musiq-technical
Open

sgoggins wants to merge 16 commits into
mainfrom
musiq-technical

Conversation

@sgoggins

@sgoggins sgoggins commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Changeset

  • MUSIQ in the technical score.
    • Google Research's MUSIQ (KonIQ-10k checkpoint, Apache-2.0) now runs in Go through ONNX Runtime (internal/ml/musiq.go), at 512 px.
    • It is blended with archivis's own measurements in the same quadratic ridge as today's rating (quality.RateWith, rating_musiq_model.json), fit on BIQ2021 train only (tools/musiq/FIT.md).
  • The model file is converted by tools/musiq/export_onnx.py.
    • It is published as the pre-release musiq-koniq-1 and mirrored in deps after merge (tools/deps/assets.txt).
    • archivis setup downloads it and checks it against its pinned SHA-256.
    • Without the model, everything works as before.
  • Storage and indexing:
    • The score is kept in the new nullable column photos.musiq.
    • Indexing scores new photos.
    • Photos scored by MUSIQ get their own penalty strengths (quality.TechnicalWithMUSIQ).
  • Older photos:
    • archivis quality status | backfill [--for D] [--workers N] scores them all at once, and can be stopped and resumed.
    • index --backfill D does it after the nightly index.
    • Each file is read again. The update is seq-guarded, and groups and folders are marked stale.
  • DEPLOY:
    • The nightly jobs pass --backfill 2h, with a CI-tested snippet to add it to existing jobs.
    • A new "Technical score and MUSIQ" section.
    • An update note.
  • Benchmark and fit tooling: tools/musiq/ (port, benchmark RESULTS.md, fit FIT.md) and validate quality -models.

Notes

  • Accuracy (BIQ2021 test, 2,000 photos never used for fitting, Spearman with people, through the Go/ONNX path, 95% bootstrap CIs):

    Score Spearman
    Technical, today 0.627 [0.597, 0.655]
    MUSIQ alone 0.753 [0.729, 0.775]
    Rating with MUSIQ 0.777 [0.756, 0.796]
    Technical with MUSIQ (shipped for scored photos) 0.768 [0.746, 0.788], paired +0.141 [+0.123, +0.159]
  • Penalties retuned for MUSIQ-scored photos on tuning data only (BIQ2021 train plus 80 ladder photos), by tune_penalties.py's rule: the strongest that cost ≤ 0.01. Result: exposure 0.1, colour 0, compression 0.1 (unscored photos keep 0.1 / 0.1 / 0.2, which the same run re-chooses).

    • They cost 0.009; today's strengths would have cost 0.028.
    • Held-out ladder (73 photos), against today's technical:
      • better on over-exposure (AUC 0.74 vs 0.55 at +2 EV), JPEG (0.81 vs 0.69 at q8), blur and motion blur;
      • colour casts no longer lower technical (0.47 vs 0.52–0.59), because a 0.1 colour penalty alone costs 0.014. Casts stay flagged by the colour score and badge;
      • slightly weaker on under-exposure, noise and haze.
    • Full tables: tools/musiq/FIT.md; summary in VALIDATION.md.
  • Cost: MUSIQ adds about 0.55 CPU-s per photo at 512 px. The backfill reads each file again, several at once.

  • CI fixes since the first run:

    • The model tests 404'd because they ran before the release was published.
    • TestMUSIQSequenceMatchesReference failed on macOS arm64, because Go fused multiply-adds in the Gaussian resize. Fixed in ca4a428 with explicit float32 rounding; the arm64 build of the preprocessing now has no FMA instructions.

Related issues/PRs

https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d


Generated by Claude Code

…harness

Measurement only; no change to archivis's shipped code. Results to follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
… resumable chunked scoring

score.py: -limit N for chunked foreground runs, per-row flush, -long-edge
for scoring a downscaled copy. bench.py: paired bootstrap CI of the
difference vs archivis, CLIP + koniq aesthetic blend, corrected AVA
test-list note. results/: bench output, results.csv, speed.csv.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ax1TWsEkWVQpqJ5rWDKUTK
…caffolding

- tools/musiq/export_onnx.py exports the KonIQ checkpoint with a fixed
  449-token input (images up to 512 px), checked against the port to
  within 5e-5; make_fixture.py writes the Go tests' reference.
- ml.MUSIQ mirrors Google's preprocessing (Gaussian resize, 32-px
  patches, hashed positions, scale ids, padding) and runs the model;
  token-for-token and score parity tests against the port.
- setup downloads musiq/koniq.onnx (pinned; mirrored in deps).
- photos.musiq (nullable) holds the score.
- quality.RatingImage / RateWith, and rating_musiq_model.json, for now a
  placeholder equal to today's rating until it is fit on BIQ2021
  (fit_quality.py --export-musiq, from `validate quality -models`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
- Indexing scores each photo with MUSIQ at the rating's 512 px, stores
  the score and rates with quality.RateWith; without the model, the
  measurements' rating as before (indexer.Rating).
- indexer.BackfillMUSIQ scores photos indexed before MUSIQ was installed:
  each file decoded again, technical and overall worked out as indexing
  would from the stored exposure/colour scores, blockiness and aesthetic
  score; seq-guarded, groups and folders marked stale, stops at a
  deadline or on Ctrl-C and resumes; missing files are retried next time.
- `archivis quality status | backfill [--for D]`, and `index --backfill D`
  after the nightly index. The model loads only if installed.
- DEPLOY: the nightly jobs pass --backfill 2h, with a tested snippet to add
  it to existing jobs (CI step), a "Technical score and MUSIQ" section,
  and the update note.

TestMUSIQRatingModelIsFitted and TestRateWithFollowsMUSIQ fail until the
blend fit on BIQ2021 replaces the placeholder model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
Reading the file dominates a backfill (about a second per photo), so
workers photos are decoded and scored at once (quality backfill
--workers, half the cores by default; index --backfill uses half its
workers). Photos not started when the time is up stay for the next run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
rating_musiq_model.json is now fit on BIQ2021 train (9,999 photos):
archivis's measurements plus MUSIQ koniq (Go/ONNX, 512 px) in the shipped
quadratic ridge. On the 2,000-photo test split it reaches Spearman 0.777
[0.755, 0.796] vs 0.632 for today's rating (+0.145 [+0.127, +0.164]).
Technical's penalties cost 0.028 on top of it (0.749). Numbers, commands
and the model's SHA-256 in tools/musiq/FIT.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
quality.TechnicalWithMUSIQ applies the exposure, colour and compression
penalties with their own strengths, which indexing and the backfill use
when MUSIQ scored the photo. For now they equal today's; they are being
tuned for the MUSIQ rating on tuning data (tools/musiq/FIT.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
@sgoggins sgoggins added the enhancement New feature or request label Nov 26, 2026
# Conflicts:
#	DEPLOY.md
#	cmd/archivis/main.go
On arm64 Go fuses a multiply and an add into one instruction, skipping
the product's rounding. In the Gaussian resize that moved a tap exactly
1.5 px away (512 px to 224) across the kernel's edge, so Apple-silicon
Macs built a slightly different input than TF, the PyTorch port and
amd64 (CI: TestMUSIQSequenceMatchesReference on macos-latest). Every
product is now rounded by an explicit float32 conversion, which the Go
spec says prevents fusion; the arm64 build of the preprocessing has no
FMADD/FMSUB left.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
@sgoggins sgoggins self-assigned this Nov 26, 2026
validate ladder gains -models M: every version (original and each
degraded one) also gets MUSIQ's score and the rating it gives
(musiq, rating_musiq), as validate quality -models writes them.
tune_penalties.py gains --rating-col (default rating), so the penalty
strengths can be tuned on rating_musiq.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
…, compression 0.1

Tuned with tune_penalties.py --rating-col rating_musiq on BIQ2021 train
and the tuning half of a rebuilt ladder (150 Open Images validation
photos and three camera JPEGs, listed with their split in
tools/musiq/ladder_photos.txt), by the same rule as today's strengths.
On BIQ2021 test, technical with MUSIQ goes from 0.749 to 0.768
(+0.019 [+0.013, +0.025]), +0.141 over today's shipped technical. Colour
casts no longer lower it: a colour penalty of 0.1 alone costs 0.014 on
train. The same run on today's rating picks today's 0.1 / 0.1 / 0.2.
FIT.md, "Penalties", has the held-out tables and commands;
penalties_report.py prints them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
musiqPenalties: exposure 0.1, colour 0, compression 0.1, chosen on tuning
data only by tune_penalties.py's rule (tools/musiq/FIT.md, "Penalties").
On BIQ2021 test, technical with MUSIQ agrees with people at 0.768
[0.746, 0.788], +0.141 [+0.123, +0.159] over today's technical score; the
penalties cost 0.009 (today's strengths would have cost 0.028). No
colour penalty fits the rule (0.1 alone costs 0.014): casts stay reported
by the colour score. TestTechnicalWithMUSIQPenalties pins the strengths.

VALIDATION.md (headline rows, a "Technical rating with MUSIQ" section),
the README, the Scores page and DEPLOY give the held-out numbers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d

Copilot AI 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.

🟡 Changes recommended

Concurrent score writes can persist stale overall scores, while other unresolved defects risk mixed-version ratings, stalled backfills, persistently skipped photos, and validation deadlocks.

5 open issues
What changed in this PR

Adds MUSIQ to Archivis’s technical-quality scoring, blending its predictions with existing measurements while preserving the measurements-only path when the model is unavailable.

Changes:

  • Adds Go/ONNX inference, a fitted rating model, and MUSIQ-specific penalties.
  • Stores MUSIQ scores and adds backfill commands with nightly deployment support.
  • Adds model export, benchmarking, validation tools, tests, and documentation.
File Description
VALIDATION.md Documents accuracy results and penalty trade-offs.
tools/​validate/​tune_penalties.py Supports tuning penalties against MUSIQ ratings.
tools/​validate/​main.go Adds MUSIQ output to quality and degradation measurements.
tools/​validate/​fit_quality.py Exports the MUSIQ-augmented rating model.
tools/​musiq/​speed.py Measures inference cost at different resolutions.
tools/​musiq/​score.py Adds resumable checkpoint scoring.
tools/​musiq/​results/​speed.csv Records timing measurements.
tools/​musiq/​results/​results.csv Records benchmark comparisons.
tools/​musiq/​results/​koniq_512.csv Records downscaled KonIQ results.
tools/​musiq/​results/​bench_output.txt Preserves benchmark output.
tools/​musiq/​RESULTS.md Explains benchmark results and limitations.
tools/​musiq/​preprocess.py Ports multi-scale image preprocessing.
tools/​musiq/​penalties_report.py Reports held-out penalty results.
tools/​musiq/​model.py Ports MUSIQ checkpoint inference to PyTorch.
tools/​musiq/​make_fixture.py Generates reference fixtures for Go tests.
tools/​musiq/​FIT.md Documents fitting, penalty tuning, and reproduction.
tools/​musiq/​export_onnx.py Exports and checks the ONNX model.
tools/​musiq/​bench.py Compares quality and aesthetic predictions.
tools/​musiq/​.gitignore Excludes Python bytecode caches.
tools/​deps/​NOTICE.md Adds MUSIQ attribution and licence information.
tools/​deps/​assets.txt Registers the model asset and checksum.
README.md Introduces MUSIQ scoring and backfill usage.
internal/​web/​templates/​guide.html Updates the technical-score explanation.
internal/​store/​store.go Adds nullable MUSIQ storage and serialization.
internal/​store/​musiq.go Adds score queries, updates, and freshness marking.
internal/​quality/​rating_musiq_model.json Stores fitted rating parameters.
internal/​quality/​quality.go Implements MUSIQ blending and tuned penalties.
internal/​quality/​quality_test.go Tests the fitted model and penalty behavior.
internal/​ml/​testdata/​musiq_ref.json Supplies preprocessing and inference reference values.
internal/​ml/​musiq.go Implements Go preprocessing and ONNX inference.
internal/​ml/​musiq_test.go Checks preprocessing and inference against references.
internal/​indexer/​backfill.go Adds bounded backfill of unscored photos.
internal/​indexer/​backfill_test.go Tests backfill, resumption, and changed-row handling.
internal/​indexer/​analyze.go Integrates MUSIQ into image analysis.
DEPLOY.md Documents installation, backfill, and nightly job updates.
cmd/​archivis/​setup.go Adds checksum-verified model downloads.
cmd/​archivis/​quality.go Adds quality status and backfill commands.
cmd/​archivis/​quality_test.go Tests backfill reporting.
cmd/​archivis/​main.go Registers commands, model loading, and nightly backfill.
.github/​workflows/​ci.yml Tests the macOS backfill deployment snippet.

Review effort: Balanced

Comment thread internal/store/musiq.go Resolved
Comment thread internal/indexer/analyze.go Resolved
Comment thread internal/indexer/backfill.go Resolved
Comment thread internal/indexer/backfill.go Resolved
Comment thread tools/validate/main.go Resolved
From Copilot's review of PR #39:
- SetMUSIQ and SetBlendedScores work out overall from the photo's
  current aesthetic (or technical) score inside their transaction, so a
  blend refreshed during a backfill, or a backfill during a refresh,
  can't leave overall built on the other's old value (neither changes
  seq).
- A MUSIQ failure while indexing no longer drops the photo: it is rated
  by its measurements, its MUSIQ score left for the backfill, and the
  error logged.
- The backfill keeps its place (meta musiq_backfill_after) and carries
  on from there next run, wrapping round once it reaches the end, so a
  photo that fails slowly can't use up every night's time.
- A file whose size or modification time no longer match the catalogue
  (checked before and after reading) isn't scored with the old file's
  stored scores; it is counted and left for the next index.
- -workers / --workers below 1 is refused (validate quality and clip,
  quality backfill) instead of deadlocking.

Tests: TestBackfillMUSIQUsesCurrentAesthetic,
TestBlendRefreshUsesCurrentTechnical, TestAnalyzeKeepsPhotoWhenMUSIQFails,
TestBackfillMUSIQContinuesWhereItStopped,
TestBackfillMUSIQSkipsChangedFiles, TestQualityBackfillNeedsWorkers;
each fails without its fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d

Copilot AI 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.

🟡 Changes recommended

Resuming scoring with a different model list silently mislabels scores under the existing header, and CI never runs the MUSIQ inference reference test.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Add MUSIQ to the required-model CI test selector

internal/​ml/​musiq_test.go:101

This inference test is never exercised by CI: the general test job has no ARCHIVIS_TEST_MODELS and skips it, while the required-model job selects only 'Faces|CLIP|Tokenizer' (.github/workflows/ci.yml:78). Consequently CI downloads MUSIQ but cannot catch an incompatible ONNX graph or incorrect inference scores on either Linux or macOS. Add MUSIQ to the required-model job's test selector so this reference comparison runs with ARCHIVIS_REQUIRE_MODELS=1.

5 resolved since last review

Review effort: Balanced

Comment thread tools/musiq/score.py Resolved
…efuses a mismatched resume

From Copilot's review of PR #39:
- The required-model job selected 'Faces|CLIP|Tokenizer', so
  TestMUSIQScoreMatchesReference was skipped in CI: it now runs with
  ARCHIVIS_REQUIRE_MODELS=1 on Linux and macOS, with the tests' usual
  options.
- archivis loads MUSIQ with CLIP's options, CoreML by default on a Mac,
  which nothing compared with the CPU: TestProviderMatchesCPU now scores
  the fixtures and test photos (at 512 px) on both and allows 0.5 points,
  so the macOS "CoreML matches the CPU" step covers it.
- tools/musiq/score.py resumed an output whatever its columns, appending
  scores in the new -models order under the old header; it now refuses
  unless the header matches exactly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d

Copy link
Copy Markdown
Contributor Author

On review 6090750485's "previously missed" point (no thread): it's real, and fixed in fee8aba.

  • CI runs the MUSIQ test now. The required-model job's selector is now 'Faces|CLIP|Tokenizer|MUSIQ', so TestMUSIQScoreMatchesReference and the sequence tests run with ARCHIVIS_REQUIRE_MODELS=1 on Linux and macOS. The test also now uses the shared testOptions() like the other model tests.
  • MUSIQ on CoreML is checked too. archivis loads MUSIQ with CLIP's options, which is CoreML by default on a Mac, and nothing compared that with the CPU. TestProviderMatchesCPU now scores the synthetic fixtures and the test photos (at 512 px) on both, logs both, and fails beyond 0.5 points. So the macOS "CoreML matches the CPU" step covers MUSIQ with coreml and coreml-gpu.

The thread on score.py is answered and resolved separately.


Generated by Claude Code

Copilot AI 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.

🔵 Needs a closer look

An unconditional wait can let stalled file reads or HEIF conversion exceed the backfill deadline indefinitely while holding the index lock, because scoring and conversion lack cancellation support.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Backfill can hang indefinitely on stalled reads or conversion

internal/​indexer/​backfill.go:136

If a file read or HEIF converter stalls, this unconditional wait can keep quality backfill --for and index --backfill running indefinitely past their deadline while holding the index lock. scoreFile has no cancellation context, and the converter uses exec.Command (internal/imageio/decode.go:423), so cancelling the run cannot finish it gracefully either. Propagate a deadline-aware context through scoring and conversion, and bound non-cancellable reads while preserving completed scores and the resume cursor.

1 resolved since last review

Review effort: Balanced

From Copilot's review of PR #39: each batch waited for every worker, so a
read stalled on a hung network drive, or a converter that never returns,
kept `quality backfill --for` and `index --backfill` running past their
time while holding the index lock.

Workers now report on a channel, and a batch stops waiting when the run
must end: backfillGrace (1 min) after the deadline, or cancelGrace (5 s)
after Ctrl-C. What finished is saved; photos still being read are left
unscored, counted as Stuck and, the cursor being past them, tried again
on a later pass. Starting the next photo also gives up when every worker
is stuck. The abandoned read ends with the process.

TestBackfillMUSIQStopsOnTimeDespiteAStalledRead (deadline and Ctrl-C)
hangs without the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d

Copy link
Copy Markdown
Contributor Author

On review 6103746363's "previously missed" point (backfill can hang on a stalled read or conversion; no thread): it's real, and fixed in c3bdfd3.

Each batch waited on every worker with wg.Wait(). So one read stalled on a hung network drive, or a HEIF conversion that never returns, kept quality backfill --for and index --backfill running past their time while holding the index lock.

What changed:

  • Workers report on a buffered channel. A worker abandoned mid-read touches nothing in the run afterwards.
  • The batch stops waiting when the run must end: backfillGrace (1 minute) after the deadline, or cancelGrace (5 s) after Ctrl-C. Starting the next photo also gives up if every worker is stuck.
  • Finished photos are saved as usual. Photos still being read are left unscored and counted in a new Stuck field. The cursor is already past them, so a later pass retries them, and the run stops. The abandoned read ends when the process exits, which quality backfill, and index after its regroup, do right after.

TestBackfillMUSIQStopsOnTimeDespiteAStalledRead uses a scorer that blocks on one photo, with a deadline and with Ctrl-C. Both return within the grace, with that photo unscored, the photo before it saved and the cursor past it. With the old unconditional wait the test hangs. All other backfill tests pass under -race.

Deliberately not done here: passing a cancellation context into imageio.Load and the HEIF converter (exec.CommandContext). That would change the decoder that indexing uses as well, and it isn't needed for the backfill to keep its time. It could follow separately.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants