Skip to content

Generalize VLM modality strategies; add encode_visual seam - #165

Open
camilobrownpinilla wants to merge 3 commits into
feat/eval-mlflow-supportfrom
refactor/vlm-modalitystrategy
Open

Generalize VLM modality strategies; add encode_visual seam#165
camilobrownpinilla wants to merge 3 commits into
feat/eval-mlflow-supportfrom
refactor/vlm-modalitystrategy

Conversation

@camilobrownpinilla

Copy link
Copy Markdown
Collaborator

Summary

  • Hoists vision projection into VLMWrapper.forward via a shared BaseModalityStrategy
  • Adds encode_visual for once-per-request decode.

Testing

  • uv run ruff check kempnerforge/ tests/ passes
  • uv run ruff format --check kempnerforge/ tests/ scripts/ passes
  • uv run pyright kempnerforge/ passes (0 errors)
  • uv run pytest tests/unit/ -v --timeout=60 passes

Closes #164

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.forward via a shared BaseModalityStrategy, eliminating per-strategy duplication.
  • Adds VLMWrapper.encode_visual() plus forward(..., 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.

Comment thread kempnerforge/model/vlm.py
@camilobrownpinilla camilobrownpinilla linked an issue Jul 24, 2026 that may be closed by this pull request
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.

Refactor VLM model code

2 participants