Repository navigation
feat(provider): 0.10.13 — reuse scoped Gemma image features in bounded RAM, off by default (port of fork #13; ships with platform #609) - #1947
Draft
jonathan308 wants to merge 2 commits into
Draft
jonathan308 wants to merge 2 commits into
jonathan308 wants to merge 2 commits into
Conversation
…-in, off by default) Port of jonathan308/d-inference#13 (private fork, 2026-10-29) onto dev, for 0.10.12. It is the provider half of darkbloom-platform#609, which sends the authenticated `vision_cache_scope`; it ships with that PR. Repeated still images rerun Gemma's vision tower and projector. With DARKBLOOM_VISION_FEATURE_CACHE=1 (default off), evaluated CPU feature bytes are reused within one account scope: the image is still decoded and resized, the prompt and its spans are rebuilt, and the language model's prefill runs in full. Missing scope, the flag off, an unsupported model or processor, and video take the cold path; local requests have no shared scope. - VisionFeatureCache: keys bind the scope, the loaded model, processor and config identity, the device, the raw payload digest, the normalized image bytes, dtype, shape and frame geometry. One process ledger charges every byte (64 MiB process, 32 MiB slot, 16 MiB scope, 8 MiB entry, 60 s TTL); pending copies and pinned retired entries stay charged; a full scope never evicts another scope; MLX faults invalidate the generation. - Protocol: an optional inbound `vision_cache_scope`; the terminal profile gains optional `vision_feature_cache_hits` and `vision_encoder_images` (counts only; no scope, digest or image). No cached-token credit. - Wiring: EngineV2VisionPrefill, the bridge's lifecycle and shutdown drain, GlobalKVCacheBudget's process ledger, the handler and serve loop. - Adapted to dev: the serve loop's arrival match (ProviderLoop+Serve) and the cluster member's request match (ProviderLoop+ClusterMember) take the new associated value. Docs merged beside dev's new sections. Tests: VisionFeatureCacheTests (20), VisionFeatureCacheProfileTests, VisionFeaturePreparationOwnerTests, GemmaVisionProcessorIdentityTests, VisionCacheScopeProtocolTests pass locally (CPU); ProtocolTests (86), SSDOwnedEntryRetirementTests (22), MediaIngestTests (47) pass. With lookups forced to miss (a local mutant, not committed), VisionFeatureCacheTests fails 20 tests with 42 issues. The live Gemma test is opt-in (real weights). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
… docs say foreground only Independent refactor pass of this port (#1947). No behavior change. - The scope rule (not blank, at most 1 KiB) was written three times: in `EngineV2VisionPrefill.prepare`, `gemmaImageFeatures` and `VisionFeatureCache.Key`. It is now `VisionFeatureCache.isEligible(scope:)`. - The process-wide entry cap (128) is the budget's `maxEntries`, beside its byte cap, instead of a literal in `reserve`. - Restores two invariant comments the change dropped from `EngineV2VisionPrefill.prepare`: native tool templating binds to the loaded wrapper, not a caller's model label; inline media stays in the UserInput's memory-backed asset, so no plaintext file is left to clean up. - `DARKBLOOM_VISION_FEATURE_CACHE` is not in the LaunchAgent passthrough, so only a foreground provider reads it; configuration.md and cli-reference.md said only "the provider process environment". Local (Xcode 27.2, CPU sandbox): VisionFeatureCacheTests and the cache's profile, owner, processor-identity and scope-protocol suites 26; ProtocolTests, SSDOwnedEntryRetirementTests, MediaIngestTests 155: pass. The isolated Swift 6 runner (warnings as errors) 26: pass. EngineV2VisionRoutingTests needs Metal (denied here); CI runs it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 12, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Repeated still images rerun Gemma's vision tower and projector. With
DARKBLOOM_VISION_FEATURE_CACHE=1(defaultoff), evaluated CPU feature bytes are reused within one coordinator-authenticated account scope. Decoding and
resizing still run, the current prompt and its spans are rebuilt, and the language model's prefill runs in full; only the
per-image encoder work is skipped. Missing scope, the flag off, an unsupported model or processor, and video take the
cold path. Local requests have no shared scope.
Bounds: one process ledger charges every byte: 64 MiB process, 32 MiB slot, 16 MiB scope, 8 MiB entry, a 60 s
absolute TTL. Pending copies and pinned retired entries stay charged; a full scope never evicts another account's
entries; an MLX fault invalidates the cache generation; shutdown cancels and drains preparation before refunds.
Wire: an optional inbound
vision_cache_scope(with platform #609); the terminal profile gains optionalvision_feature_cache_hitsandvision_encoder_images(counts only: no scope, digest or image). No cached-token credit;output budgets, deadlines and billing are unchanged.
Before
After
flowchart LR A["trusted outer vision_cache_scope (coordinator)"] --> B["decode and resize the current image"] B --> C{"qualified feature hit in this scope?"} C -- yes --> D["restore a fresh MLX array from charged CPU bytes"] C -- no --> E["run the tower; keep a bounded CPU snapshot"] D --> F["current prompt with spans; full prefill"] E --> F classDef reuse fill:#d8f3dc,stroke:#23743b,color:#123d20 class C,D reuseCode:
VisionFeatureCache,GemmaVisionFeatureCache,GemmaVisionProcessorIdentity,VisionFeaturePreparationOwner(
Inference/Vision/),EngineV2VisionPrefill, the bridge's lifecycle,GlobalKVCacheBudget's process ledger,Messages/InferenceProfile/RequestProfileBuilder, the handler and the serve loop. Design:docs/architecture/image-feature-cache.md(new).Adapted to dev
ProviderLoop+Serve, added on dev after the original's base) and the clustermember's request match (
ProviderLoop+ClusterMember) take the new associated value.Linked issue
None. Coordinator half: darkbloom-platform#609. Original: jonathan308/d-inference#13 (private).
Test plan
0f11fbe01a):VisionFeatureCacheTests(20),VisionFeatureCacheProfileTests(2),
VisionFeaturePreparationOwnerTests(2),GemmaVisionProcessorIdentityTests(1),VisionCacheScopeProtocolTests(1),
ProtocolTests(86),SSDOwnedEntryRetirementTests(22),MediaIngestTests(47): pass.VisionFeatureCacheTestsfails 20 tests with 42 issues(repeat reuse, LRU, scope quotas, expiry, shutdown drain).
0bfd9a2a4d: success, provider and cluster (21 jobs). It also ranCoordinatorIntegrationTestsandEngineV2BridgeTests, which need Metal (denied in the local sandbox).make docs-check(212 files),docs-impact-check --base dev(50 files),changelog check,git diff --check.bb81bd78f8), local: the cache suites 26,ProtocolTests|SSDOwnedEntryRetirementTests|MediaIngestTests155, the isolated Swift 6 runner (warnings as errors) 26: pass (
EngineV2VisionRoutingTestsneeds Metal, denied inthe sandbox). CI (dev) run 42700784572 on
bb81bd78f8: success, provider and cluster (21 jobs).cells, lifecycle and billing audits) was on its October base;
GemmaVisionFeatureCacheLiveTestsis opt-in with realweights. The original measured repeated-image B2 first-content p50/p95 849.7/1118.1 ms OFF against 278.1/568.3 ms ON,
and unique images slightly slower with the cache on (562.7 against 548.2 ms p50).
Open before merge (from the original)
content (provider-path delays between the last delta and the terminal); the cause was not found.
telemetry-types.tsmirror (platform side).Components touched
Protocol / interface changes
vision_cache_scope, optional terminal-profile counts; older coordinators and providersignore them. Matching side: darkbloom-platform#609.
Documentation impact
docs/architecture/image-feature-cache.md(new) and the architecture, developer, provider and reference pages itlinks;
changelog.d/gemma-image-feature-cache.md.Refactor pass
The original had an independent source/refactor review (cancellation and drain, quota isolation, invalid input). The
port's independent refactor pass (2026-11-09,
bb81bd78f8, no behavior change):VisionFeatureCache.isEligible(scope:); theprocess-wide entry cap is the budget's
maxEntriesinstead of a literal 128;EngineV2VisionPrefill.prepareare back (native templating binds tothe loaded wrapper; inline media leaves no plaintext file);
DARKBLOOM_VISION_FEATURE_CACHEis not forwarded to the LaunchAgent, so only a foreground providerreads it;
configuration.mdandcli-reference.mdnow say so.inferenceRequestmatch binds the right positions (a wrong one would still compile:visionCacheScopeandserviceReservationIDare bothString?); fix(provider,coordinator): make the memory cap bind in the two places it did not #609's field names match.EngineV2VisionPlumbingisinjected, so
.production.prepareis no longer called and no routing test shows the cache, scope and profile reachthe preparer; widening the seam touches ~33 test sites in other suites.
AI usage: ported by Claude Opus 5.5 (S-DINF sweep) at the owner's request. Not for merge until reviewed.