Views
No views yet

1conda create -n gfmrag python=3.12
2conda activate gfmrag
3conda install cuda-toolkit -c nvidia/label/cuda-12.4.1 # Replace with your desired CUDA version
4pip install gfmrag1TORCH=$(python -c "import torch; print(torch.__version__)")
2pip install torch_scatter torch_sparse -f https://data.pyg.org/whl/torch-${TORCH}.htmldataset_corpus.json: A JSON file containing the entire document corpus.train.json (optional): A JSON file containing the training data.test.json (optional): A JSON file containing the test data.data_name/
├── raw/
│ ├── dataset_corpus.json
│ ├── train.json # (optional)
│ └── test.json # (optional)
└── processed/ # Output directorydataset_corpus.jsondataset_corpus.json is a dictionary where each key is the title or unique id of a document and the value is the text of the document.1{
2 "Fred Gehrke":
3 "Clarence Fred Gehrke (April 24, 1918 – February 9, 2002) was an American football player and executive. He played in the National Football League (NFL) for the Cleveland / Los Angeles Rams, San Francisco 49ers and Chicago Cardinals from 1940 through 1950. To boost team morale, Gehrke designed and painted the Los Angeles Rams logo in 1948, which was the first painted on the helmets of an NFL team. He later served as the general manager of the Denver Broncos from 1977 through 1981. He is the great-grandfather of Miami Marlin Christian Yelich"
4 ,
5 "Manny Machado":
6 "Manuel Arturo Machado (] ; born July 6, 1992) is an American professional baseball third baseman and shortstop for the Baltimore Orioles of Major League Baseball (MLB). He attended Brito High School in Miami and was drafted by the Orioles with the third overall pick in the 2010 Major League Baseball draft. He bats and throws right-handed."
7 ,
8 ...
9 }train.json and test.json (optional)id: A unique identifier for the example.question: The question or query.supporting_facts: A list of supporting facts for the question. Each supporting fact is a list containing the title of the document that can be found in the dataset_corpus.json file.answer: The answer to the question.1[
2 {
3 "id": "5adf5e285542992d7e9f9323",
4 "question": "When was the judge born who made notable contributions to the trial of the man who tortured, raped, and murdered eight student nurses from South Chicago Community Hospital on the night of July 13-14, 1966?",
5 "answer": "June 4, 1931",
6 "supporting_facts": [
7 "Louis B. Garippo",
8 "Richard Speck"
9 ]
10 },
11 {
12 "id": "5a7f7b365542992097ad2f80",
13 "question": "Did the Beaulieu Mine or the McIntyre Mines yield gold and copper?",
14 "answer": "The McIntyre also yielded a considerable amount of copper",
15 "supporting_facts": [
16 "Beaulieu Mine",
17 "McIntyre Mines"
18 ]
19 }
20 ...
21]python -m gfmrag.workflow.stage1_index_datasetkg.txt and document2entities.json) from the dataset_corpus.json filekg.txt: Contains knowledge graph triplesdocument2entities.json: Maps documents to their entitiestrain.json: Processed training data (if raw exists)test.json: Processed test data (if raw exists)root/
└── data_name/
├── raw/
│ ├── dataset_corpus.json
│ ├── train.json (optional)
│ └── test.json (optional)
└── processed/
└── stage1/
├── kg.txt
├── document2entities.json
├── train.json
└── test.json1import logging
2import os
3
4import hydra
5from hydra.core.hydra_config import HydraConfig
6from omegaconf import DictConfig, OmegaConf
7
8from gfmrag import GFMRetriever
9
10logger = logging.getLogger(__name__)
11
12
13@hydra.main(
14 config_path="config", config_name="stage3_qa_ircot_inference", version_base=None
15)
16def main(cfg: DictConfig) -> None:
17 output_dir = HydraConfig.get().runtime.output_dir
18 logger.info(f"Config:\n {OmegaConf.to_yaml(cfg)}")
19 logger.info(f"Current working directory: {os.getcwd()}")
20 logger.info(f"Output directory: {output_dir}")
21
22 gfmrag_retriever = GFMRetriever.from_config(cfg)docs = retriever.retrieve("Who is the president of France?", top_k=5)1from hydra.utils import instantiate
2from gfmrag.llms import BaseLanguageModel
3from gfmrag.prompt_builder import QAPromptBuilder
4
5llm = instantiate(cfg.llm)
6qa_prompt_builder = QAPromptBuilder(cfg.qa_prompt)
7
8message = qa_prompt_builder.build_input_prompt(current_query, retrieved_docs)
9answer = llm.generate_sentence(message) # Answer: "Emmanuel Macron"train.json from the labeled dataset to learn complex relationships for retrieval.1[
2 {
3 "id": "5abc553a554299700f9d7871",
4 "question": "Kyle Ezell is a professor at what School of Architecture building at Ohio State?",
5 "answer": "Knowlton Hall",
6 "supporting_facts": [
7 "Knowlton Hall",
8 "Kyle Ezell"
9 ],
10 "question_entities": [
11 "kyle ezell",
12 "architectural association school of architecture",
13 "ohio state"
14 ],
15 "supporting_entities": [
16 "10 million donation",
17 "2004",
18 "architecture",
19 "austin e knowlton",
20 "austin e knowlton school of architecture",
21 "bachelor s in architectural engineering",
22 "city and regional planning",
23 "columbus ohio united states",
24 "ives hall",
25 "july 2002",
26 "knowlton hall",
27 "ksa",
28 ]
29 },
30 ...
31]1python -m gfmrag.workflow.stage2_qa_finetune
2# Multi-GPU training
3torchrun --nproc_per_node=4 gfmrag.workflow.stage2_qa_finetune
4# Multi-node Multi-GPU training
5torchrun --nproc_per_node=4 --nnodes=2 gfmrag.workflow.stage2_qa_finetune1@article{luo2025gfmrag,
2 title={GFM-RAG: Graph Foundation Model for Retrieval Augmented Generation},
3 author={Luo, Linhao and Zhao, Zicheng and Haffari, Gholamreza and Phung, Dinh and Gong, Chen and Pan, Shirui},
4 journal={arXiv preprint arXiv:2502.01113},
5 year={2025}
6}