MCPcopy Index your code
hub / github.com/ZhuYun97/ENGINE

github.com/ZhuYun97/ENGINE @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
114 symbols 434 edges 29 files 8 documented · 7%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Efficient Tuning and Inference for Large Language Models on Textual Graphs

Official implementation of paper Efficient Tuning and Inference for Large Language Models on Textual Graphs

Yun Zhu, Yaoke Wang, Haizhou Shi, Siliang Tang†

In IJCAI 2024

This repository is still on progress.

Overview

In this paper, we propose ENGINE, a parameter- and memory-efficient fine-tuning method for textual graphs with LLM encoder as depicted in Figure 2(Right). The key insight is to combine the LLMs and GNNs through a tunable side structure, which significantly reduces the training complexity without impairing the joint model's capacity.

Environments

  1. virtual environment: conda create --name llama python=3.9 -y
  2. install torch (>=2.0.1): pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu117
  3. install related packages: pip install llama-recipes transformers datasets accelerate sentencepiece protobuf==3.20 py7zr scipy peft bitsandbytes fire torch_tb_profiler ipywidgets
  4. get License for downloading weights: https://ai.meta.com/resources/models-and-libraries/llama-downloads/
  5. download mode weights:git clone https://github.com/facebookresearch/llama

-cd llama

-sh download.sh 6. change into hugging face format: python <anaconda path>/envs/llama/lib/python3.9/site-packages/transformers/models/llama/convert_llama_weights_to_hf.py --input_dir <Weights_PATH> --model_size <size> --output_dir <Outout_PATH>

-https://github.com/facebookresearch/llama-recipes#model-conversion-to-hugging-face 7. install pyg: pip install torch_geometric 8. Optional dependencies: pip install torch_scatter torch_sparse

Download Datasets

For citeseer, wikics, photo datasets, you can download them from link and put them in preprocessed_data/new. And you can download other datasets with raw text in https://github.com/XiaoxinHe/TAPE and put them into datasets dir.

Runing Commands

Baselines for Traditional GNNs

# GNN

CUDA_VISIBLE_DEVICES=5 python traditional_gnn.py --config ./configs/cora/gnn.yaml

CUDA_VISIBLE_DEVICES=5 python traditional_gnn.py --config ./configs/<dataset>/gnn.yaml

# GNN+Subsampling

CUDA_VISIBLE_DEVICES=5 python traditional_gnn.py --config ./configs/cora/subgnn.yaml

CUDA_VISIBLE_DEVICES=5 python traditional_gnn.py --config ./configs/<dataset>/subgnn.yaml

dataset can be set as cora, citeseer, wikics, products, arxiv, arxiv_2023, photo.

Baselines for finetuning LMs


CUDA_VISIBLE_DEVICES=4 python finetune_lm.py --dataset cora --lm_type bert --epochs 4 --lr 5e-5 --batch_size 6

Baselines for PEFT of LLMs


CUDA_VISIBLE_DEVICES=4 python llm.py --peft ia3 --dataset cora --lr 1e-2 --epochs 10 --batch_size 16

Running commands for our method

  1. generate cache:
python cache.py --dataset citeseer
  1. running ENGINE w/ caching:
# For simplicity, we use caching for all samples here. However, in real-world scenarios, access to test samples in advance may not be available. The forthcoming version of this repository, ENGINE w/o caching will be provided. It is imperative to highlight that in Table 4, caching is not utilized.

CUDA_VISIBLE_DEVICES=3 python main.py --config ./configs/citeseer/engine.yaml

  1. running ENGINE (Early):
# For simplicity, we use caching for all samples here. However, in real-world scenarios, access to test samples in advance may not be available. The forthcoming version of this repository, ENGINE w/o caching will be provided. It is imperative to highlight that in Table 4, caching is not utilized.

CUDA_VISIBLE_DEVICES=3 python main.py --config ./configs/citeseer/engine.yaml --early

Core symbols most depended-on inside this repo

get_norm
called by 21
models/encoder.py
reset_parameters
called by 12
models/encoder.py
eval
called by 11
models/LMs/trainer.py
train
called by 9
models/LMs/trainer.py
get_activation
called by 7
models/encoder.py
collect_subgraphs
called by 6
data/sampling.py
ego_graphs_sampler
called by 6
data/sampling.py
load_data
called by 6
data/load.py

Shape

Method 52
Function 45
Class 17

Languages

Python100%

Modules by API surface

models/encoder.py30 symbols
models/LMs/model.py9 symbols
utils/register.py8 symbols
models/LMs/trainer.py7 symbols
traditional_gnn.py6 symbols
main.py6 symbols
models/gnn.py5 symbols
llm.py5 symbols
finetune_lm.py5 symbols
utils/time.py4 symbols
data/sampling.py4 symbols
data/dataset.py4 symbols

For agents

$ claude mcp add ENGINE \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact