Skip to content

feat: configurable patch encoder input resolution via dynamic_img_size#217

Open
HHenryD wants to merge 3 commits into
mainfrom
feat/configurable-patch-encoder-resize
Open

feat: configurable patch encoder input resolution via dynamic_img_size#217
HHenryD wants to merge 3 commits into
mainfrom
feat/configurable-patch-encoder-resize

Conversation

@HHenryD

@HHenryD HHenryD commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds optional custom input resolution for ViT patch encoders via timm dynamic_img_size (interpolates positional embeddings at runtime instead of forcing 224px).

Changes

  • Enabled dynamic_img_size for: gigapath, hoptimus0/1, gpfm, lunit-vits8, h0-mini
  • Added target_img_size build-kwarg to all supported ViTs (above + uni_v1/v2, virchow/virchow2, kaiko-*)
  • Helper asserts requested size is a multiple of the model's patch size (suggests nearest valid sizes)
  • Defaults unchanged when flag unset; CLI errors clearly if used on an unsupported encoder
  • Drive-by fix: virchow/virchow2 HF-hub path was dropping dynamic_img_size/reg_tokens/etc. — unified both load paths

Not covered

Non-ViT / fixed-token backbones (ctranspath Swin, musk, gemma4-*, conch_v1, keep, …) and HF-transformers ViTs (phikon*, hibou_l, midnight12k) — would need different handling, out of scope.

HHenryD and others added 3 commits June 9, 2026 20:02
Add tests for the --patch_encoder_img_size / target_img_size feature:

- tests/test_patch_encoder_resize.py (CI-safe, no downloads): unit tests
  for _resolve_target_img_size validation, RESIZE_SUPPORTED registry
  consistency, both CLI parsers exposing the flag, and run_task gating
  (unsupported encoder raises, supported forwards target_img_size).
- tests/test_patch_encoders.py (integration-gated): per-branch forward
  tests asserting the embedding dim is invariant to target_img_size, plus
  non-multiple and unsupported-encoder rejection.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants