-
Notifications
You must be signed in to change notification settings - Fork 355
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 cycle consistency loss and VampPrior to scVI #2383
Comments
Hi, thanks for this suggestion. I think adding these changes would be a great addition to the codebase. However, for now I am opposed to adding them to the scVI model directly for two reasons:
What do you think? Are you interested in contributing code directly or wanted us to add the changes? Either works, but the latter might take a bit longer. |
I was initially thinking that this could be an optional extension of scVI, making both not used by default (via new parameters with defaults being False). The users could then decide to enable it in their new code. I thought this would be much easier for maintenance than adding a new model and would also improve outreach as anyone using scVI could directly test it. Alternatively, I could also add it as a new model - the current code is anyway based on scvi-tools although with quite some modifications. However, I am not sure that adding a new model would make sense as I will not be able to maintain it in the future and it is directly compatible with scVI anyways. I can help contribute to some extent as I am familiar with the implementation, but support on your side would also be appreciated - we can discuss it. |
Hi, I really enjoyed reading your preprint. It's interesting to see your good results with CycleConsistencyLoss as it was overintegrating in some examples in our hand (slightly different implementation and this might be the reason). I think CycleConsistencyLoss should be in an external model. It requires major changes to the model and will blow up the code. We currently make sure that external models are compatible with recent code changes. It's not excluded that in the future, external models that are not used after integration into scvi-tools might be depreciated. I don't see this coming before scvi-tools v2.0 though. For VAMPprior, we have MoG priors (similar to VAMP but logits are learnable) in scvi-tools (developed for MrVI) but used in several unpublished new scvi-tools models. Adding those things, doesn't really change the code and this could live in scVI IMO. |
Agreed that cycle consistency adds quite an overhead. Will probably proceed with making it external then, making minimal adaptations to make it compatible with the latest scvi version. We can then later discuss if some code needs to be improved to reduce repetition etc. For us using an appropriate distance in cycle consistency made an important impact - we tested a few. - What was different in your implementation? For priors, I already have an implementation like you suggest (for standard normal, Vamp, and GMM), although some changes outside of this are also needed (e.g. pseudoinputs etc). |
@canergen I now added the model here. Also, for the tutorial if I have a small data object (38.2 MB). - Where should it be stored? In scvi/external/mypackage/data/? |
@PierreBoyeau used cycle consistency loss in our hands, do you see substantial differences to our trials? |
@martinkim0 I was also asked to add existing scArches functionality (probably from ArchesMixin) into my model. Would this be currently even possible given that my covariate structure is so different? |
@Hrovatin For scArches, compatibility mostly depends on how you register covariates with @canergen Sounds good, we can keep the priors code in external for now. |
In that case I assume it will not be compatible - are you planing to extend scArches to be more flexible wrt covariates? I now also made the PR and added a tutorial here: scverse/scvi-tutorials#212 |
We will be hopefully re-submitting our manuscript next week. Is it ok if we write that we added our model to scvi-tools external and it is still under review? |
Sorry for the late response. Totally fine with me, please go ahead! |
I was wondering when the PR for the code & the tutorial could be merged? - I have a talk about this work at M2D2 series from Valence labs/MILA next Tuesday and it would be great if I could provide links to the scvi-tools repo rather than my fork. |
Hi, to do some expectation management. The code will be part of a stable relese with version 1.2. We are currently finishing version 1.1. Timeline for version 1.2 is on the order of 4 months. This timeline is long as we for example work with precommits to make sure every change works within the scverse ecosystem. |
@Hrovatin Sorry for the delay in reviewing - I've taken another pass at it now. I think we'll need to add a couple more changes and trim down code where needed before merging into main. We can try our best to get it in before Tuesday, but no promises. In terms of linking to the scvi-tools repo, feel free to reference the PR. |
Thank you for letting me know - I just wanted to make sure to share a link version that is not on my own fork which will not be maintained in the future. I will then add links to the PR if we cant merge into main beforehand. |
@martinkim0 |
Hi @moinfar and @Hrovatin we're sorry for the long time it takes us to integrate the changes. Unfortunately, we were not able to understand all parts of the code yet (I currently can't review it myself), which makes it difficult to take over maintenance after merging. We are currently restructuring our team (switch in SWE) and have to push this to the latter release. We will update you after another round of reviewing the PR with remaining questions/requests about the structure. |
Reviewed it now. Numerous comments from the last reviews are not addressed. please try to reduce the amount of new functions and highlight for all functions, why a new implementation is necessary and what part is missing in our implementation (we might add those). Currently, the overhead to maintain this code is large and I/Martin are pretty certain that we can help you to reduce it. |
I don't think understanding is the problem. I was puzzled by two implementation details and requested for citations there as it will make it easier for users in the future to follow the design. |
Thank you. We will look into them and try to resolve them. |
@canergen It may take us a while to resolve the comments as we are currently working on the paper revision. - Let us know if there are any release dates we should be catching. |
No worries. We will release 1.2 in the coming weeks. 1.3 will be at the end of this year. We could also think about adding the model with a patch release in between. |
We were considering adding cycle-consistency loss and VampPrior as described in Integrating single-cell RNA-seq datasets with substantial batch effects | bioRxiv) to scvi-tools package, preferably directly into scVI.
The current implementation is based on a cVAE that works with normalized+log transformed data: https://github.com/theislab/cross_system_integration/blob/main/cross_system_integration/model/_xxjointmodel.py
Adding VampPrior would require changes in Model to initialise VampPrior pseudoinputs https://github.com/theislab/cross_system_integration/blob/322549224cddcd5d375f8b49cb9f0e0e77c2be1f/cross_system_integration/model/_xxjointmodel.py#L87C10-L87C10 and in module to replace prior: https://github.com/theislab/cross_system_integration/blob/322549224cddcd5d375f8b49cb9f0e0e77c2be1f/cross_system_integration/module/_xxjointmodule.py#L165C11-L165C11
Adding cycle consistency would require changes in adata setup to specify which batch covariate should be used as the "system" that is specifically corrected for with Lcyc - we specify systems and batches within systems (not corrected by Lcyc) for which batch_key and categorical/continous_covariate_keys could be used respectively. Besides, changes in the forward pass and an additional loss would need to be added, see this file: https://github.com/theislab/cross_system_integration/blob/multiple_sys_model/cross_system_integration/module/_xxjointmodule.py#L235 - This branch has slightly different implementation than in the paper, but I would suggest adding this one as it is more general.
The text was updated successfully, but these errors were encountered: