Text Generation
Transformers
Safetensors
PyTorch
English
graph_token_lm
causal-lm
graph-neural-network
graph-to-text
graph-conditioned-generation
multimodal
custom-code
qwen
conversational
custom_code
Instructions to use naos-ku/GraphTokenLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use naos-ku/GraphTokenLM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="naos-ku/GraphTokenLM", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("naos-ku/GraphTokenLM", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use naos-ku/GraphTokenLM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "naos-ku/GraphTokenLM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "naos-ku/GraphTokenLM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/naos-ku/GraphTokenLM
- SGLang
How to use naos-ku/GraphTokenLM with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "naos-ku/GraphTokenLM" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "naos-ku/GraphTokenLM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "naos-ku/GraphTokenLM" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "naos-ku/GraphTokenLM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use naos-ku/GraphTokenLM with Docker Model Runner:
docker model run hf.co/naos-ku/GraphTokenLM
File size: 4,081 Bytes
4826ca9 3d11baa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | ---
license: apache-2.0
datasets:
- naos-ku/motif-qa
language:
- en
metrics:
- accuracy
base_model:
- Qwen/Qwen3-4B-Base
pipeline_tag: text-generation
library_name: transformers
tags:
- text-generation
- causal-lm
- graph-neural-network
- graph-to-text
- graph-conditioned-generation
- multimodal
- custom-code
- pytorch
- qwen
---
# GraphTokenLM
GraphTokenLM is a Graph-Language Model (GLM) based on **GraphToken** (Perozzi et al., 2024).
A GNN encoder maps an input graph into a small number of soft-prompt vectors ("graph tokens"),
which are prepended to the input embeddings of a frozen pre-trained LLM.
This checkpoint was trained on the [MotifQA](https://huggingface.co/datasets/naos-ku/motif-qa)
dataset in a multitask setting, and is used in our study that proposed a method for explaining GLM predictions
via edge importance (see [Citation](#citation)).
Source code, training and evaluation scripts:
[N-Shimoda/GLMExplainer](https://github.com/N-Shimoda/GLMExplainer).
## Architecture
| Component | Setting |
|---|---|
| Pre-trained LLM | [Qwen/Qwen3-4B-Base](https://huggingface.co/Qwen/Qwen3-4B-Base) (hidden size 2560, 36 layers, 32 heads) |
| LLM parameters | Frozen (`freeze_llm = true`), no LoRA (`enable_lora = false`) |
| GNN encoder | GIN, 3 layers, hidden / output dim 64 |
| Graph pooling | mean |
| Projection layers | 2-layer MLP, 64-dim GNN output → 2560-dim graph tokens |
| Number of graph tokens | 4 |
| Node features | Laplacian positional encoding (`lpe_dim = 8`), no degree embedding |
| Learned node positional embedding | 8-dim (`pos_emb_dim = 8`) |
| Max nodes per graph | 20 |
| dtype | float32 |
Only the GNN encoder and the projection layers are trained; the LLM weights are identical to
`Qwen/Qwen3-4B-Base`.
## Training
| Item | Setting |
|---|---|
| Dataset | MotifQA (multitask over `ba_shapes`, `ba_two_motifs`, `tree_cycle`, `tree_grid_v2`) |
| Epochs | 32 |
| Optimizer | AdamW |
| Learning rate | 5e-3 |
| Weight decay | 1e-2 |
| LR scheduler | cosine, warmup ratio 0.05 |
| Per-device train batch size | 2 |
| Gradient accumulation steps | 4 |
| GPUs | 2 (`torchrun --nproc_per_node=2`) |
| Seed | 42 |
The equivalent training command from the source repository:
```bash
torchrun --nproc_per_node=2 train.py \
--dataset MotifQA \
--subset ba_shapes ba_two_motifs tree_cycle tree_grid_v2 \
--lpe-dim 8 --pos-emb-dim 8 \
--gnn-type GIN \
--gnn-hidden-dim 64 --gnn-out-dim 64 \
--num-gnn-layers 3 --graph-pooling mean \
--num-proj-layers 2 --num-graph-tokens 4 \
--epochs 32 \
--optim adamw --lr 5e-3 --weight-decay 1e-2 \
--lr-scheduler-type cosine --warmup-ratio 0.05
```
## Usage
The model ships with custom code (`glm.py`), so `trust_remote_code=True` is required.
`torch-geometric` must be installed in addition to `transformers`.
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained(
"naos-ku/GraphTokenLM",
trust_remote_code=True,
load_llm_weights=False, # LLM weights are already included in this repo
)
tokenizer = AutoTokenizer.from_pretrained("naos-ku/GraphTokenLM", trust_remote_code=True)
```
For end-to-end evaluation and explanation, use `eval.py` and `explain.py` in the
[source repository](https://github.com/N-Shimoda/GLMExplainer):
```bash
torchrun --nproc_per_node=2 eval.py \
--dataset MotifQA --subset ba_shapes tree_cycle \
--model-path "naos-ku/GraphTokenLM" \
--num-trials 5 --per-device-batch-size 5
```
## Citation
```bibtex
@article{shimoda2026glmexplainer,
title={Identifying Important Subgraphs in Graph-Language Models via Representative Value Aggregation},
author={Naoki Shimoda and Akihiro Yamamoto},
journal={JSAI Technical Report, SIG-FPAI},
volume={137},
pages={36-43},
year={2026},
month=sep,
doi={10.11517/jsaifpai.137.0_36}
}
```
## References
- Perozzi et al. (2024). *Let Your Graph Do the Talking: Encoding Structured Data for LLMs.* (GraphToken)
- Fatemi et al. (2024). *Talk like a Graph: Encoding Graphs for Large Language Models.* (GraphQA)
|