Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding model with cycle consistency and VampPrior #2421

Draft
wants to merge 76 commits into
base: main
Choose a base branch
from

Conversation

Hrovatin
Copy link

@Hrovatin Hrovatin commented Jan 19, 2024

Closes #2383

@Hrovatin Hrovatin changed the title Adding model with cycle consistency and VampPrior, closes https://github.com/scverse/scvi-tools/issues/2383 Adding model with cycle consistency and VampPrior Jan 19, 2024
Copy link

codecov bot commented Jan 19, 2024

Codecov Report

Attention: Patch coverage is 88.26667% with 44 lines in your changes missing coverage. Please review.

Project coverage is 84.62%. Comparing base (c53efe0) to head (6a2e3eb).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
src/scvi/external/sysvi/_base_components.py 72.64% 32 Missing ⚠️
src/scvi/external/sysvi/_model.py 90.90% 7 Missing ⚠️
src/scvi/external/sysvi/_module.py 97.01% 4 Missing ⚠️
src/scvi/external/sysvi/_priors.py 97.67% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2421      +/-   ##
==========================================
- Coverage   84.81%   84.62%   -0.20%     
==========================================
  Files         173      183      +10     
  Lines       14793    15436     +643     
==========================================
+ Hits        12547    13063     +516     
- Misses       2246     2373     +127     
Files with missing lines Coverage Δ
src/scvi/external/__init__.py 100.00% <100.00%> (ø)
src/scvi/external/sysvi/__init__.py 100.00% <100.00%> (ø)
src/scvi/external/sysvi/_priors.py 97.67% <97.67%> (ø)
src/scvi/external/sysvi/_module.py 97.01% <97.01%> (ø)
src/scvi/external/sysvi/_model.py 90.90% <90.90%> (ø)
src/scvi/external/sysvi/_base_components.py 72.64% <72.64%> (ø)

... and 14 files with indirect coverage changes

---- 🚨 Try these New Features:

Copy link
Contributor

@martinkim0 martinkim0 left a comment

Choose a reason for hiding this comment

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

Hey, thanks for putting in this PR! A couple of high-level comments for now.

Could you restructure the files as follows?

  • csi/model/_model.py -> csi/_model.py
  • csi/model/_utils.py -> csi/_utils.py
  • csi/module/_module.py -> csi/_module.py
  • csi/module/_priors.py -> csi/_priors.py
  • csi/nn/_base_components.py -> csi/_components.py
  • csi/train/_trainingplans.py -> csi/_trainingplans.py
  • Refactor csi/module/_module.py to use scvi.module.base.LossOutput instead of our previous LossRecorder and remove csi/module/_loss_recoder.py
  • If the plan is to directly inherit from UnsupervisedTrainingMixin without any major changes except setting _training_plan_cls, this can be done within _model.py by directly subclassing UnsupervisedTrainingMixin and setting _training_plan_cls there instead, so I would recommend doing that and deleting csi/model/_training.py

I can take a look at compatibility with scArches in the next round.

We're also slowly migrating to newer typing annotations in Python. Could you add a from __future__ import annotations to the top of every file (except __init__.pys) and migrate typing from:

  • Optional[x] -> x | None
  • Union[x, y] -> x | y
  • List[x] -> list[x]
  • Tuple[x] -> tuple[x]
  • Callable -> callable
  • There's more, I don't remember all of them. The pre-commit hooks will warn about missing ones.

@martinkim0 martinkim0 added this to the scvi-tools 1.2.0 milestone Jan 19, 2024
@Hrovatin
Copy link
Author

I added changes and adapted tutorial accrordingly

@martinkim0
Copy link
Contributor

Thanks for addressing the comments! I'll take another pass at it soon.

Copy link
Contributor

@martinkim0 martinkim0 left a comment

Choose a reason for hiding this comment

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

Some minor typing/style comments as well as implementation ones. I still don't understand all parts of the implementation so I will take another pass at this

scvi/external/sysvi/_base_components.py Outdated Show resolved Hide resolved
scvi/external/sysvi/_base_components.py Outdated Show resolved Hide resolved
scvi/external/sysvi/_base_components.py Outdated Show resolved Hide resolved
scvi/external/sysvi/_base_components.py Outdated Show resolved Hide resolved
scvi/external/sysvi/_base_components.py Outdated Show resolved Hide resolved
scvi/external/sysvi/_model.py Outdated Show resolved Hide resolved
scvi/external/sysvi/_model.py Outdated Show resolved Hide resolved
scvi/external/sysvi/_model.py Outdated Show resolved Hide resolved
scvi/external/sysvi/_module.py Outdated Show resolved Hide resolved
scvi/external/sysvi/_priors.py Outdated Show resolved Hide resolved
@martinkim0 martinkim0 added the cuda tests Run test suite on CUDA label Feb 5, 2024
@Hrovatin
Copy link
Author

Hrovatin commented Oct 27, 2024

@canergen @ori-kron-wis The PR is now ready for review.

@ori-kron-wis Can you help me fix the cuda test err? For some reason, it can not import SysVI, although for me, it works locally. I also was not able to test on GPU since I only have MacOS access and I get the err where mps is detected but not used. - If you have any solutions for that also please let me know.

@Hrovatin Hrovatin requested a review from canergen October 27, 2024 20:09
self.var_param = Parameter(torch.zeros(1, n_output))
else:
raise ValueError("Mode not recognised.")
self.activation = torch.exp if activation is None else activation
Copy link
Member

Choose a reason for hiding this comment

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

Do you still need nan_to_num if you use here a softplus activation? You should consider changing it. It's just for backward compatibility still exp in scvi.

super().train(*args, **kwargs)

@torch.inference_mode()
def get_latent_representation(
Copy link
Member

Choose a reason for hiding this comment

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

Does it need it's own get_latent_representation or can it inherit from VAEMIXIN class?

@canergen
Copy link
Member

First look, looks good. Two comments. Should we wait for FClayers to be compatible and then use FClayers? Or do you think it will anyhow not work?

@Hrovatin
Copy link
Author

Hrovatin commented Nov 19, 2024

The FCLayers I use now are the a base for the suggestion that you are working of so it should work with minor modifications in how API is accessed in SysVI. If that is planned to be finished soon then lets wait, but otherwise I suggest merging so that we finally get it in main and then switching afterwards

Also @canergen can you please help with tests. I can not check code on GPU locally (don't have any) and the CI tests fail - I think not due to my side as I can make the below import

ImportError while importing test module '/__w/scvi-tools/scvi-tools/tests/external/sysvi/test_sysvi.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/external/sysvi/test_sysvi.py:10: in <module>
    from scvi.external import SysVI
E   ImportError: cannot import name 'SysVI' from 'scvi.external' (/usr/local/lib/python3.12/site-packages/scvi/external/__init__.py)```

@Hrovatin
Copy link
Author

@canergen I think that all the requests that could be solved at this time were implemented. I would very much appreciate it if we could resolve this, as having this as PR is creating double the amount of work for me since others keep using different SysVI versions from my fork and local repository.

Last thing:
Could you please help with your CI pipeline so that we can see if the tests pass? - As described before, I think there is an error on CI side not finding the SysVI imports although it works locally.

@Hrovatin Hrovatin requested a review from canergen November 30, 2024 06:01
@Hrovatin Hrovatin marked this pull request as ready for review November 30, 2024 06:01
@Hrovatin Hrovatin marked this pull request as draft December 12, 2024 16:57
@Hrovatin
Copy link
Author

When running the full benchmark on the new version we realised it no longer performs as the version before changes in autumn. Will have a look at it, but I am afraid it may be one of the many "non-straightforward" changes required to re-use more of the scvi-tools code. @canergen

If that is the case I will probably give up on this PR and then people need to use the stable version of my fork, before requested changes, as I also lack capacity to work on this.

@canergen
Copy link
Member

See my mail. Happy to look through it once and see whether we can make it work again. Otherwise, we should close here - which would be quite unfortunate.

@Hrovatin
Copy link
Author

Thanks for the reminder. As also mentioned in the email reply, I will inspect the performance in more detail over the holidays and then let you know about merging/closing by early January.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda tests Run test suite on CUDA P1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding cycle consistency loss and VampPrior to scVI
4 participants