pytorch / pytorch/rl

[BUG] Vmap call in value estimate not compatible with torch_geometric radius graph

Open
#2,537 0 comments 0 reactions 1 assignee View on GitHub

@vmoens is already working on this.

Since Nov 5, 2024.

bug
Dominant language
Python
Stars
3.6k
Forks
487
Avg merge
1d 1h
Merged PRs (30d)
207

Description

The vmap call to in the value estimators is giving rise to an incompatibility issue.

In particular, this is the call
https://github.com/pytorch/rl/blob/98b45a6132b0094e100ec047ea73ec41eb52c078/torchrl/objectives/value/advantages.py#L144

My problem today is in relation to a feature for GNNs.

Basically in GNN you might need to compute the graph adjacency from an input vector containing positions using this function
https://pytorch-geometric.readthedocs.io/en/latest/generated/torch_geometric.nn.pool.radius_graph.html

This function, given inputs of the same shape, could give outputs of different size and was not made to be vmap compatible.

Here is the closest reprod script I came up with

import torch
from torch_geometric.nn import radius_graph


class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x, batch):
        edge_index = radius_graph(x, r=3.5, batch=batch, loop=False)
        return x


model = Model()

x = torch.tensor([[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, 1.0], [0.5, 0.5]])
batch = torch.tensor([0, 0, 1, 1, 1])

# Normal call works
data_out = model(x, batch)

# Vmap does not
x = torch.stack([x, x], dim=0)
batch = torch.stack([batch, batch], dim=0)
data_out = torch.vmap(model, (0, 0))(x, batch)

Any suggestions?

In general I think that this specific vmap call has been cause of incompatibility for many, would it be possible to make it optional?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.