Else block fails because slice is unhashable type
Hi! I'm just playing with PufferLib and I found an error when running this command:
python demo.py --env puffer_snake --mode train --track
This patch is (maybe) a fix for this, though I naively don't know what's important about the else branch here. The errors I were getting were:
│ /home/relh/Code/PufferLib/clean_pufferl.py:124 in <dictcomp> │
│ │
│ 121 │ │ │ # TODO: Doesn't exist in native envs │
│ 122 │ │ │ n = vecenv.agents_per_batch │
│ 123 │ │ │ shape = (n, policy.hidden_size) │
│ ❱ 124 │ │ │ lstm_h = {slice(i*n, (i+1)*n):torch.zeros(shape).to(config.device) for i in │
│ 125 │ │ │ lstm_c = {slice(i*n, (i+1)*n):torch.zeros(shape).to(config.device) for i in │
│ 126 │ │
│ 127 │ minibatch_size = min(config.minibatch_size, config.max_minibatch_size) │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: unhashable type: 'slice'
I tried changing to a tuple but I get this, so rather than making everything ugly I tried deleting the else branch and now things run again (but unclear on if they work).
│ 598 │ │
│ 599 │ # Fast path for fully vectorized envs │
│ 600 │ if data.config.env_batch_size == 1: │
│ ❱ 601 │ │ l = data.ep_lengths[env_id.start].item() │
│ 602 │ │ batch_rows = slice(data.ep_indices[env_id.start].item(), 1+data.ep_indices[env_i │
│ 603 │ else: │
│ 604 │ │ l = data.ep_lengths[env_id] │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'tuple' object has no attribute 'start'
I wrote an alternative that's ugly but also works, where we keep the potentially-necessary-multiagent-esque-stuff from the lstm_h and lstm_c dict creation but then we add annoying if statements later. This one also runs!
What branch are you on? Testing on dev branch in PufferTank dev branch works fine.
Oh, I thought I had checked Puffertank branches for dev but I hadn't.. thanks~ ignore this
Okay well I re-built puffertank from dev branch (base -> puffer-deps -> puffertank)
(base) relh@titan ~/Code/puffertank dev ● bash docker.sh test
Running Docker image pufferai/puffertank:dev and executing shell...
CUDA Version: V12.4.131
/root/version_check.py:1: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources as pkg
/root/version_check.py:12: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
if version(installed_version) < version(latest_version):
pufferlib 2.0.6 is up to date.
🐡
🐡
🐡
🐡
🐡
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
(base) ✘ relh@titan ~/Code/PufferLib dev ● docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
pufferai/puffertank dev f333e3e393a2 53 minutes ago 23.3GB
pufferai/puffer-deps dev 2b9bdcd4776b 57 minutes ago 20.3GB
pufferai/base dev bc977c6f06e6 About an hour ago 19.6GB
And I still get this slice unhashable type list error when I run this:
python demo.py --env puffer_snake --track
Which I guess makes sense because it won't fix the slice issue:
│ /home/relh/Code/PufferLib/clean_pufferl.py:124 in <dictcomp> │
│ │
│ 121 │ │ │ # TODO: Doesn't exist in native envs │
│ 122 │ │ │ n = vecenv.agents_per_batch │
│ 123 │ │ │ shape = (n, policy.hidden_size) │
│ ❱ 124 │ │ │ lstm_h = {slice(i*n, (i+1)*n):torch.zeros(shape).to(config.device) for i in │
│ 125 │ │ │ lstm_c = {slice(i*n, (i+1)*n):torch.zeros(shape).to(config.device) for i in │
│ 126 │ │
│ 127 │ minibatch_size = min(config.minibatch_size, config.max_minibatch_size) │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: unhashable type: 'slice'
But I'm new to PufferLib sooo.. Anyways it's all good hope this helps someone.