Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a tensor from a list of numpy.ndarrays is extremely slow #189

Open
zakaria-narjis opened this issue Sep 3, 2023 · 1 comment
Open

Comments

@zakaria-narjis
Copy link

/usr/local/lib/python3.10/dist-packages/pfrl/replay_buffer.py:180: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at ../torch/csrc/utils/tensor_new.cpp:245.) "action": torch.as_tensor(

"action": torch.as_tensor(

I found something related to this issue pytorch/pytorch#13918

@Pranav-Malpure
Copy link

I was facing the same issue, I think this is because of some lazy development of PFRL. This is how I solved it:
replace the below

"action": torch.as_tensor(
            [elem[0]["action"] for elem in experiences], device=device
        )

by

"action": torch.from_numpy(
            np.asarray([elem[0]["action"] for elem in experiences])).to(device)

This should solve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants