Skip to content

Improve tokenizer and model handling for Transformers v5 compatibility - #168

Closed
RaykKretzschmar wants to merge 22 commits into
mainfrom
t-v5
Closed

RaykKretzschmar wants to merge 22 commits into
mainfrom
t-v5

Conversation

@RaykKretzschmar

Copy link
Copy Markdown
Collaborator

No description provided.

@RaykKretzschmar
RaykKretzschmar marked this pull request as draft May 22, 2026 06:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Lightning IR’s model/config/tokenizer integration to stay compatible with Transformers v5, including improved backbone type inference, tokenizer/model class-factory behavior, and test/CI adjustments for external dependencies.

Changes:

  • Bump Python/Transformers requirements (Python >= 3.10, Transformers >= 5.0.0) and add pytest markers for model/dataset-downloading tests.
  • Improve backbone model type handling across configs/models (e.g., get_backbone_model_type(), dropping None overrides) and add caching/registration in class factories.
  • Patch/adjust several models and tests for Transformers v5 behavior (tied weights keys, state-dict loading, CPU device usage, attention mask handling).

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_models/test_splade.py Forces CPU device in test to stabilize behavior across environments.
tests/test_models/test_col.py Monkeypatches ColBERT internals for Transformers v5 tied-weights/key-ignore behavior.
tests/test_models/test_coil.py Adds post_init() and custom state-dict loading to match expected checkpoints.
tests/test_lsr_benchmark_integration.py Marks dataset-downloading tests with a pytest marker.
tests/test_config.py Extends config serialization assertions for new/internal config keys.
tests/test_callbacks.py Skips Seismic-dependent callback tests when the package isn’t installed.
tests/conftest.py Limits BLAS/OpenMP threads; updates typing; bumps test embedding dim defaults.
pyproject.toml Raises Python minimum to 3.10; bumps Transformers to v5; pins sentence-transformers; adds pytest markers; updates Ruff target.
lightning_ir/retrieve/plaid/plaid_searcher.py Adjusts FastPlaid initialization (removes preload_index=True).
lightning_ir/models/cross_encoders/set_encoder.py Updates backbone type handling and attention path for Transformers v5.
lightning_ir/models/cross_encoders/mono.py Uses get_backbone_model_type() for T5 detection.
lightning_ir/models/bi_encoders/splade.py Updates tied-weights handling and backbone type inference for mapping MLM weights.
lightning_ir/modeling_utils/batching.py Moves Callable import to collections.abc (Py3.10+).
lightning_ir/data/dataset.py Ensures targets tensors are float32 for consistency in training/loss usage.
lightning_ir/cross_encoder/cross_encoder_tokenizer.py Adjusts preprocessing for T5 template post-processing behavior.
lightning_ir/callbacks/callbacks.py Moves Callable import to collections.abc (Py3.10+).
lightning_ir/bi_encoder/bi_encoder_model.py Places mask-scoring ID tensors on CPU (moved to input device at use time).
lightning_ir/bi_encoder/bi_encoder_config.py Allows explicit embedding_dim override and persists it appropriately in diffs.
lightning_ir/base/tokenizer.py Improves tokenizer class resolution when TOKENIZER_MAPPING is incomplete in newer Transformers.
lightning_ir/base/model.py Drops None backbone type overrides when merging config diffs during from_pretrained.
lightning_ir/base/external_model_hub.py Moves Callable import to collections.abc (Py3.10+).
lightning_ir/base/config.py Adds backbone type inference and safer serialization/deserialization across derived configs.
lightning_ir/base/class_factory.py Adds caching and AutoModel registration; improves tokenizer mapping handling for Transformers v5.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 132 to +136
num_docs = encoding.pop("num_docs", None)
if num_docs is not None:
attention_mask = encoding.get("attention_mask")
if attention_mask is not None:
device = attention_mask.device

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Implemented in 84c6285. I removed the duplicate attention_mask extension from forward() and now bind get_extended_attention_mask / attention forward from class methods each call to avoid stacked partials across repeated forwards.

@RaykKretzschmar
RaykKretzschmar marked this pull request as ready for review June 12, 2026 12:36
@RaykKretzschmar

Copy link
Copy Markdown
Collaborator Author

I will clean this up and make a new PR

@RaykKretzschmar
RaykKretzschmar marked this pull request as draft June 12, 2026 16:07
@RaykKretzschmar
RaykKretzschmar deleted the t-v5 branch August 26, 2026 15:51
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.

3 participants