dgl icon indicating copy to clipboard operation
dgl copied to clipboard

A question about dgl.nn.PyTorch.EGTLayer

Open happyzhanglol opened this issue 1 year ago • 4 comments

I have a question about dgl.nn.PyTorch.EGTLayer. I don't know how to define the mask parameter in the forward function. According to the official documentation, I define the mask variable with the valid position set to 0 and the invalid position set to -inf. But my model weight always changes to Nan every time I execute the code. But that doesn't happen when I don't use the mask variable. So now I don't know how to define the mask variable. Can you give an example of using the mask variable? Thank you!

happyzhanglol avatar Oct 08 '23 01:10 happyzhanglol

The number of graph nodes I use is different, so I'll add nodes to each graph up to the maximum number of nodes. At the same time, the corresponding position of the mask variable is -inf

happyzhanglol avatar Oct 08 '23 01:10 happyzhanglol

This issue has been automatically marked as stale due to lack of activity. It will be closed if no further activity occurs. Thank you

github-actions[bot] avatar Nov 12 '23 01:11 github-actions[bot]

I think the Nans come from padding. As an example, for a batch of a 2-node graph and a 4-node graph, the mask should be

tensor([[[0., 0., -inf, -inf],
         [0., 0., -inf, -inf],
         [0., 0., -inf, -inf],
         [0., 0., -inf, -inf]],

        [[0., 0., 0., 0.],
         [0., 0., 0., 0.],
         [0., 0., 0., 0.],
         [0., 0., 0., 0.]]])

instead of

tensor([[[0., 0., -inf, -inf],
         [0., 0., -inf, -inf],
         [-inf, -inf, -inf, -inf],
         [-inf, -inf, -inf, -inf]],

        [[0., 0., 0., 0.],
         [0., 0., 0., 0.],
         [0., 0., 0., 0.],
         [0., 0., 0., 0.]]])

Rows full of -inf in the second example will lead to Nans because of a softmax operation with all input values as -inf.

rudongyu avatar Nov 23 '23 01:11 rudongyu

This issue has been automatically marked as stale due to lack of activity. It will be closed if no further activity occurs. Thank you

github-actions[bot] avatar Dec 24 '23 01:12 github-actions[bot]