lightly icon indicating copy to clipboard operation
lightly copied to clipboard

SparK Implementation

Open gabrielfruet opened this issue 9 months ago • 23 comments

Addresses #1462

Continues #1750

Inspired by: https://github.com/keyu-tian/SparK

https://arxiv.org/pdf/2301.03580

gabrielfruet avatar Feb 05 '26 22:02 gabrielfruet

@guarin Tried to adhere to the patterns you listed on @johnsutor 's PR.

I still need to clean a bit of unused code, but i think what we have work for now.

gabrielfruet avatar Feb 09 '26 14:02 gabrielfruet

Thanks for the PR! I'll have a look ASAP, might take a couple of days.

guarin avatar Feb 10 '26 16:02 guarin

hey @guarin, wanted to understand some things.

is lightly repo still actively mantained? i'm not seeing much community contributions lately, last commit was made 5 months ago.

just wanted to get some context on how things are going historically, and what are the plans for the repo.

i know that lightly-train is still actively maintained. was it a replacement to detriment of lightly? i know that they are fundamentally different and i think lightly-train doesn't even use lightly under the hood(might be wrong).

FYI, i will be actively maintaining and implementing some methods from now on. I'm very interested in SSL, and i think Lightly is the gold standard for that.

I'm drafting PRs for LeJEPA also.

If there is a list of wanted features, please let me know!

gabrielfruet avatar Feb 12 '26 09:02 gabrielfruet

Hi, both are maintained :) Just didn't have a lot of time to work on the lightly repo recently. This repo is for SSL research whereas LightlyTrain is more targeted towards production/industry use-cases and also covers fine-tuning etc.

New methods are the most interesting contributions for us. Especially recent methods like:

  • JEPAs
  • Pixio

There are also some opportunities to improve the benchmarking code. Let me know if you are interested in this.

Thanks a lot for the interest and contributions!

guarin avatar Feb 12 '26 10:02 guarin

thanks guarin! makes total sense regarding the research vs production split.

i'm wrapping up the lejepa loss function pr now, then i'll continue implementing the full module. pixio is next. since it deals with dense prediction, it fits my lidar/3d background perfectly.

btw, i just applied for the "machine learning engineer (oss)" role from Lightly. really hoping to help manage the repo officially. would love for you to treat these PRs as a trial run to show how i work :)

gabrielfruet avatar Feb 12 '26 12:02 gabrielfruet

Quick heads-up @gabrielfruet : Currently reviewing it, but might take until the beginning of next week until I'll finish since I have quite a lot of other things to do.

liopeer avatar Feb 19 '26 05:02 liopeer

Sorry @gabrielfruet that it's taking longer. But I blocked myself some time today to do it. :)

liopeer avatar Feb 27 '26 07:02 liopeer

Hi @liopeer, that's fine! I personally understand.

I will address some issues in this PR, that i acknowledged through the modifications that Igor made to my LeJEPA PR.

But would still be nice to have some direction here! Just to guarantee we're in the same page.

gabrielfruet avatar Feb 27 '26 08:02 gabrielfruet

FYI, you can update the branch with latest main. I should resolve the CI issues!

IgorSusmelj avatar Mar 02 '26 16:03 IgorSusmelj

@gabrielfruet I'll try to help a bit in the next few days so that we can merge this. Pushed a few cleanups and a context variable for taking care of that ugly global tensor. Feel free to also reach out on Discord for slightly faster interaction.

liopeer avatar Mar 02 '26 17:03 liopeer

Hi @liopeer, sorry for the delay. I got really sick recently.

I made some comments and reviews, but i forgot to submit them. I submitted them now.

gabrielfruet avatar Mar 02 '26 17:03 gabrielfruet

Codecov Report

:x: Patch coverage is 53.89408% with 148 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 84.78%. Comparing base (ee30cd4) to head (9687035). :warning: Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
lightly/models/modules/sparse_spark.py 50.00% 145 Missing :warning:
lightly/loss/sparse_spark.py 89.65% 3 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1892      +/-   ##
==========================================
- Coverage   86.10%   84.78%   -1.32%     
==========================================
  Files         168      171       +3     
  Lines        6979     7375     +396     
==========================================
+ Hits         6009     6253     +244     
- Misses        970     1122     +152     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Mar 05 '26 09:03 codecov[bot]

@liopeer If you wish i could increase test coverage. If not necessary let me know.

gabrielfruet avatar Mar 05 '26 10:03 gabrielfruet

I'll take a look into these type errors (Check 3.7)

gabrielfruet avatar Mar 05 '26 12:03 gabrielfruet

FYI, i still have to address these python 3.7 errors. Do we still support python 3.7?

gabrielfruet avatar Mar 10 '26 13:03 gabrielfruet

Hi @liopeer , when possible, can you approve these workflows? I think i fixed most of the issues. Also, the 3.7 tests are still relevant?

Also if you have any other suggestion for the code, let me know!

gabrielfruet avatar Apr 02 '26 11:04 gabrielfruet

  1. Tests are green
  2. Formatted the code
  3. Generated notebooks

Quick question: One of my modules depends on timm. Should i port the necessary classes to our repo or should i declare it as a dependency?

from timm.models.layers import DropPath, trunc_normal_

gabrielfruet avatar Apr 02 '26 12:04 gabrielfruet

  1. Tests are green
  2. Formatted the code
  3. Generated notebooks

Quick question: One of my modules depends on timm. Should i port the necessary classes to our repo or should i declare it as a dependency?

from timm.models.layers import DropPath, trunc_normal_

If timm is not yet a dependency we should copy over the files. You can add a note that you copied them from timm.

IgorSusmelj avatar Apr 02 '26 21:04 IgorSusmelj

There are two options here. I was taking a look and we also have this pattern for timm's ViT to skip tests on minimal CI

https://github.com/lightly-ai/lightly/blob/904c50a7cc8bff9dbc0863a99bc71c84422322a8/lightly/utils/dependency.py#L27-L44

We already have a test that depends on DropPath and is being just skipped if timm is not available. Since we are already using this pattern, i'll stick to it.

https://github.com/lightly-ai/lightly/blob/904c50a7cc8bff9dbc0863a99bc71c84422322a8/tests/models/test_ModelUtils.py#L923-L938

gabrielfruet avatar Apr 02 '26 21:04 gabrielfruet

I tested with py37 on my environment and the workflows went green. I'm just worried about the test coverage. I'll take a look into it when possible.

gabrielfruet avatar Apr 03 '26 12:04 gabrielfruet