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

Question about truncation (Problem with dimensionality) #7

Open
Palamabron opened this issue Aug 29, 2023 · 1 comment
Open

Question about truncation (Problem with dimensionality) #7

Palamabron opened this issue Aug 29, 2023 · 1 comment

Comments

@Palamabron
Copy link

Hi, I'm trying to implement TQC to play game called Trackmania using custom version of Tmrl which is available here. While trying to implement your code I encountered this problem, which I cannot solve due to lack of my knowledge of this subject.
(...) backup = r + (1 - d) * self.gamma * (sorted_z_part - alpha * next_log_pi) RuntimeError: The size of tensor a (46) must match the size of tensor b (128) at non-singleton dimension 1
And this is my fragment of code with tensor sizes in the comments:

# in this case batch size=128 and 2*[quantiles - top_quantiles_to_drop] = 46
with torch.no_grad():
            new_next_action, next_log_pi = self.model.actor(o2)  # Tensor(batch x 3), Tensor(batch)
            # Compute and cut quantiles at the next state
            next_q1 = self.model_target.q1(o2, new_next_action)  # Tensor(batch x quantiles)
            next_q2 = self.model_target.q2(o2, new_next_action)  # Tensor(batch x quantiles)
            next_z = torch.stack((next_q1, next_q2), dim=1)  # Tensor(batch x nets x quantiles)
            sorted_z, _ = torch.sort(next_z.reshape(batch_size, -1))
            sorted_z_part = sorted_z[:, :self.quantiles_total - self.top_quantiles_to_drop] # Tensor(batch x 2*[quantiles - top_quantiles_to_drop])
            # alpha: Tensor (1,)
            backup = r + (1 - d) * self.gamma * (sorted_z_part - alpha * next_log_pi)

While 2*[quantiles - top_quantiles_to_drop] > 1 my code cannot run and I don't how to fix it. Thanks for any help in advance. :)

@brickerino
Copy link
Contributor

brickerino commented Aug 30, 2023 via email

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