# Scanvi best practices

**URL:** <https://discourse.scverse.org/t/scanvi-best-practices/122>\
**Category:** scvi-tools\
**Tags:** scanvi\
**Created:** [July 1, 2021, 1:53pm UTC](https://discourse.scverse.org/t/scanvi-best-practices/122 "2021-07-01T13:53:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![crg](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/crg/32/225_2.png) [@crg](https://discourse.scverse.org/u/crg)\
**Post date:** [July 1, 2021, 1:53pm UTC](https://discourse.scverse.org/t/scanvi-best-practices/122/1 "2021-07-01T13:53:25Z")

</div>

Hi,

I’ve been reviewing the latest changes in SCANVI. I noted the removal of pretraining scvi and that the option to do pretraining was moved to the `from_scvi_model()` method.

Could you elaborate on whether it is still best practice to pretrain with scvi, or whether just using scanvi on its own is better?

Thanks  
Charlotte

---

<div class="post-metadata">

**Author:** ![adamgayoso](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/adamgayoso/32/100_2.png) [@adamgayoso](https://discourse.scverse.org/u/adamgayoso)\
**Post date:** [July 1, 2021, 2:58pm UTC](https://discourse.scverse.org/t/scanvi-best-practices/122/2 "2021-07-01T14:58:49Z")

</div>

It is still best practice to pretrain a SCVI model and then instantiate SCANVI with the `from_scvi_model` class method. We moved this around for API reasons.

---

<div class="post-metadata">

**Author:** ![crg](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/crg/32/225_2.png) [@crg](https://discourse.scverse.org/u/crg)\
**Post date:** [July 1, 2021, 3:37pm UTC](https://discourse.scverse.org/t/scanvi-best-practices/122/3 "2021-07-01T15:37:55Z")

</div>

Thanks for the quick response!

---

<div class="post-metadata">

**Author:** ![grst](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/grst/32/17_2.png) [@grst](https://discourse.scverse.org/u/grst)\
**Post date:** [September 15, 2021, 7:02am UTC](https://discourse.scverse.org/t/scanvi-best-practices/122/4 "2021-09-15T07:02:41Z")

</div>

Does it make a difference if I already add the labels\_key when training the SCVI model, i.e.

```python
scvi.data.setup_anndata(adata, batch_key='batch', labels_key="seed_labels")
scvi_model = scvi.model.SCVI(adata)
scvi_model.train()
scanvi_model = scvi.model.SCANVI.from_scvi_model(scvi_model, 'Unknown')
scanvi_model.train()

```

or if I add the labels only when running SCANVI?

```python
scvi.data.setup_anndata(adata, batch_key="batch")
scvi_model = scvi.model.SCVI(adata)
scvi_model.train()
scvi.data.setup_anndata(adata, batch_key="batch", labels_key="seed_labels")
scanvi_model = scvi.model.SCANVI.from_scvi_model(scvi_model, "Unknown", adata=adata)
scanvi_model.train()

```

The former method is used in the “seed labelling” tutorial, the latter in the “atlas-level integration” tutorial.

---

<div class="post-metadata">

**Author:** ![adamgayoso](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/adamgayoso/32/100_2.png) [@adamgayoso](https://discourse.scverse.org/u/adamgayoso)\
**Post date:** [September 15, 2021, 3:14pm UTC](https://discourse.scverse.org/t/scanvi-best-practices/122/5 "2021-09-15T15:14:26Z")

</div>

@grst either way will work, setup anndata just creates a dictionary in `adata.uns["_scvi"]` and the labels won’t do anything to SCVI. This will be more explicit in a future release.

---

<div class="post-metadata">

**Author:** ![kanefos](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/kanefos/32/151_2.png) [@kanefos](https://discourse.scverse.org/u/kanefos)\
**Post date:** [November 28, 2022, 8:30pm UTC](https://discourse.scverse.org/t/scanvi-best-practices/122/6 "2022-11-28T20:30:27Z")

</div>

Hi,

I have a similar question. If I have a scvi model trained with one labels\_key, but then later want to use this scvi model to create a scanvi model but predicting a different set of labels (a new labels\_key) - is this possible? Can I replace the original labels\_key?

---

<div class="post-metadata">

**Author:** ![adamgayoso](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/adamgayoso/32/100_2.png) [@adamgayoso](https://discourse.scverse.org/u/adamgayoso)\
**Post date:** [November 28, 2022, 10:17pm UTC](https://discourse.scverse.org/t/scanvi-best-practices/122/7 "2022-11-28T22:17:07Z")

</div>

> [@kanefos](#):
>
> I have a similar question. If I have a scvi model trained with one labels\_key, but then later want to use this scvi model to create a scanvi model but predicting a different set of labels (a new labels\_key) - is this possible? Can I replace the original labels\_key?

In this case, it’s better not to provide the labels key to scvi, as the only thing this enables is gene-label specific dispersion parameters.

If you do provide the `labels_key`, what you want will not be possible; however, if you only provide the labels at the time of scanvi initialization it is possible
