Generalize VLM modality strategies; add encode_visual seam - #165
Open
camilobrownpinilla wants to merge 3 commits into
Open
Generalize VLM modality strategies; add encode_visual seam#165camilobrownpinilla wants to merge 3 commits into
camilobrownpinilla wants to merge 3 commits into
Conversation
Hoist vision projection into VLMWrapper.forward via a shared BaseModalityStrategy; add encode_visual for once-per-request decode.
Reject visual_embeds passed alongside pixel_values, check rank/batch/ token-count/dim, and swap the training-mode assert for a ValueError so it survives -O. Tests: cached calls now pass pixel_values=None, wrappers get their identity-init projections perturbed (CA and MoT are image-blind at construction), dispatch checks use exact types, and the MoMa strategy tests run through the real projection chain.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the VLM modality pipeline so modality strategies operate on already-projected visual embeddings, and introduces an encode_visual seam to support once-per-request vision projection for cached/incremental decode.
Changes:
- Hoists visual projection into
VLMWrapper.forwardvia a sharedBaseModalityStrategy, eliminating per-strategy duplication. - Adds
VLMWrapper.encode_visual()plusforward(..., visual_embeds=...)to support cached decode (vision tower runs once per request). - Updates/extends unit tests to exercise the cached path and tighten modality-strategy registry expectations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
kempnerforge/model/vlm.py |
Generalizes strategy prep to consume projected visual embeds; adds cached-decode support via encode_visual/visual_embeds. |
tests/unit/test_vlm.py |
Updates strategy tests to pass projected embeds; adds coverage for cached vs uncached equivalence and cache guards. |
tests/unit/test_moma.py |
Adjusts MoMa strategy tests to route pixels through the real projection helper before calling prepare(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Testing
uv run ruff check kempnerforge/ tests/passesuv run ruff format --check kempnerforge/ tests/ scripts/passesuv run pyright kempnerforge/passes (0 errors)uv run pytest tests/unit/ -v --timeout=60passesCloses #164