Code Monkey home page Code Monkey logo

largegt's Introduction

LargeGT: Graph Transformers for Large Graphs

Source code for the paper Graph Transformers for Large Graphs

by Vijay Prakash Dwivedi, Yozen Liu, Anh Tuan Luu, Xavier Bresson, Neil Shah and Tong Zhao.

The paper proposes LargeGT which is a scalable Graph Transformer framework designed to efficiently handle large-scale graphs, featuring a combination of fast neighborhood sampling and local-global attention mechanisms.

LargeGT Framework

1. Installation

To setup the Python environment with conda, follow these instructions.

2. Download data

Download preprocessed data by running this script as:

cd data  
bash download_data.sh

3. Run experiments

To run an experiment, run the command:

python main.py --dataset <dataset name> --sample_node_len <value of K>

For example:

python main.py --dataset ogbn-products --sample_node_len 100

To reproduce results, follow these steps.

4. Acknowledgement

This code repository leverages the open-source codebases released by GOAT and NAGphormer.

5. Reference

๐Ÿ“ƒ Paper on arXiv

@article{dwivedi2023graph,
  title={Graph Transformers for Large Graphs},
  author={Dwivedi, Vijay Prakash and Liu, Yozen and Luu, Anh Tuan and Bresson, Xavier and Shah, Neil and Zhao, Tong},
  journal={arXiv preprint arXiv:2312.11109},
  year={2023}
}

6. Contact

Please contact [email protected] for any questions.

largegt's People

Contributors

vijaydwivedi75 avatar zhao-tong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

largegt's Issues

The "LocalModel()" used in the model.py file is inconsistent with the "LocalModel()" defined in your local_module.py.

Hi, great work you're doing! However, while trying to reproduce the results, I encountered the error "TypeError: LocalModule.forward() takes 2 positional arguments but 3 were given." I guess this is because the "LocalModel()" used in the model.py file is not consistent with the "LocalModel()" defined in your local_module.py.

#####################################################
########## the "LocalModel()" used in the model.py ###########

    self.local_module = LocalModule(
        seq_len=self.sample_node_len * 3,
        input_dim=in_channels,
        n_layers=1,
        num_heads=heads,
        hidden_dim=out_channels,
    )

def local_forward(self, seq, pos_enc):
    return self.local_module(seq, pos_enc)

#####################################################

the "LocalModel()" defined in your local_module.py.
def forward(self, batched_data):
    tensor = self.att_embeddings_nope(batched_data)

    # transformer encoder
    for enc_layer in self.layers:
        tensor = enc_layer(tensor)

    output = self.final_ln(tensor)

    _target = output[:, 0, :].unsqueeze(1).repeat(1, self.seq_len - 1, 1)
    split_tensor = torch.split(output, [1, self.seq_len - 1], dim=1)

    node_tensor = split_tensor[0]
    _neighbor_tensor = split_tensor[1]

    if self.node_only_readout:
        # only slicing the indices that belong to nodes and not the 1-hop and 2-hop feats
        indices = torch.arange(3, self.seq_len, 3)
        neighbor_tensor = _neighbor_tensor[:, indices]
        target = _target[:, indices]
    else:
        target = _target
        neighbor_tensor = _neighbor_tensor

    layer_atten = self.attn_layer(torch.cat((target, neighbor_tensor), dim=2))
    layer_atten = F.softmax(layer_atten, dim=1)

    neighbor_tensor = neighbor_tensor * layer_atten
    neighbor_tensor = torch.sum(neighbor_tensor, dim=1, keepdim=True)

    output = (node_tensor + neighbor_tensor).squeeze()

    return output

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.