Skip to content

Refac(MSplit): LVAE module - #1033

Open
CatEek wants to merge 12 commits into
dev/microsplit_apifrom
iz/feat/lvae_model_refac
Open

Refac(MSplit): LVAE module#1033
CatEek wants to merge 12 commits into
dev/microsplit_apifrom
iz/feat/lvae_model_refac

Conversation

@CatEek

@CatEek CatEek commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Disclaimer

  • I am an AI agent.
  • I have used AI and I thoroughly reviewed every line.
  • I have not used AI extensively.

Description

Note

tldr: Behavior-preserving cleanup of the LVAE model — dead code removal, layer blocks cleanup, and models/lvae/ back to pre-commits.

Background - why do we need this PR?

Lot's of old commented-out code, unnecessary inheritance, dead parameters, lot's of pre-commit errors

Overview - what changed?

  • Removed dead/commented code and the resolved TODOs across lvae.py, layers.py, stochastic.py, utils.py.
  • Specialized the layer blocks to the single used config: dropped the dead-configurable params (block_type, batchnorm, conv2d_bias, res_block_kernel, merge_type, skip-padding) and their branches.
  • Collapsed unnecessary inheritance: removed ResBlockWithResampling, ResidualGatedBlock, SkipConnectionMerger. BottomUpDeterministicResBlock/TopDownDeterministicResBlock are now standalone and share a _make_pre_conv helper.
  • Docstrings → numpydoc, typing cleaned up, and the models/lvae/ pre-commit exclusions removed

Modified features or files

  • src/careamics/models/lvae/lvae.py, layers.py, stochastic.py, utils.py — cleanup + specialization + docstrings/typing.
  • src/careamics/config/architectures/lvae_config.py — removed dead/broken set_3D.
  • .pre-commit-config.yaml — narrowed the lvae exclusions to noise_models.py only.
  • tests/models/lvae/test_lvae_architecture.py — updated the (already-skipped) test_bottom_up_pass to call bottomup_pass after the wrapper was inlined.

Removed features or files

  • ResBlockWithResampling, ResidualGatedBlock, SkipConnectionMerger, ModelType, power_of_2, LVAEConfig.set_3D.

Please ensure your PR meets the following requirements:

  • Code builds and passes tests locally, including doctests
  • New tests have been added (for bug fixes/features)
  • Pre-commit passes
  • PR to the documentation exists (for bug fixes / features)

@CatEek CatEek changed the title Iz/feat/lvae model refac LVAE module refac Aug 2, 2026
@CatEek

CatEek commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

I'm very open to suggestion, maybe missed something

@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.67470% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.64%. Comparing base (469bcfe) to head (6ff0f3d).
⚠️ Report is 4 commits behind head on dev/microsplit_api.

Files with missing lines Patch % Lines
src/careamics/models/lvae/layers.py 70.83% 14 Missing ⚠️
src/careamics/models/lvae/lvae.py 50.00% 8 Missing ⚠️
src/careamics/models/lvae/utils.py 77.77% 4 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                   @@
##           dev/microsplit_api    #1033      +/-   ##
======================================================
+ Coverage               83.49%   83.64%   +0.14%     
======================================================
  Files                     252      252              
  Lines                    9254     9160      -94     
======================================================
- Hits                     7727     7662      -65     
+ Misses                   1527     1498      -29     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@jdeschamps jdeschamps changed the title LVAE module refac Refac(MSplit): LVAE module Aug 3, 2026

@jdeschamps jdeschamps left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I did not review the PR, just had a quick look.

Could you comment on how you tested correctness? It is part of the PR template and it would be useful to know whether the existing model weights can still be loaded, and/or whether you ran some training.


return z_dims

def set_3D(self, is_3D: bool) -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should also have another look at the UNet and whether this set 3D is ever used or necessary. Maybe a small clean up issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

created issue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Following #1038, this should not be removed and we should see what else needs to be updated for the LVAE architecture to be set to 3D.

Indeed, we need to have an HDN napari plugin for a grant.

Comment thread src/careamics/models/lvae/layers.py Outdated
Co-authored-by: Joran Deschamps <6367888+jdeschamps@users.noreply.github.com>
@CatEek

CatEek commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

I did not review the PR, just had a quick look.

Could you comment on how you tested correctness? It is part of the PR template and it would be useful to know whether the existing model weights can still be loaded, and/or whether you ran some training.

Old checkpoints trained by Ashesh won't load in any version of careamics without some manipulation with weights. We have that in reproducibility.
Older careamics versions will almost load here(although not with strict=True) but that doesn't matter because we don't have any useful checkpoints

@jdeschamps

Copy link
Copy Markdown
Member

Can you report on training performances?

@CatEek

CatEek commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Can you report on training performances?

~ 31.1 / 32.2, given the full(400ep) original run produced 32/32.9

@veegalinova

Copy link
Copy Markdown
Collaborator

Can you report on training performances?

~ 31.1 / 32.2, given the full(400ep) original run produced 32/32.9

I think it's a substantial difference. If the performance was checked with a script similar to one in #1052, there is no seed set anywhere during training (please correct me if I'm wrong!). Can you re-run two comparison runs with the same seed, and maybe cuda deterministic and benchmark for a good measure?
I will also do the same for HDN and report here.

@CatEek

CatEek commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Can you report on training performances?

~ 31.1 / 32.2, given the full(400ep) original run produced 32/32.9

I think it's a substantial difference. If the performance was checked with a script similar to one in #1052, there is no seed set anywhere during training (please correct me if I'm wrong!). Can you re-run two comparison runs with the same seed, and maybe cuda deterministic and benchmark for a good measure? I will also do the same for HDN and report here.

seeds are very good point, will add. As for the numbers, also forgot that those were with mmse of 1, with 50 it jumps to 31.6/32.8. Running full 400ep also

@jdeschamps

jdeschamps commented Aug 24, 2026

Copy link
Copy Markdown
Member

As discussed, before merging we are waiting for full report of the experiments (original PSNR, this branch with seeds and mmse) and for @veegalinova tests on HDN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants