Can't run GCN_chemo.py ( an example on GitHub)

code:


seems work well on the author’s side.

data:


solubility.train.sdf and solubility.test.sdf

On my side, the following is the Error info.
DGLError: Cannot update column of scheme Scheme(shape=(256,), dtype=torch.float32) using feature of scheme Scheme (shape=(35,), dtype=torch.float32).

Can you try replacing

class NodeApplyModule(nn.Module):
    def __init__(self, in_feats, out_feats, activation):
        super(NodeApplyModule, self).__init__()
        self.linear = nn.Linear(in_feats, out_feats)
        self.activation = activation
    
    def forward(self, node):
        h = self.linear(node.data['h'])
        h = self.activation(h)
        return {'h': h}
    

class GCN(nn.Module):
    def __init__(self, in_feats, out_feats, activation):
        super(GCN, self).__init__()
        self.apply_mod = NodeApplyModule(in_feats, out_feats, activation)
    
    def forward(self, g, feature):
        g.ndata['h'] = feature
        g.update_all(msg, reduce)
        g.apply_nodes(func=self.apply_mod)
        h =  g.ndata.pop('h')
        #print(h.shape)
        return h

with

class GCN(nn.Module):
    def __init__(self, in_feats, out_feats, activation):
        super(GCN, self).__init__()
        self.linear = nn.Linear(in_feats, out_feats)
        self.activation = activation
    
    def forward(self, g, feature):
        g.ndata['h'] = feature
        g.update_all(msg, reduce)
        h = self.linear(g.ndata['h'])
        if self.activation is not None:
            h = self.activation(h)
        return h

Nevertheless, I’m not sure if this is a bug or a feature due to the new DGL version …

1 Like

It works. Thanks a lot:D

This turns out to be a bug and should be fixed with PR #2223.