# Errors in training and predicting when the newest version of vak is installed

**URL:** <https://forum.vocalpy.org/t/errors-in-training-and-predicting-when-the-newest-version-of-vak-is-installed/71>\
**Category:** Q&A\
**Tags:** vak\
**Created:** [August 3, 2023, 10:11am UTC](https://forum.vocalpy.org/t/errors-in-training-and-predicting-when-the-newest-version-of-vak-is-installed/71 "2023-08-03T10:11:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jacqueline](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jacqueline](https://forum.vocalpy.org/u/Jacqueline)\
**Post date:** [August 3, 2023, 10:11am UTC](https://forum.vocalpy.org/t/errors-in-training-and-predicting-when-the-newest-version-of-vak-is-installed/71/1 "2023-08-03T10:11:38Z")

</div>

Hi,

I found a bug: if you install vak with the newest version of python and lightning package than there will be an error with the accelerator = ‘None’.

I installed the vak environment as such:

- Anaconda Powershell
- conda create -n vak-env python vak -c pytorch -c conda-forge
- conda activate vak-env
- conda install tweetynet -c conda-forge -c pytorch

if you try to execute vak predict and vak train you will get the error that the accelerator shouldn’t be ‘None’.  
You have to change that in the files:  
1: anaconda3 → vak-env → Lib → site-packages → vak → trainer.py  
in the file: line=60 → change to accelerator = ‘auto’  
2: anaconda3 → vak-env → Lib → site-packages → vak → core → predict.py  
in the file: line=205 → change to accelerator = ‘auto’

As far as I know the ‘None’ doesn’t work with the newest version of lightning package. I chack again which versions i installed. But this solution worked for me 🙂

I hope that helps others!!!

---

<div class="post-metadata">

**Author:** ![nicholdav](https://yyz2.discourse-cdn.com/flex032/user_avatar/forum.vocalpy.org/nicholdav/32/5_2.png) [@nicholdav](https://forum.vocalpy.org/u/nicholdav)\
**Post date:** [August 4, 2023, 1:04pm UTC](https://forum.vocalpy.org/t/errors-in-training-and-predicting-when-the-newest-version-of-vak-is-installed/71/2 "2023-08-04T13:04:00Z")

</div>

Hi @Jacqueline, welcome to the forum and thank you for letting us know about this.  
I’m sorry you’re running into this issue.

Thank you also for helping me find the bug.  
I think you are right that one way to fix this would be to fallback to `'auto'` in line 60 of trainer.py here:

> <https://github.com/vocalpy/vak/blob/3dcce70030ae9b1fd6d040e055def0d656a7512e/src/vak/trainer.py#L60>

It sounds like this fix is working for you right now – ideally you wouldn’t need to change code in an installed package though, because that might break other parts of the code that interact with it. It would be better if we fix this bug for you and everybody else and release a new version. (The thought of everybody manually changing code in installed packages and then creating a whole new class of bugs I can’t fix kind of scares me 😬 )

Could you please go ahead and raise an issue reporting this bug on the vocalpy/vak issue tracker here?

> **[Build software better, together](https://github.com/vocalpy/vak/issues/new?assignees=&labels=BUG&projects=&template=bug_report.md&title=BUG%3A)**
>
> GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 330 million projects.

That way we can be sure to fix it so no one else needs to change code, and we can give you credit for spotting the bug.

You all are training on CPU, right? I think I remember @koparkanya telling me that before. (I saw you had a Tuebi email so I assume you are in Lena’s lab – apologies if I’m mistaken).

I need to think a little more about the right way to fix this. People should be able to say they want to use `'cpu'` explicitly, so I don’t think it should be either `'cuda'` or `'auto'`. It might be better to just let people specify the `'accelerator'` option directly in the config, file although this forces people to learn about Lightning. But we can hash that out on the GitHub issue.

Thank you again, this is really helpful and I appreciate you sharing your solution with others!!! 🙏

---

<div class="post-metadata">

**Author:** ![nicholdav](https://yyz2.discourse-cdn.com/flex032/user_avatar/forum.vocalpy.org/nicholdav/32/5_2.png) [@nicholdav](https://forum.vocalpy.org/u/nicholdav)\
**Post date:** [August 9, 2023, 3:01pm UTC](https://forum.vocalpy.org/t/errors-in-training-and-predicting-when-the-newest-version-of-vak-is-installed/71/3 "2023-08-09T15:01:58Z")

</div>

Hi @Jacqueline,

Thank you again for catching this bug and suggesting a fix.

Just want to let you know I did raise an issue about it on the vak issue tracker:

> <https://github.com/vocalpy/vak/issues/687>
>
> \*\*Describe the bug\*\*
> Running \`vak train\` with version 1.0.0a1 and the device se…t to \`'cpu'\` causes a crash, as described in this forum post: https://forum.vocalpy.org/t/errors-in-training-and-predicting-when-the-newest-version-of-vak-is-installed/71
> 
> It produces the following traceback:
> \`\`\`python
> $ vak train data/configs/TeenyTweetyNet\_train\_audio\_cbin\_annot\_notmat.toml
> 2023-08-09 10:37:15,262 - vak.cli.train - INFO - vak version: 1.0.0a1
> 2023-08-09 10:37:15,263 - vak.cli.train - INFO - Logging results to ../vak-vocalpy/tests/data\_for\_tests/generated/results/train/audio\_cbin\_annot\_notmat/TeenyTweetyNet/results\_230809\_103715
> 2023-08-09 10:37:15,263 - vak.core.train - INFO - Loading dataset from .csv path: ../vak-vocalpy/tests/data\_for\_tests/generated/prep/train/audio\_cbin\_annot\_notmat/TeenyTweetyNet/032312\_prep\_230809\_103332.csv
> 2023-08-09 10:37:15,266 - vak.core.train - INFO - Size of timebin in spectrograms from dataset, in seconds: 0.002
> 2023-08-09 10:37:15,266 - vak.core.train - INFO - using training dataset from ../vak-vocalpy/tests/data\_for\_tests/generated/prep/train/audio\_cbin\_annot\_notmat/TeenyTweetyNet/032312\_prep\_230809\_103332.csv
> 2023-08-09 10:37:15,266 - vak.core.train - INFO - Total duration of training split from dataset (in s): 50.046
> 2023-08-09 10:37:15,380 - vak.core.train - INFO - number of classes in labelmap: 12
> 2023-08-09 10:37:15,380 - vak.core.train - INFO - no spect\_scaler\_path provided, not loading
> 2023-08-09 10:37:15,380 - vak.core.train - INFO - will normalize spectrograms
> 2023-08-09 10:37:15,449 - vak.core.train - INFO - Duration of WindowDataset used for training, in seconds: 50.046
> 2023-08-09 10:37:15,460 - vak.core.train - INFO - Total duration of validation split from dataset (in s): 15.948
> 2023-08-09 10:37:15,461 - vak.core.train - INFO - will measure error on validation set every 50 steps of training
> 2023-08-09 10:37:15,467 - vak.core.train - INFO - training TeenyTweetyNet
> Traceback (most recent call last):
> File "/home/pimienta/miniconda3/envs/vak-env/bin/vak", line 10, in \<module\>
> sys.exit(main())
> ^^^^^^
> File "/home/pimienta/miniconda3/envs/vak-env/lib/python3.11/site-packages/vak/\_\_main\_\_.py", line 48, in main
> cli.cli(command=args.command, config\_file=args.configfile)
> File "/home/pimienta/miniconda3/envs/vak-env/lib/python3.11/site-packages/vak/cli/cli.py", line 49, in cli
> COMMAND\_FUNCTION\_MAP\[command\](toml\_path=config\_file)
> File "/home/pimienta/miniconda3/envs/vak-env/lib/python3.11/site-packages/vak/cli/cli.py", line 8, in train
> train(toml\_path=toml\_path)
> File "/home/pimienta/miniconda3/envs/vak-env/lib/python3.11/site-packages/vak/cli/train.py", line 67, in train
> core.train(
> File "/home/pimienta/miniconda3/envs/vak-env/lib/python3.11/site-packages/vak/core/train.py", line 358, in train
> trainer = get\_default\_trainer(
> ^^^^^^^^^^^^^^^^^^^^
> File "/home/pimienta/miniconda3/envs/vak-env/lib/python3.11/site-packages/vak/trainer.py", line 66, in get\_default\_trainer
> trainer = lightning.Trainer(
> ^^^^^^^^^^^^^^^^^^
> File "/home/pimienta/miniconda3/envs/vak-env/lib/python3.11/site-packages/pytorch\_lightning/utilities/argparse.py", line 69, in insert\_env\_defaults
> return fn(self, \*\*kwargs)
> ^^^^^^^^^^^^^^^^^^
> File "/home/pimienta/miniconda3/envs/vak-env/lib/python3.11/site-packages/pytorch\_lightning/trainer/trainer.py", line 398, in \_\_init\_\_
> self.\_accelerator\_connector = \_AcceleratorConnector(
> ^^^^^^^^^^^^^^^^^^^^^^
> File "/home/pimienta/miniconda3/envs/vak-env/lib/python3.11/site-packages/pytorch\_lightning/trainer/connectors/accelerator\_connector.py", line 140, in \_\_init\_\_
> self.\_check\_config\_and\_set\_final\_flags(
> File "/home/pimienta/miniconda3/envs/vak-env/lib/python3.11/site-packages/pytorch\_lightning/trainer/connectors/accelerator\_connector.py", line 221, in \_check\_config\_and\_set\_final\_flags
> raise ValueError(
> ValueError: You selected an invalid accelerator name: \`accelerator=None\`. Available names are: auto, cpu, cuda, hpu, ipu, mps, tpu.
> \`\`\`
> 
> As reported in the forum post, this probably affects all CLI commands besides prep: predict, eval, learncurve -- I did not verify though.
> 
> \*\*To Reproduce\*\*
> Steps to reproduce the behavior:
> 1. Install vak 1.0.0a1 e.g. with conda
> \`\`\`console
> $ mamba create -n vak-env python vak -c pytorch -c conda-forge
> \`\`\`
> 2. Create a TOML configuration file with a \`\[TRAIN\]\` table that specifies \`device = 'cpu'\`
> (full file is attached)
> \`\`\`TOML
> \[TRAIN\]
> model = "TeenyTweetyNet"
> normalize\_spectrograms = true
> batch\_size = 4
> num\_epochs = 2
> val\_step = 50
> ckpt\_step = 200
> patience = 3
> num\_workers = 2
> device = "cpu"
> root\_results\_dir = "../vak-vocalpy/tests/data\_for\_tests/generated/results/train/audio\_cbin\_annot\_notmat/TeenyTweetyNet"
> dataset\_path = "../vak-vocalpy/tests/data\_for\_tests/generated/prep/train/audio\_cbin\_annot\_notmat/TeenyTweetyNet/032312\_prep\_230809\_103332.csv"
> \`\`\`
> 3. Run \`vak train config.toml\`
> 4. See error
> 
> \*\*Expected behavior\*\*
> \`vak train\` should run without crashing
> 
> \*\*Desktop (please complete the following information):\*\*
> - I verified this on Linux
> - Version 1.0.0a1
> \- I think Veit lab is using Mac OS tho 
> 
> \*\*Additional context\*\*
> What's going on here is that:
> \- High-level train/predict/eval functions call \`get\_default\_trainer\`
> \- Inside \`get\_trainer\`, if \`device\` is not set to \`cuda\`, we default to \`None\`, but \`None\` is not a valid option for \`accelerator\` (the argument used when instantiating \`Trainer\`)
> \[vocalpy/vak/blob/3dcce70030ae9b1fd6d040e055def0d656a7512e/src/vak/trainer.py#L60\](https://github.com/vocalpy/vak/blob/3dcce70030ae9b1fd6d040e055def0d656a7512e/src/vak/trainer.py#L60)
> \`\`\`
> if device == 'cuda':
> accelerator = 'gpu'
> else:
> accelerator = None
> \`\`\`
> \[TeenyTweetyNet\_train\_audio\_cbin\_annot\_notmat.zip\](https://github.com/vocalpy/vak/files/12304070/TeenyTweetyNet\_train\_audio\_cbin\_annot\_notmat.zip)

If you have a GitHub profile or if you can set one up, please feel free to reply on that issue stating that you’re the one who spotted it, so we can give you credit as a contributor

---

<div class="post-metadata">

**Author:** ![Jacqueline](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jacqueline](https://forum.vocalpy.org/u/Jacqueline)\
**Post date:** [August 10, 2023, 9:05am UTC](https://forum.vocalpy.org/t/errors-in-training-and-predicting-when-the-newest-version-of-vak-is-installed/71/4 "2023-08-10T09:05:39Z")

</div>

Hi @nicholdav,

thank you for raising the issue.

---

<div class="post-metadata">

**Author:** ![nicholdav](https://yyz2.discourse-cdn.com/flex032/user_avatar/forum.vocalpy.org/nicholdav/32/5_2.png) [@nicholdav](https://forum.vocalpy.org/u/nicholdav)\
**Post date:** [August 10, 2023, 12:56pm UTC](https://forum.vocalpy.org/t/errors-in-training-and-predicting-when-the-newest-version-of-vak-is-installed/71/5 "2023-08-10T12:56:12Z")

</div>

Sure thing! I know you’re probably busy doing grad student stuff 🙂 Thanks again for spotting this

---

<div class="post-metadata">

**Author:** ![nicholdav](https://yyz2.discourse-cdn.com/flex032/user_avatar/forum.vocalpy.org/nicholdav/32/5_2.png) [@nicholdav](https://forum.vocalpy.org/u/nicholdav)\
**Post date:** [September 11, 2023, 4:04pm UTC](https://forum.vocalpy.org/t/errors-in-training-and-predicting-when-the-newest-version-of-vak-is-installed/71/6 "2023-09-11T16:04:19Z")

</div>

Hi @Jacqueline just letting you know I just released version 1.0.0a2 that includes a temporary fix for this issue. You should be able to `pip install vak==1.0.0a2` now to test it. Please do let us know if that fixes things for you if you have a chance.

We plan to replace the `device` option in the configuration file with `accelerator` so you can configure this directly and there’s less of an opportunity for this kind of bug to slip in, as discussed here: [ENH: Refer to 'accelerator' not 'device' · Issue #691 · vocalpy/vak · GitHub](https://github.com/vocalpy/vak/issues/691)

Thank you again for catching the bug.
