Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b1b180e
support multiscalefeatures in modelwrapper
liopeer May 22, 2026
553f01a
simplify fine-tuning dino wrappers through modelwrapper
liopeer May 22, 2026
622df5a
support loading old checkpoints
liopeer May 22, 2026
c01e724
fix typing issues
liopeer May 22, 2026
0b29ad6
adding tests
liopeer May 22, 2026
78e25a8
Merge branch 'main' into lionel-support-any-backbone
liopeer May 22, 2026
1421ade
fixes in wrappers
liopeer May 22, 2026
6d07ae2
Merge branch 'main' into lionel-support-any-backbone
liopeer May 25, 2026
19c551b
explicit checkpoint loading
liopeer May 26, 2026
2f7e530
use public API
liopeer May 26, 2026
e5dfb45
add fastervit package
liopeer May 26, 2026
4c773f4
add fastervit
liopeer May 26, 2026
af4ebc8
add fastvit
liopeer May 26, 2026
4d58255
Merge branch 'lionel-support-any-backbone' into lionel-add-fastervit
liopeer May 26, 2026
6af44f1
wrapper in linear semseg
liopeer May 26, 2026
b299136
forward only tokens
liopeer May 26, 2026
a3f0213
Merge branch 'main' into lionel-support-any-backbone
yutong-xiang-97 May 27, 2026
7dee325
Merge branch 'lionel-support-any-backbone' into lionel-add-fastervit
liopeer May 27, 2026
382d9bc
remove fastervit
liopeer May 27, 2026
6dac481
small fastvit fixes
liopeer May 27, 2026
34269d9
better model wrappers for vit and cnn
liopeer May 27, 2026
a2d2210
even better model wrappers
liopeer May 27, 2026
f1a5bc7
multiscale fastvit model
liopeer May 27, 2026
2d8e218
any backbone with linseg task model
liopeer May 27, 2026
f100dc1
typing
liopeer May 27, 2026
90f9870
remove drop path rate
liopeer May 27, 2026
bca4706
again a change in drop path rate
liopeer May 27, 2026
f49565e
some dimension fixes
liopeer May 27, 2026
723d855
make it easier
liopeer May 27, 2026
e878292
register load state dict prehook instead
liopeer May 28, 2026
7eb519c
formatting
liopeer May 28, 2026
68ddeda
always STA=false with dinov2
liopeer May 28, 2026
7bc705c
Merge branch 'lionel-support-any-backbone' into lionel-add-fastervit
liopeer May 28, 2026
72af789
remove ltdetr dinov2 to avoid agent confusion
liopeer May 28, 2026
22f6863
any backbone in ltdetr spatial wrappers
liopeer May 28, 2026
c7d2be2
some typing stuff
liopeer May 28, 2026
0c8487a
support any backbone in LT-DETR
liopeer May 29, 2026
5e257f7
hardcoded configs for ltdetr fastvit
liopeer May 29, 2026
4fa184b
Merge branch 'main' into lionel-anybackbone-ltdetr
liopeer Jun 1, 2026
78d7461
formatting
liopeer Jun 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ add-header:

# Apply the Apache 2.0 license header to DEIMv2 derived files
uv run --frozen licenseheaders -t dev_tools/deimv2_licenseheader.tmpl \
-f src/lightly_train/_task_models/dinov2_ltdetr_object_detection/dinov2_vit_wrapper.py \
src/lightly_train/_task_models/dinov3_ltdetr_object_detection/dinov3_vit_wrapper.py \
-f src/lightly_train/_task_models/dinov3_ltdetr_object_detection/dinov3_vit_wrapper.py \
src/lightly_train/_task_models/object_detection_components/flat_cosine.py \
-E py

Expand Down
16 changes: 9 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ dependencies = [
"nvidia-ml-py>=12", # For GPU monitoring
"pytorch_lightning>=2.1",
"tensorboard>=2.10.0",
"torch>=2.1.0",
"torch>=2.1.0",
"torchmetrics[detection]>=0.8", # Torchmetrics is needed for fine-tuning.
# 0.8 is required by SuperGradients
# 1.5.2 is the last version that supports Python 3.8
# 1.7 is recommended version
# 0.8 is required by SuperGradients
# 1.5.2 is the last version that supports Python 3.8
# 1.7 is recommended version
"torchvision>=0.16.0", # torchvision 0.15.0 was yanked
"transformers>=4.46", # Transformers is needed for fine-tuning.
# 4.46 is last version that supports Python 3.8.
# 4.51.3 is the default for EoMT
# 4.46 is last version that supports Python 3.8.
# 4.51.3 is the default for EoMT
"tqdm>=4.0.0",
"pycocotools>=2.0.11; python_version>='3.9'",
"numpy>1.23.0; python_version>='3.12'", # numpy<=1.23 fails to build on Python>3.12 (no distutils).

]

[dependency-groups]
Expand Down Expand Up @@ -190,7 +191,8 @@ ignore_missing_imports = true
module = [
"lightly_train._models.dinov2_vit.dinov2_vit_src.*",
"lightly_train._models.dinov3.dinov3_src.*",
"lightly_train._task_models.object_detection_components.*"
"lightly_train._task_models.object_detection_components.*",
"lightly_train._models.fastvit.components.*",
]
ignore_errors = true

Expand Down
4 changes: 0 additions & 4 deletions src/lightly_train/_commands/train_task_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
from lightly_train._task_models.dinov2_linear_semantic_segmentation.train_model import (
DINOv2LinearSemanticSegmentationTrain,
)
from lightly_train._task_models.dinov2_ltdetr_object_detection.train_model import (
DINOv2LTDETRObjectDetectionTrain,
)
from lightly_train._task_models.dinov3_eomt_instance_segmentation.train_model import (
DINOv3EoMTInstanceSegmentationTrain,
)
Expand Down Expand Up @@ -129,7 +126,6 @@
DINOv2LinearSemanticSegmentationTrain,
DINOv3EoMTSemanticSegmentationTrain,
SemanticSegmentationMultiheadTrain,
DINOv2LTDETRObjectDetectionTrain,
DINOv3LTDETRObjectDetectionTrain,
PicoDetObjectDetectionTrain,
]
Expand Down
9 changes: 5 additions & 4 deletions src/lightly_train/_models/dinov2_vit/dinov2_vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
ArchitectureInfoGettable,
ForwardFeaturesOutput,
ForwardPoolOutput,
MultiScaleFeatureModelWrapper,
MultiScaleFeatureViT,
)


class DINOv2ViTModelWrapper(
Module, MultiScaleFeatureModelWrapper, ArchitectureInfoGettable
):
class DINOv2ViTModelWrapper(Module, MultiScaleFeatureViT, ArchitectureInfoGettable):
def __init__(self, model: DinoVisionTransformer) -> None:
super().__init__()
self._model = model
Expand All @@ -37,6 +35,9 @@ def __init__(self, model: DinoVisionTransformer) -> None:
def feature_dim(self) -> int:
return self._feature_dim

def patch_size(self) -> int:
return int(self._model.patch_size)

def forward_features(
self, x: Tensor, masks: Tensor | None = None, n_blocks: int = 1
) -> ForwardFeaturesOutput:
Expand Down
16 changes: 13 additions & 3 deletions src/lightly_train/_models/dinov3/dinov3_convnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
import torch
import torch.nn.functional as F
from torch import Tensor
from torch.nn import AdaptiveAvgPool2d, Module
from torch.nn import AdaptiveAvgPool2d, Conv2d, Module

from lightly_train._models.dinov3.dinov3_src.models.convnext import ConvNeXt
from lightly_train._models.model_wrapper import (
ForwardFeaturesOutput,
ForwardPoolOutput,
MultiScaleFeatureModelWrapper,
MultiScaleFeatureCNN,
)


class DINOv3VConvNeXtModelWrapper(Module, MultiScaleFeatureModelWrapper):
class DINOv3VConvNeXtModelWrapper(Module, MultiScaleFeatureCNN):
def __init__(self, model: ConvNeXt) -> None:
super().__init__()
self._model = model
Expand Down Expand Up @@ -83,6 +83,16 @@ def get_model(self) -> ConvNeXt:
def make_teacher(self) -> None:
pass

def multiscale_feature_strides(self) -> list[int]:
strides = []
cumulative = 1
for stage in self._model.downsample_layers:
for mod in stage:
if isinstance(mod, Conv2d):
cumulative *= mod.stride[0]
strides.append(cumulative)
return strides

def multiscale_feature_dims(self) -> list[int]:
return list(self._model.embed_dims)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def __init__(
del ignored_kwargs

# ==== ConvNeXt's original init =====
self.downsample_layers = (
self.downsample_layers: Sequence[nn.Sequential] = (
nn.ModuleList()
) # stem and 3 intermediate downsampling conv layers
stem = nn.Sequential(
Expand Down
9 changes: 5 additions & 4 deletions src/lightly_train/_models/dinov3/dinov3_vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
ArchitectureInfoGettable,
ForwardFeaturesOutput,
ForwardPoolOutput,
MultiScaleFeatureModelWrapper,
MultiScaleFeatureViT,
)


class DINOv3ViTModelWrapper(
Module, MultiScaleFeatureModelWrapper, ArchitectureInfoGettable
):
class DINOv3ViTModelWrapper(Module, MultiScaleFeatureViT, ArchitectureInfoGettable):
def __init__(self, model: DinoVisionTransformer) -> None:
super().__init__()
self._model = model
Expand All @@ -39,6 +37,9 @@ def __init__(self, model: DinoVisionTransformer) -> None:
def feature_dim(self) -> int:
return self._feature_dim

def patch_size(self) -> int:
return int(self._model.patch_size)

def forward_features(
self, x: Tensor, masks: Tensor | None = None, n_blocks: int = 1
) -> ForwardFeaturesOutput:
Expand Down
7 changes: 7 additions & 0 deletions src/lightly_train/_models/fastvit/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# Copyright (c) Lightly AG and affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
26 changes: 26 additions & 0 deletions src/lightly_train/_models/fastvit/components/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) Lightly AG and affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
from .fastvit import (
fastvit_ma36,
fastvit_s12,
fastvit_sa12,
fastvit_sa24,
fastvit_sa36,
fastvit_t8,
fastvit_t12,
)

__all__ = [
"fastvit_t8",
"fastvit_t12",
"fastvit_s12",
"fastvit_sa12",
"fastvit_sa24",
"fastvit_sa36",
"fastvit_ma36",
]
Loading
Loading