# Error issue running with vae.train()

**URL:** https://discourse.scverse.org/t/error-issue-running-with-vae-train/807
**Category:** scvi-tools
**Created:** [October 7, 2022, 12:28pm UTC](https://discourse.scverse.org/t/error-issue-running-with-vae-train/807 "2022-10-07T12:28:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DRSEI](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/drsei/32/172_2.png) [@DRSEI](https://discourse.scverse.org/u/DRSEI)
#### Post date: [October 7, 2022, 12:28pm UTC](https://discourse.scverse.org/t/error-issue-running-with-vae-train/807/1 "2022-10-07T12:28:29Z")

</div>

Hi I have SCVI env which is running perfectly fine but whenever I want to run vae.train() I am getting this error which I don’t know how to fix .

I really appreciate your help.

/Users/sergio/opt/miniconda3/envs/scib/lib/python3.9/site-packages/scvi/model/base/\_training\_mixin.py:67: UserWarning: max\_epochs=115 is less than n\_epochs\_kl\_warmup=400. The max\_kl\_weight will not be reached during training. warnings.warn( GPU available: True (mps), used: False TPU available: False, using: 0 TPU cores IPU available: False, using: 0 IPUs HPU available: False, using: 0 HPUs /Users/sergio/opt/miniconda3/envs/scib/lib/python3.9/site-packages/pytorch\_lightning/trainer/trainer.py:1789: UserWarning: MPS available but not used. Set `accelerator` and `devices` using `Trainer(accelerator='mps', devices=1)`. rank\_zero\_warn(

Epoch 1/115: 0%| | 0/115 [00:00\<?, ?it/s]

Output exceeds the size limit. Open the full output data in a text editor

--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In [23], line 1 ----\> 1 vae.train() File ~/opt/miniconda3/envs/scib/lib/python3.9/site-packages/scvi/model/base/\_training\_mixin.py:142, in UnsupervisedTrainingMixin.train(self, max\_epochs, use\_gpu, train\_size, validation\_size, batch\_size, early\_stopping, plan\_kwargs, \*\*trainer\_kwargs) **131** trainer\_kwargs[es] = ( **132** early\_stopping if es not in trainer\_kwargs.keys() else trainer\_kwargs[es] **133** ) **134** runner = TrainRunner( **135** self, **136** training\_plan=training\_plan, (…) **140** \*\*trainer\_kwargs, **141** ) → 142 return runner() File ~/opt/miniconda3/envs/scib/lib/python3.9/site-packages/scvi/train/\_trainrunner.py:81, in TrainRunner. **call** (self) **78** if hasattr(self.data\_splitter, “n\_val”): **79** self.training\_plan.n\_obs\_validation = self.data\_splitter.n\_val —\> 81 self.trainer.fit(self.training\_plan, self.data\_splitter) **82** self.\_update\_history() **84** # data splitter only gets these attrs after fit File ~/opt/miniconda3/envs/scib/lib/python3.9/site-packages/scvi/train/\_trainer.py:188, in Trainer.fit(self, \*args, \*\*kwargs)

…

[nan, nan, nan, …, nan, nan, nan], …, [nan, nan, nan, …, nan, nan, nan], [nan, nan, nan, …, nan, nan, nan], [nan, nan, nan, …, nan, nan, nan]], grad\_fn=)t`

---

<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: [October 7, 2022, 3:26pm UTC](https://discourse.scverse.org/t/error-issue-running-with-vae-train/807/2 "2022-10-07T15:26:56Z")

</div>

Do you have any outlier data points? Can you try turning down the learning rate?

---

<div class="post-metadata">

### Author: ![DRSEI](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/drsei/32/172_2.png) [@DRSEI](https://discourse.scverse.org/u/DRSEI)
#### Post date: [October 7, 2022, 9:40pm UTC](https://discourse.scverse.org/t/error-issue-running-with-vae-train/807/3 "2022-10-07T21:40:24Z")

</div>

hi @adamgayoso ,

Thank you so much for your reply.

I have attached my code below

```auto
sc.pp.highly_variable_genes(
    ad_orig,
    n_top_genes=1200,
    subset=True,
    layer="counts"
)

scvi.model.SCVI.setup_anndata(ad_orig, layer="counts", batch_key="patientID")

vae = scvi.model.SCVI(ad_orig, n_layers=2, n_latent=30, gene_likelihood="nb")

vae.train()

```

What do you mean by turining down the learing rate?

I am very new to SCVI.I may need your guidance

---

<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: [October 8, 2022, 2:38am UTC](https://discourse.scverse.org/t/error-issue-running-with-vae-train/807/4 "2022-10-08T02:38:56Z")

</div>

I see, can you try the following?

```auto
sc.pp.highly_variable_genes(
    ad_orig,
    n_top_genes=1200,
    subset=True,
    layer="counts",
    flavor="seurat_v3"
)

```

Using the counts for HVG may lead to poor results if not using the seurat v3 flavor.

---

<div class="post-metadata">

### Author: ![DRSEI](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/drsei/32/172_2.png) [@DRSEI](https://discourse.scverse.org/u/DRSEI)
#### Post date: [October 8, 2022, 10:43am UTC](https://discourse.scverse.org/t/error-issue-running-with-vae-train/807/7 "2022-10-08T10:43:29Z")

</div>

I think the problem happens when some category in ‘batch\_key’ has less number of the gene in my batch. After removing it, I managed to run the script.
