# Parameters in training model for integrating datasets with scVI in R

**URL:** <https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522>\
**Category:** scvi-tools\
**Tags:** integration, scvi, model-fit\
**Created:** [March 1, 2025, 8:00am UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522 "2025-03-01T08:00:06Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![joweihsieh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/joweihsieh/32/1326_2.png) [@joweihsieh](https://discourse.scverse.org/u/joweihsieh)\
**Post date:** [March 1, 2025, 8:00am UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/1 "2025-03-01T08:00:06Z")

</div>

Thanks for developing this tool!!

I was trying to use scVI to integrate my datasets. Following the instructions ([Integrating datasets with scVI in R — scvi-tools](https://docs.scvi-tools.org/en/stable/tutorials/notebooks/scrna/scvi_in_R.html)), I was able to run the script successfully without changing any parameters in the training model. My next step was trying to change some parameters in the training model, but I encountered errors. Could you please help me resolve these issues? Thanks!

============

> model ← scvi$model$SCVI(adata\_5\_in\_1, n\_latent = 5)

Error in py\_call\_impl(callable, call\_args$unnamed, call\_args$named) :  
TypeError: empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType), but expected one of:

- (tuple of ints size, \*, tuple of names names, torch.memory\_format memory\_format = None, torch.dtype dtype = None, torch.layout layout = None, torch.device device = None, bool pin\_memory = False, bool requires\_grad = False)
- (tuple of ints size, \*, torch.memory\_format memory\_format = None, Tensor out = None, torch.dtype dtype = None, torch.layout layout = None, torch.device device = None, bool pin\_memory = False, bool requires\_grad = False)

> reticulate::py\_last\_error()

── Python Exception Message ──────────────────────────────────────────────────────────────────────────────────────  
Traceback (most recent call last):  
File “/home/f06b22037/SSD2/utility/miniconda3/envs/scvi-env/lib/python3.12/site-packages/scvi/model/\_scvi.py”, line 162, in **init**  
self.module = self.\_module\_cls(  
^^^^^^^^^^^^^^^^^  
File “/home/f06b22037/SSD2/utility/miniconda3/envs/scvi-env/lib/python3.12/site-packages/scvi/module/\_vae.py”, line 235, in **init**  
self.z\_encoder = Encoder(  
^^^^^^^^  
File “/home/f06b22037/SSD2/utility/miniconda3/envs/scvi-env/lib/python3.12/site-packages/scvi/nn/\_base\_components.py”, line 260, in **init**  
self.mean\_encoder = nn.Linear(n\_hidden, n\_output)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/home/f06b22037/SSD2/utility/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/nn/modules/linear.py”, line 106, in **init**  
torch.empty((out\_features, in\_features), \*\*factory\_kwargs)  
TypeError: empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType), but expected one of:

- (tuple of ints size, \*, tuple of names names, torch.memory\_format memory\_format = None, torch.dtype dtype = None, torch.layout layout = None, torch.device device = None, bool pin\_memory = False, bool requires\_grad = False)
- (tuple of ints size, \*, torch.memory\_format memory\_format = None, Tensor out = None, torch.dtype dtype = None, torch.layout layout = None, torch.device device = None, bool pin\_memory = False, bool requires\_grad = False)

── R Traceback ───────────────────────────────────────────────────────────────────────────────────────────────────  
▆

1. └─scvi$model$SCVI(adata\_5\_in\_1, n\_latent = 5)
2. └─reticulate:::py\_call\_impl(callable, call\_args$unnamed, call\_args$named)  
See `reticulate::py_last_error()$r_trace$full_call` for more details.

---

<div class="post-metadata">

**Author:** ![cane11](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/cane11/32/241_2.png) [@cane11](https://discourse.scverse.org/u/cane11)\
**Post date:** [March 1, 2025, 8:14am UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/2 "2025-03-01T08:14:02Z")

</div>

Hi, I assume reticulate has issues interpreting 5. Can you try:

```auto
n_latent_value <- as.integer(5)
model <- scvi$model$SCVI(adata_5_in_1, n_latent = n_latent_value)

```

---

<div class="post-metadata">

**Author:** ![joweihsieh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/joweihsieh/32/1326_2.png) [@joweihsieh](https://discourse.scverse.org/u/joweihsieh)\
**Post date:** [March 1, 2025, 7:51pm UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/3 "2025-03-01T19:51:56Z")

</div>

Hi,

> n\_latent\_value ← as.integer(5)  
> model ← scvi$model$SCVI$create(adata\_5\_in\_1, n\_latent = n\_latent\_value)

# I tried but still have errors.

Error in py\_get\_attr(x, name) :  
AttributeError: type object ‘SCVI’ has no attribute ‘create’  
Run `reticulate::py_last_error()` for details.

> reticulate::py\_last\_error()

── Python Exception Message ──────────────────────────────────────────────────────────────────────────────────────  
AttributeError: type object ‘SCVI’ has no attribute ‘create’

── R Traceback ───────────────────────────────────────────────────────────────────────────────────────────────────  
▆

1. ├─scvi$model$SCVI$create
2. └─reticulate:::`$.python.builtin.object`(scvi$model$SCVI, create)
3. └─reticulate:::py\_get\_attr\_or\_item(x, name, TRUE)
4. 

```
└─reticulate::py_get_attr(x, name)

```

See `reticulate::py_last_error()$r_trace$full_call` for more details.

── Python Exception Message ──────────────────────────────────────────────────────────────────────────────────────  
AttributeError: type object ‘SCVI’ has no attribute ‘create’

── R Traceback ───────────────────────────────────────────────────────────────────────────────────────────────────  
▆

1. ├─scvi$model$SCVI$create
2. └─reticulate:::`$.python.builtin.object`(scvi$model$SCVI, create)
3. └─reticulate:::py\_get\_attr\_or\_item(x, name, TRUE)
4. 

```
└─reticulate::py_get_attr(x, name)

```

See `reticulate::py_last_error()$r_trace$full_call` for more details.

> reticulate::py\_last\_error()$r\_trace$full\_call  
> [[1]]  
> scvi$model$SCVI$create

[[2]]  
`$.python.builtin.object`(scvi$model$SCVI, create)

[[3]]  
py\_get\_attr\_or\_item(x, name, TRUE)

[[4]]  
py\_get\_attr(x, name)

---

<div class="post-metadata">

**Author:** ![cane11](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/cane11/32/241_2.png) [@cane11](https://discourse.scverse.org/u/cane11)\
**Post date:** [March 1, 2025, 8:09pm UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/4 "2025-03-01T20:09:13Z")

</div>

See edit above. Sorry for the typo.

---

<div class="post-metadata">

**Author:** ![joweihsieh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/joweihsieh/32/1326_2.png) [@joweihsieh](https://discourse.scverse.org/u/joweihsieh)\
**Post date:** [March 1, 2025, 8:21pm UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/5 "2025-03-01T20:21:24Z")

</div>

It works!! Thank you!!

---

<div class="post-metadata">

**Author:** ![joweihsieh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/joweihsieh/32/1326_2.png) [@joweihsieh](https://discourse.scverse.org/u/joweihsieh)\
**Post date:** [March 2, 2025, 11:30pm UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/6 "2025-03-02T23:30:36Z")

</div>

Could you please share some suggestions on which parameters we can adjust to enhance the integration performance? I am planning to try n\_hidden, n\_layers and n\_latent\_value.

Thanks!!

---

<div class="post-metadata">

**Author:** ![ori-kron-wis](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/ori-kron-wis/32/1099_2.png) [@ori-kron-wis](https://discourse.scverse.org/u/ori-kron-wis)\
**Post date:** [March 3, 2025, 8:29am UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/7 "2025-03-03T08:29:11Z")

</div>

Hi,  
Practically all model/training parameters are open for tune and can affect the integration performance. Also the selection of batch key is a crucial factor of course. You can use our autotune to try to find an optimal set of parameters, check our documentation in the subject.

---

<div class="post-metadata">

**Author:** ![joweihsieh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/joweihsieh/32/1326_2.png) [@joweihsieh](https://discourse.scverse.org/u/joweihsieh)\
**Post date:** [March 5, 2025, 8:04am UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/8 "2025-03-05T08:04:48Z")

</div>

Hi,

I would like to use GPU to speed up the process. I got some errors…It seems to result from PyTorch and CUDA so I tried to re-install PyTorch. But it still failed…  
Just wonder if you have any idea? Thanks!!!

========

> Sys.setenv(CUDA\_VISIBLE\_DEVICES = “1”)  
> torch$cuda$is\_available()  
> [1] TRUE  
> scvi$model$SCVI$setup\_anndata(adata\_5\_in\_1, batch\_key = “batch”)  
> model ← scvi$model$SCVI(adata\_5\_in\_1)  
> model$train(accelerator=“gpu”)  
> GPU available: True (cuda), used: True  
> TPU available: False, using: 0 TPU cores  
> HPU available: False, using: 0 HPUs  
> Error in py\_call\_impl(callable, call\_args$unnamed, call\_args$named) :  
> torch.cuda.DeferredCudaCallError: CUDA call failed lazily at initialization with error: device \>= 0 && device \< num\_gpus INTERNAL ASSERT FAILED at “…/aten/src/ATen/cuda/CUDAContext.cpp”:49, please report a bug to PyTorch. device=1, num\_gpus=

\<…truncated…\> 1360, in \_find\_and\_load  
File “”, line 1331, in \_find\_and\_load\_unlocked  
File “”, line 935, in \_load\_unlocked  
File “”, line 999, in exec\_module  
File “”, line 488, in \_call\_with\_frames\_removed  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/cuda/ **init**.py”, line 264, in   
\_lazy\_call(\_check\_capability)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/cuda/ **init**.py”, line 261, in \_lazy\_call  
\_queued\_calls.append((callable, traceback.format\_stack()))

Run `reticulate::py_last_error()` for details.

── Python Exception Message ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────  
Traceback (most recent call last):  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/cuda/ **init**.py”, line 332, in \_lazy\_init  
queued\_call()  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/cuda/ **init**.py”, line 200, in \_check\_capability  
capability = get\_device\_capability(d)  
^^^^^^^^^^^^^^^^^^^^^^^^  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/cuda/ **init**.py”, line 509, in get\_device\_capability  
prop = get\_device\_properties(device)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/cuda/ **init**.py”, line 527, in get\_device\_properties  
return \_get\_device\_properties(device) # type: ignore[name-defined]  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
RuntimeError: device \>= 0 && device \< num\_gpus INTERNAL ASSERT FAILED at “…/aten/src/ATen/cuda/CUDAContext.cpp”:49, please report a bug to PyTorch. device=1, num\_gpus=

The above exception was the direct cause of the following exception:

Traceback (most recent call last):  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/scvi/model/base/\_training\_mixin.py”, line 161, in train  
return runner()  
^^^^^^^^  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/scvi/train/\_trainrunner.py”, line 96, in **call**  
self.trainer.fit(self.training\_plan, self.data\_splitter)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/scvi/train/\_trainer.py”, line 210, in fit  
super().fit(\*args, \*\*kwargs)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/lightning/pytorch/trainer/trainer.py”, line 539, in fit  
call.\_call\_and\_handle\_interrupt(  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/lightning/pytorch/trainer/call.py”, line 47, in \_call\_and\_handle\_interrupt  
return trainer\_fn(\*args, \*\*kwargs)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/lightning/pytorch/trainer/trainer.py”, line 575, in \_fit\_impl  
self.\_run(model, ckpt\_path=ckpt\_path)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/lightning/pytorch/trainer/trainer.py”, line 938, in \_run  
self.strategy.setup\_environment()  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/lightning/pytorch/strategies/strategy.py”, line 129, in setup\_environment  
self.accelerator.setup\_device(self.root\_device)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/lightning/pytorch/accelerators/cuda.py”, line 46, in setup\_device  
\_check\_cuda\_matmul\_precision(device)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/lightning/fabric/accelerators/cuda.py”, line 161, in \_check\_cuda\_matmul\_precision  
if not torch.cuda.is\_available() or not \_is\_ampere\_or\_later(device):  
^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/lightning/fabric/accelerators/cuda.py”, line 155, in \_is\_ampere\_or\_later  
major, \_ = torch.cuda.get\_device\_capability(device)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/cuda/ **init**.py”, line 509, in get\_device\_capability  
prop = get\_device\_properties(device)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/cuda/ **init**.py”, line 523, in get\_device\_properties  
\_lazy\_init() # will define \_get\_device\_properties  
^^^^^^^^^^^^  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/cuda/ **init**.py”, line 338, in \_lazy\_init  
raise DeferredCudaCallError(msg) from e  
torch.cuda.DeferredCudaCallError: CUDA call failed lazily at initialization with error: device \>= 0 && device \< num\_gpus INTERNAL ASSERT FAILED at “…/aten/src/ATen/cuda/CUDAContext.cpp”:49, please report a bug to PyTorch. device=1, num\_gpus=

CUDA call was originally invoked at:

File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 122, in \_find\_and\_load\_hook  
return \_run\_hook(name, \_hook)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 96, in \_run\_hook  
module = hook()  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 120, in \_hook  
return _find\_and\_load(name, import_)  
File “”, line 1360, in \_find\_and\_load  
File “”, line 1331, in \_find\_and\_load\_unlocked  
File “”, line 935, in \_load\_unlocked  
File “”, line 999, in exec\_module  
File “”, line 488, in \_call\_with\_frames\_removed  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/anndata/ **init**.py”, line 39, in   
from .io import read\_h5ad, read\_zarr  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 122, in \_find\_and\_load\_hook  
return \_run\_hook(name, \_hook)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 96, in \_run\_hook  
module = hook()  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 120, in \_hook  
return _find\_and\_load(name, import_)  
File “”, line 1360, in \_find\_and\_load  
File “”, line 1331, in \_find\_and\_load\_unlocked  
File “”, line 935, in \_load\_unlocked  
File “”, line 999, in exec\_module  
File “”, line 488, in \_call\_with\_frames\_removed  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/anndata/io.py”, line 7, in   
from .\_io.h5ad import read\_h5ad, write\_h5ad  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 122, in \_find\_and\_load\_hook  
return \_run\_hook(name, \_hook)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 96, in \_run\_hook  
module = hook()  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 120, in \_hook  
return _find\_and\_load(name, import_)  
File “”, line 1360, in \_find\_and\_load  
File “”, line 1331, in \_find\_and\_load\_unlocked  
File “”, line 935, in \_load\_unlocked  
File “”, line 999, in exec\_module  
File “”, line 488, in \_call\_with\_frames\_removed  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/anndata/\_io/h5ad.py”, line 25, in   
from …experimental import read\_dispatched  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 122, in \_find\_and\_load\_hook  
return \_run\_hook(name, \_hook)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 96, in \_run\_hook  
module = hook()  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 120, in \_hook  
return _find\_and\_load(name, import_)  
File “”, line 1360, in \_find\_and\_load  
File “”, line 1331, in \_find\_and\_load\_unlocked  
File “”, line 935, in \_load\_unlocked  
File “”, line 999, in exec\_module  
File “”, line 488, in \_call\_with\_frames\_removed  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/anndata/experimental/ **init**.py”, line 12, in   
from .pytorch import AnnLoader  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 122, in \_find\_and\_load\_hook  
return \_run\_hook(name, \_hook)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 96, in \_run\_hook  
module = hook()  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 120, in \_hook  
return _find\_and\_load(name, import_)  
File “”, line 1360, in \_find\_and\_load  
File “”, line 1331, in \_find\_and\_load\_unlocked  
File “”, line 935, in \_load\_unlocked  
File “”, line 999, in exec\_module  
File “”, line 488, in \_call\_with\_frames\_removed  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/anndata/experimental/pytorch/ **init**.py”, line 3, in   
from .\_annloader import AnnLoader  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 122, in \_find\_and\_load\_hook  
return \_run\_hook(name, \_hook)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 96, in \_run\_hook  
module = hook()  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 120, in \_hook  
return _find\_and\_load(name, import_)  
File “”, line 1360, in \_find\_and\_load  
File “”, line 1331, in \_find\_and\_load\_unlocked  
File “”, line 935, in \_load\_unlocked  
File “”, line 999, in exec\_module  
File “”, line 488, in \_call\_with\_frames\_removed  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/anndata/experimental/pytorch/\_annloader.py”, line 19, in   
import torch  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 122, in \_find\_and\_load\_hook  
return \_run\_hook(name, \_hook)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 96, in \_run\_hook  
module = hook()  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 120, in \_hook  
return _find\_and\_load(name, import_)  
File “”, line 1360, in \_find\_and\_load  
File “”, line 1331, in \_find\_and\_load\_unlocked  
File “”, line 935, in \_load\_unlocked  
File “”, line 999, in exec\_module  
File “”, line 488, in \_call\_with\_frames\_removed  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/ **init**.py”, line 1954, in   
\_C.\_initExtension(\_manager\_path())  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 122, in \_find\_and\_load\_hook  
return \_run\_hook(name, \_hook)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 96, in \_run\_hook  
module = hook()  
File “/home/guest001/miniconda3/envs/scvi-env/lib/R/library/reticulate/python/rpytools/loader.py”, line 120, in \_hook  
return _find\_and\_load(name, import_)  
File “”, line 1360, in \_find\_and\_load  
File “”, line 1331, in \_find\_and\_load\_unlocked  
File “”, line 935, in \_load\_unlocked  
File “”, line 999, in exec\_module  
File “”, line 488, in \_call\_with\_frames\_removed  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/cuda/ **init**.py”, line 264, in   
\_lazy\_call(\_check\_capability)  
File “/home/guest001/miniconda3/envs/scvi-env/lib/python3.12/site-packages/torch/cuda/ **init**.py”, line 261, in \_lazy\_call  
\_queued\_calls.append((callable, traceback.format\_stack()))

── R Traceback ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────  
▆

1. └─model$train(accelerator = “gpu”)
2. └─reticulate:::py\_call\_impl(callable, call\_args$unnamed, call\_args$named)  
See `reticulate::py_last_error()$r_trace$full_call` for more details.

=============  
Here is my GPU information:

Wed Mar 5 15:50:35 2025  
±----------------------------------------------------------------------------------------+  
| NVIDIA-SMI 550.90.07 Driver Version: 550.90.07 CUDA Version: 12.4 |  
|-----------------------------------------±-----------------------±---------------------+  
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |  
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |  
| | | MIG M. |  
|=========================================+========================+======================|  
| 0 Quadro P4000 Off | 00000000:17:00.0 Off | N/A |  
| 85% 85C P0 66W / 105W | 7461MiB / 8192MiB | 100% Default |  
| | | N/A |  
±----------------------------------------±-----------------------±---------------------+  
| 1 Quadro P1000 Off | 00000000:73:00.0 Off | N/A |  
| 34% 29C P8 N/A / N/A | 61MiB / 4096MiB | 0% Default |  
| | | N/A |  
±----------------------------------------±-----------------------±---------------------+

±----------------------------------------------------------------------------------------+  
| Processes: |  
| GPU GI CI PID Type Process name GPU Memory |  
| ID ID Usage |  
|=========================================================================================|  
| 0 N/A N/A 3725 G /usr/lib/xorg/Xorg 4MiB |  
| 0 N/A N/A 6867 C dorado\_basecall\_server 910MiB |  
| 0 N/A N/A 1438629 C guppy\_basecaller 6542MiB |  
| 1 N/A N/A 3725 G /usr/lib/xorg/Xorg 12MiB |  
| 1 N/A N/A 5471 G /usr/bin/gnome-shell 2MiB |  
| 1 N/A N/A 6867 C dorado\_basecall\_server 40MiB |  
±----------------------------------------------------------------------------------------+  
nvcc: NVIDIA (R) Cuda compiler driver  
Copyright (c) 2005-2025 NVIDIA Corporation  
Built on Wed\_Jan\_15\_19:20:09\_PST\_2025  
Cuda compilation tools, release 12.8, V12.8.61  
Build cuda\_12.8.r12.8/compiler.35404655\_0

======== re-installation  
pip uninstall torch torchvision torchaudio -y  
pip install torch torchvision torchaudio --index-url [https://download.pytorch.org/whl/cu121](https://download.pytorch.org/whl/cu121)

---

<div class="post-metadata">

**Author:** ![ori-kron-wis](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/ori-kron-wis/32/1099_2.png) [@ori-kron-wis](https://discourse.scverse.org/u/ori-kron-wis)\
**Post date:** [March 5, 2025, 8:18am UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/9 "2025-03-05T08:18:10Z")

</div>

kinda hard for me to understand whats going on.  
I do see some anndata related messages.

My suggestion to you is to: create a new clean environment, install scvi-tools v1.3 on python 3.12 backend & make sure you can run code (any simple code, not scvi) on the GPU, given this torch + cuda settings you have in your R env, then move to try to run a scvi code, and start from a very basic dummy test.

does the same code trains on the cpu? so we will know there no data issues

---

<div class="post-metadata">

**Author:** ![joweihsieh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/joweihsieh/32/1326_2.png) [@joweihsieh](https://discourse.scverse.org/u/joweihsieh)\
**Post date:** [March 5, 2025, 8:30am UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/10 "2025-03-05T08:30:32Z")

</div>

> [@ori-kron-wis](#):
>
> does the same code trains on the cpu? so we will know there no data issues

Yes! The data is able to be trained on cpu.

scvi$model$SCVI$setup\_anndata(adata\_5\_in\_1, batch\_key = “batch”)  
model ← scvi$model$SCVI(adata\_5\_in\_1)  
model$train()

---

<div class="post-metadata">

**Author:** ![joweihsieh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/joweihsieh/32/1326_2.png) [@joweihsieh](https://discourse.scverse.org/u/joweihsieh)\
**Post date:** [March 5, 2025, 9:41am UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/11 "2025-03-05T09:41:30Z")

</div>

> [@ori-kron-wis](#):
>
> My suggestion to you is to: create a new clean environment, install scvi-tools v1.3 on python 3.12 backend & make sure you can run code (any simple code, not scvi) on the GPU, given this torch + cuda settings you have in your R env, then move to try to run a scvi code, and start from a very basic dummy test.

Thanks for the suggestions!!! It works!!

---

<div class="post-metadata">

**Author:** ![joweihsieh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/joweihsieh/32/1326_2.png) [@joweihsieh](https://discourse.scverse.org/u/joweihsieh)\
**Post date:** [March 7, 2025, 7:44am UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/12 "2025-03-07T07:44:17Z")

</div>

> [@ori-kron-wis](#):
>
> You can use our autotune to try to find an optimal set of parameters, check our documentation in the subject

Hi,

I tried running the autotune method you suggested, but I couldn’t get it to work.

# === Here is my script ===

# Import the necessary Python modules

scvi ← import(“scvi”)  
scvi\_data ← import(“scvi.data”) # Import scvi.data for datasets  
torch ← import(“torch”)  
anndata ← import(“anndata”)  
tune ← import(“ray.tune”)  
ray ← import(“ray”)

adata\_5\_in\_1 ← anndata$read\_h5ad(“adata\_5\_in\_1.h5ad”)

py$adata\_5\_in\_1 ← adata\_5\_in\_1

py\_run\_string("  
from scvi.model import SCVI  
from ray import tune

SCVI.setup\_anndata(adata\_5\_in\_1, batch\_key=‘batch’)

def train\_scvi(config):  
model = SCVI(  
adata\_5\_in\_1,  
n\_hidden=config[‘n\_hidden’],  
n\_layers=config[‘n\_layers’],  
n\_latent=config[‘n\_latent’],  
gene\_likelihood=config[‘gene\_likelihood’]  
)  
model.train(max\_epochs=100, plan\_kwargs={‘lr’: config[‘lr’]})  
return {‘elbo’: model.get\_elbo()}

search\_space = {  
‘n\_hidden’: tune.choice([64, 128, 256]),  
‘n\_layers’: tune.choice([1, 2, 3, 4]),  
‘n\_latent’: tune.choice([5, 10, 20, 30, 40, 50]),  
‘gene\_likelihood’: tune.choice([‘nb’, ‘zinb’]),  
‘lr’: tune.loguniform(1e-4, 1e-2)  
}

analysis = tune.run(  
train\_scvi,  
config=search\_space,  
num\_samples=20, # Number of trials  
metric=‘elbo’,  
mode=‘min’  
)

best\_params = analysis.best\_config

ray.shutdown()  
")

# === Here are the errors ====

```
▆

```

1. └─reticulate::py\_run\_string(“\nanalysis = tune.run(\n train\_scvi,\n config=search\_space,\n num\_samples=5, # Reduce number of trials\n metric=‘elbo’,\n mode=‘min’\n)\n”)
2. └─reticulate:::py\_run\_string\_impl(code, local, convert)  
See `reticulate::py_last_error()$r_trace$full_call` for more details.

# === Then I tried some basic things and they are all good ===

#ray stop  
#ray start --head --num-cpus=50 --num-gpus=1

py\_run\_string("  
import os  
import ray

ray.shutdown()

os.environ[‘CUDA\_VISIBLE\_DEVICES’] = ‘1’

ray.init(address=‘auto’)  
print(ray.is\_initialized())  
")

# Test Training a Single SCVI Model

py\_run\_string("  
from scvi.model import SCVI

print(type(adata\_5\_in\_1))

SCVI.setup\_anndata(adata\_5\_in\_1, batch\_key=‘batch’)

model = SCVI(  
adata\_5\_in\_1,  
n\_hidden=128,  
n\_layers=2,  
n\_latent=20,  
gene\_likelihood=‘nb’  
)  
model.train(max\_epochs=10, plan\_kwargs={‘lr’: 0.001})  
print(‘Model trained successfully’)  
")

---

<div class="post-metadata">

**Author:** ![cane11](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/cane11/32/241_2.png) [@cane11](https://discourse.scverse.org/u/cane11)\
**Post date:** [March 7, 2025, 8:00am UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/13 "2025-03-07T08:00:53Z")

</div>

Hi, could you train directly in Python? This would make the error log much simpler and avoid some errors like wrong type setting that come with reticulate.

---

<div class="post-metadata">

**Author:** ![ori-kron-wis](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/ori-kron-wis/32/1099_2.png) [@ori-kron-wis](https://discourse.scverse.org/u/ori-kron-wis)\
**Post date:** [March 9, 2025, 12:36pm UTC](https://discourse.scverse.org/t/parameters-in-training-model-for-integrating-datasets-with-scvi-in-r/3522/14 "2025-03-09T12:36:23Z")

</div>

hey @joweihsieh  
I agree to try to run this directly on python, especially also because in the R code you run most of it in python code…

In any case, using scvi-tools 1.3v, we run the autotune code a bit different now. For example this was working for me in R env (just replace to your adata):

```auto
library(reticulate)
options(reticulate.verbose = TRUE)
py_module_available('scvi')
scvi <- import('scvi')
ray <- import('ray')

adata <- scvi$data$synthetic_iid()

py$adata <- adata

py_run_string("
from scvi.model import SCVI
from ray import tune
from scvi.data import synthetic_iid
from scvi.autotune import run_autotune

SCVI.setup_anndata(adata)

experiment = run_autotune(
  SCVI,
  adata,
  metrics=['elbo_validation'],
  mode='min',
  search_space={
    'model_params': {
      'n_hidden': tune.choice([64, 128, 256]),
      'n_layers': tune.choice([1, 2, 3, 4]),
      'n_latent': tune.choice([5, 10, 20, 30, 40, 50]),
      'gene_likelihood': tune.choice(['nb', 'zinb']),
    },
    'train_params': {
      'max_epochs': 100,
      'plan_kwargs': {'lr': tune.loguniform(1e-4, 1e-2)}
    },
  },
  num_samples=20,
  seed=0,
  scheduler='asha',
  searcher='hyperopt',
  ignore_reinit_error=True,
)
")

```
