'--cpu' flag causes IndexError: list index out of range
See original GitHub issueRun:
python -m spinup.run ppo --hid [32,32] --env LunarLander-v2 --exp_name installtest --gamma 0.999 --cpu 12 --seed 42
After a random number of epochs, ‘IndexError: list index out of range’ occurs:
File "/home/steve/spinningup/spinup/utils/logx.py", line 321, in log_tabular
vals = np.concatenate(v) if isinstance(v[0], np.ndarray) and len(v[0].shape)>0 else v
IndexError: list index out of range
Despite passing --seed, this is not deterministic, but always seems to happen within the first ~20 epochs. The problem appears to be that v is [], hence the attempt to access v[0] fails.
–cpu auto also has the problem Only --cpu 1 seems to be safe.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
List Index Out of Range – Python Error Message Solved
You'll get the Indexerror: list index out of range error when iterating through a list and trying to access an item that doesn't...
Read more >How can I avoid IndexError: list index out of range when the ...
Show activity on this post. Lets say I have a split string that can have up to x amount of words, and that...
Read more >how to solve this IndexError list index out of range in python ...
If you are using a loop to access an item, make sure that the loop accounts for the fact that lists are indexed...
Read more >ansible/buster: flatpak_remote: IndexError: list index out of range
... flatpak_remote: IndexError: list index out of range ... (SMP w/8 CPU cores) Kernel taint flags: TAINT_USER Locale: LANG=ca_ES.
Read more >1942261 – rteval failed with "IndexError: list index out of range ...
In the case I created myself, rteval is using code in systopology.py (there are a few other spots that do similar things that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was running into this issue with PPO. Basically, the “steps_per_epoch” parameter must be at least as big as the max episode length of the environment. For CartPole-v1, this is 500, so the “steps_per_epoch” must be > 500.
The default setting in test_ppo.py is 100, which is not enough.
I just stumbled on this same problem and can confirm the reason is what @jachiam guessed above.
I think, however, that the workaround suggested by @richardrl (thanks!) is ONLY correct for non-parallel training. The actual number of steps in the main loop is
local_steps_per_epoch
(which is notsteps_per_epoch
, but ‘local_steps_per_epoch’, calculated aslocal_steps_per_epoch = int(steps_per_epoch / num_procs())
). If you setsteps_per_epoch
at 4000 and `–num_cpu’ is say 4, each of the four loops will run for only 1000 steps.So what has worked for me (so far) is to set
steps_per_epoch
to, at least,max_ep_len
timesnum_procs()
, e.g.:max_ep_len
= 2000--cpu
= 4steps_per_epoch
>= 8000