Skip to content

feat(models): add LightlyViT model package - #1003

Open
IgorSusmelj wants to merge 6 commits into
mainfrom
pr-d/lightlyvit-package
Open

IgorSusmelj wants to merge 6 commits into
mainfrom
pr-d/lightlyvit-package

Conversation

@IgorSusmelj

Copy link
Copy Markdown
Contributor

Why

LightlyViT is a compact ViT backbone family (T/S/M/L, patch size 16) that replaces most attention blocks with cheap local mixers (depthwise conv), keeping only a few global blocks. This gives strong quality per FLOP, which is interesting for robotics and embedded workloads with limited compute. Upstreaming the package makes LightlyViT checkpoints loadable and fine-tunable with LightlyTrain. Detection and segmentation adapters on top of it follow in separate PRs.

What changes

  • Adds the lightlyvit model package with variant factories for t16, s16, m16 and l16, plus variant options such as the global mixer kind and the position encoding (learned or RoPE).
  • Adds a model wrapper implementing the standard feature contracts (forward_features, multi-scale features, activation checkpointing).
  • Registers the package in the model list and marks it as ImageNet-normalized.
  • Adds linear semantic segmentation configs for every variant, so each model can be fine-tuned out of the box.
  • Adds a documentation page under "Models" including how to load exported weights via model_args={"backbone_weights": ...}.

How tested

  • Unit tests for the model, package and wrapper (tests/_models/lightlyvit).
  • Registry guard test (every model has a linear segmentation config) and activation checkpointing tests.
  • 418 tests passing locally across the touched areas; ruff and mypy clean; docs build with --fail-on-warning passes.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T22:23:22.479077Z ba4edd9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba4edd9925

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +65 to +66
- [Object Detection](#object-detection) — fine-tune a LightlyViT-based LTDETR model;
supports loading custom pretrained backbone weights via `backbone_weights`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove the unsupported LTDETR fine-tuning claim

The advertised object-detection flow cannot currently be used: a repo-wide search finds no LightlyViT entry in LTDETR_MODEL_REGISTRY, and LTDETRObjectDetection calls that registry before constructing a backbone and later restricts accepted backbones to ConvNeXt, DINOv2/DINOv3 ViTs, or ECViT. Consequently, users following this documentation cannot instantiate a LightlyViT LTDETR model or load the exported backbone_weights; add the required LTDETR configuration and wrapper support or remove this claim.

Useful? React with 👍 / 👎.

Comment on lines +366 to +367
if key_mask.dtype != torch.bool:
key_mask = key_mask > 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve additive-mask semantics in linear attention

When a caller supplies a standard floating-point additive mask, allowed entries are 0 and excluded entries are negative (usually -inf), so key_mask > 0 marks every entry invalid. On the default linear-attention T/M/L variants, passing even an all-zero mask through execute_block therefore zeros every key and value and collapses the attention output instead of behaving like the unmasked call. Interpret additive masks consistently with GlobalSelfAttention, or explicitly reject unsupported floating masks.

Useful? React with 👍 / 👎.

Comment on lines +7 to +9
lightlyvit_l16_v1,
lightlyvit_m16_v1,
lightlyvit_s16_v1,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Export the Tiny factory from the public API

The package and documentation expose lightlyvit_t16_v1 as a supported model, but this public API imports and exports only the S/M/L factories. As a result, from lightly_train._models.lightlyvit import lightlyvit_t16_v1 fails while the equivalent imports for every other advertised variant work; include the Tiny factory in both the import list and __all__.

Useful? React with 👍 / 👎.

@IgorSusmelj

Copy link
Copy Markdown
Contributor Author

/review

This branch has not been deployed

No deployments
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