Skip to content

ColPali rebase#228

Open
NohTow wants to merge 66 commits into
mainfrom
snapshot-colplai-rebase
Open

ColPali rebase#228
NohTow wants to merge 66 commits into
mainfrom
snapshot-colplai-rebase

Conversation

@NohTow

@NohTow NohTow commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

NohTow and others added 30 commits June 12, 2026 13:08
Update dependency requirements for the new sentence-transformers API,
add optional `image` dependency group for multimodal support, and
update ruff target-version to py310.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adapt Dense to inherit from the new sentence_transformers.base.modules.Dense
(Module base class). Key changes:
- Add config_keys list including use_residual
- Use module_input_name/module_output_name instead of hardcoded keys
- Update save() to use save_config/save_torch_weights
- Update load() with new hub-compatible signature and cls.load_config/load_torch_weights
- Handle string activation functions in from_sentence_transformers()
- Use fullname() for activation function serialization

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Major changes to the ColBERT model:
- Update imports to new ST paths (base.modules, util.quantization)
- Constructor: keyword-only args, processor_kwargs replaces tokenizer_kwargs,
  use_auth_token deprecation handling, add backend parameter
- Replace _load_auto_model/_load_sbert_model with _load_default_modules/
  _load_config_modules/_load_converted_modules
- Add _get_model_config()/_parse_model_config() for config management
- Rename tokenize() to preprocess() with backward-compat wrapper
- Add encode_query()/encode_document() convenience methods
- Add multimodal support: _is_text_input(), _preprocess_multimodal(),
  handle non-text inputs in encode() with skiplist mask fallback
- Update save() to overlay PyLate fields on existing config

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rename the primary parameter from tokenize_fn to preprocess_fn with
backward compatibility. Add _is_text_column() helper for multimodal
detection and skip prompt prepending for non-text columns.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- colbert_triplet: sentence_transformers.sentence_transformer.evaluation
- colbert_distillation: base.evaluation, sentence_transformer.model
- nano_beir: sentence_transformer.evaluation.nano_beir
- IR evaluator: sentence_transformer.evaluation
- model_card: sentence_transformer.model_card, base.evaluation,
  sentence_transformer.trainer, get_embedding_dimension()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…mport

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Example script demonstrating text-query to image-document retrieval
training with a VLM-based ColBERT model using CachedContrastive loss.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace model.tokenize with model.preprocess in code examples
- Replace tokenize_fn with preprocess_fn in collator usage
- Update Transformer import path to sentence_transformers.base.modules

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The training_args module moved from sentence_transformers.training_args
to sentence_transformers.sentence_transformer.training_args in v5.4.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- get_word_embedding_dimension() -> get_embedding_dimension()
- truncate_sentence_embeddings() -> truncate_embeddings()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
_text_length was removed in ST v5.4. The inherited _input_length
(BaseModel) handles strings, dicts, lists, tensors, and PIL images.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replaces 16 lines of manual prompt/prompt_name resolution logic with
the single-line _resolve_prompt() inherited from BaseModel.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replaces ~40 lines of reimplemented HPU power-of-2 padding with the
inherited _pad_features_for_hpu() from SentenceTransformer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Multimodal inputs (images, etc.) may not have input_ids. Guard all
direct input_ids access with .get() or 'in' checks, falling back
to attention_mask where appropriate.

- contrastive.py: extract_skiplist_mask() guards input_ids for query
  and document features
- cached_contrastive.py: use next(iter(values)) instead of input_ids
  for batch size
- colbert.py: guard input_ids in query expansion mask creation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Aligns with ST v5.4 API convention. Uses @deprecated_kwargs decorator
so that callers using sentences= still work with a deprecation warning.
Also renames encode_query/encode_document parameter accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove dead hasattr(first_module, "tokenize") check in preprocess():
  ST v5.4 Transformer only has preprocess()
- Remove redundant config JSON re-write in save(): _get_model_config()
  already includes all PyLate fields, super().save() writes them
- Remove unused _embedding_size/_bias attributes: set but never read

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Both _load_config_modules and _load_converted_modules had identical
~15-line filtering logic. Extract to a shared static method.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
_preprocess_multimodal() now accepts is_query parameter, allowing
downstream use for different max lengths or metadata. Also removes
dead tokenize() fallback (ST v5.4 Transformer only has preprocess).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ColBERTCollator now extends ST v5.4's BaseDataCollator, inheriting
_resolve_router_mapping(), _resolve_prompts(), _get_prompt_for_column(),
and maybe_warn_about_column_order(). Overrides __call__() for
ColBERT-specific behavior: is_query detection, list flattening,
_id column skipping, pad=True, and prompt length tracking.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Antoine Chaffin and others added 9 commits June 15, 2026 12:23
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Load ColPali-family checkpoints (ColQwen2, ColQwen2_5, ColQwen3, etc.)
as their base VLM architecture, extracting the projection layer into a
separate Dense module. Removes the colpali_engine runtime dependency.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…sion

ColPali models use no [Q]/[D] prefixes, empty skiplist, right-padding
with the native pad token, and attend_to_expansion_tokens=True by default.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Append N expansion tokens after the full query text instead of
pad-to-fixed-length, matching colpali_engine's process_queries behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Disable unpadding when query expansion is active and raise an error if
attend_to_expansion_tokens=False is used with Flash Attention, which
silently degrades retrieval scores.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@NohTow NohTow force-pushed the snapshot-colplai-rebase branch from c3bffac to a3ce020 Compare June 15, 2026 12:24
@NohTow NohTow force-pushed the snapshot-colplai-rebase branch from 2749b49 to 74d55ec Compare June 16, 2026 09:25
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.

1 participant