rdf2vecgpu 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. rdf2vecgpu-0.1.0/.gitignore +189 -0
  2. rdf2vecgpu-0.1.0/.python-version +1 -0
  3. rdf2vecgpu-0.1.0/LICENSE +21 -0
  4. rdf2vecgpu-0.1.0/PKG-INFO +222 -0
  5. rdf2vecgpu-0.1.0/README.md +200 -0
  6. rdf2vecgpu-0.1.0/__init__.py +5 -0
  7. rdf2vecgpu-0.1.0/corpus/__init__.py +0 -0
  8. rdf2vecgpu-0.1.0/corpus/walk_corpus.py +459 -0
  9. rdf2vecgpu-0.1.0/data/.gitkeep +0 -0
  10. rdf2vecgpu-0.1.0/data_preparation/conversion_to_ttl.py +19 -0
  11. rdf2vecgpu-0.1.0/data_preparation/converstion_to_ttl.py +17 -0
  12. rdf2vecgpu-0.1.0/data_preparation/merge_text_file.py +53 -0
  13. rdf2vecgpu-0.1.0/doap.rdf +42 -0
  14. rdf2vecgpu-0.1.0/docs/Makefile +20 -0
  15. rdf2vecgpu-0.1.0/docs/make.bat +35 -0
  16. rdf2vecgpu-0.1.0/docs/source/conf.py +38 -0
  17. rdf2vecgpu-0.1.0/docs/source/index.rst +134 -0
  18. rdf2vecgpu-0.1.0/docs/source/modules.rst +7 -0
  19. rdf2vecgpu-0.1.0/docs/source/rdf2vecgpu.corpus.rst +21 -0
  20. rdf2vecgpu-0.1.0/docs/source/rdf2vecgpu.embedders.rst +31 -0
  21. rdf2vecgpu-0.1.0/docs/source/rdf2vecgpu.helper.rst +21 -0
  22. rdf2vecgpu-0.1.0/docs/source/rdf2vecgpu.logger.rst +29 -0
  23. rdf2vecgpu-0.1.0/docs/source/rdf2vecgpu.reader.rst +29 -0
  24. rdf2vecgpu-0.1.0/docs/source/rdf2vecgpu.rst +33 -0
  25. rdf2vecgpu-0.1.0/embedders/__init__.py +0 -0
  26. rdf2vecgpu-0.1.0/embedders/word2vec.py +106 -0
  27. rdf2vecgpu-0.1.0/embedders/word2vec_loader.py +125 -0
  28. rdf2vecgpu-0.1.0/gpu_rdf2vec.py +447 -0
  29. rdf2vecgpu-0.1.0/helper/__init__.py +0 -0
  30. rdf2vecgpu-0.1.0/helper/functions.py +121 -0
  31. rdf2vecgpu-0.1.0/img/github_repo_header.png +0 -0
  32. rdf2vecgpu-0.1.0/jrdf2vec-1.3-SNAPSHOT.jar +0 -0
  33. rdf2vecgpu-0.1.0/logger/__init__.py +0 -0
  34. rdf2vecgpu-0.1.0/logger/mlflow_logger.py +0 -0
  35. rdf2vecgpu-0.1.0/logger/wandb_logger.py +0 -0
  36. rdf2vecgpu-0.1.0/performance/README.md +14 -0
  37. rdf2vecgpu-0.1.0/performance/env_files/jrdf2vec_environment.yml +85 -0
  38. rdf2vecgpu-0.1.0/performance/env_files/jrdf2vec_requirements.txt +39 -0
  39. rdf2vecgpu-0.1.0/performance/env_files/pyrdf2vec_environment.yml +123 -0
  40. rdf2vecgpu-0.1.0/performance/env_files/pyrdf2vec_requirements.txt +77 -0
  41. rdf2vecgpu-0.1.0/performance/env_files/rdf2vecgpu_environment.yml +154 -0
  42. rdf2vecgpu-0.1.0/performance/env_files/rdf2vecgpu_requirements.txt +125 -0
  43. rdf2vecgpu-0.1.0/performance/env_files/sparkrdf2vec_environment.yml +179 -0
  44. rdf2vecgpu-0.1.0/performance/env_files/sparkrdf2vec_requirements.txt +36 -0
  45. rdf2vecgpu-0.1.0/performance/evaluation_parameters.py +12 -0
  46. rdf2vecgpu-0.1.0/performance/gpu_rdf2vec_performance.py +75 -0
  47. rdf2vecgpu-0.1.0/performance/graph_creation.py +38 -0
  48. rdf2vecgpu-0.1.0/performance/graph_statistics.py +41 -0
  49. rdf2vecgpu-0.1.0/performance/jrdf2vec_based_performance.py +116 -0
  50. rdf2vecgpu-0.1.0/performance/pyrdf2vec_based_performance.py +164 -0
  51. rdf2vecgpu-0.1.0/performance/spark_rdf2vec_performance.py +123 -0
  52. rdf2vecgpu-0.1.0/performance/wandb_analysis.py +41 -0
  53. rdf2vecgpu-0.1.0/pyproject.toml +30 -0
  54. rdf2vecgpu-0.1.0/rdf2vecgpu/__init__.py +5 -0
  55. rdf2vecgpu-0.1.0/rdf2vecgpu/corpus/__init__.py +0 -0
  56. rdf2vecgpu-0.1.0/rdf2vecgpu/corpus/walk_corpus.py +459 -0
  57. rdf2vecgpu-0.1.0/rdf2vecgpu/embedders/__init__.py +0 -0
  58. rdf2vecgpu-0.1.0/rdf2vecgpu/embedders/word2vec.py +106 -0
  59. rdf2vecgpu-0.1.0/rdf2vecgpu/embedders/word2vec_loader.py +125 -0
  60. rdf2vecgpu-0.1.0/rdf2vecgpu/gpu_rdf2vec.py +447 -0
  61. rdf2vecgpu-0.1.0/rdf2vecgpu/helper/__init__.py +0 -0
  62. rdf2vecgpu-0.1.0/rdf2vecgpu/helper/functions.py +121 -0
  63. rdf2vecgpu-0.1.0/rdf2vecgpu/logger/__init__.py +0 -0
  64. rdf2vecgpu-0.1.0/rdf2vecgpu/logger/mlflow_logger.py +0 -0
  65. rdf2vecgpu-0.1.0/rdf2vecgpu/logger/wandb_logger.py +0 -0
  66. rdf2vecgpu-0.1.0/rdf2vecgpu/reader/__init__.py +0 -0
  67. rdf2vecgpu-0.1.0/rdf2vecgpu/reader/kg_file_reader.py +66 -0
  68. rdf2vecgpu-0.1.0/rdf2vecgpu/reader/kg_reader.py +64 -0
  69. rdf2vecgpu-0.1.0/reader/__init__.py +0 -0
  70. rdf2vecgpu-0.1.0/reader/kg_file_reader.py +66 -0
  71. rdf2vecgpu-0.1.0/reader/kg_reader.py +64 -0
  72. rdf2vecgpu-0.1.0/test/reader/functions_test.py +45 -0
  73. rdf2vecgpu-0.1.0/test/reader/kg_reader_test.py +97 -0
@@ -0,0 +1,189 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # PyPI configuration file
171
+ .pypirc
172
+
173
+ data/*
174
+ !data/.gitkeep
175
+ wandb/
176
+ job/
177
+ vector/
178
+ walks/
179
+ python-server/
180
+ dask_spill/
181
+ lightning_logs/
182
+ .vscode/
183
+ spark_local/
184
+ wikidata_parquet/
185
+ .scale*
186
+ test.py
187
+ *.xlsx
188
+ wikidata*
189
+ .uv.lock
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Martin Böckling
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,222 @@
1
+ Metadata-Version: 2.4
2
+ Name: rdf2vecgpu
3
+ Version: 0.1.0
4
+ Summary: GPU-Accelerated RDF2Vec – A high-performance GPU implementation of RDF2Vec that uses CUDA and RAPIDS to generate scalable, embeddings for large dense knowledge graphs.
5
+ Project-URL: Homepage, https://github.com/MartinBoeckling/rdf2vecgpu
6
+ Project-URL: Issues, https://github.com/MartinBoeckling/rdf2vecgpu/issues
7
+ License: MIT
8
+ License-File: LICENSE
9
+ Requires-Python: >=3.12
10
+ Requires-Dist: cudf-cu12>=25.6.0
11
+ Requires-Dist: cugraph-cu12==25.6.*
12
+ Requires-Dist: cupy-cuda12x>=13.5.1
13
+ Requires-Dist: dask-cudf-cu12>=25.6.0
14
+ Requires-Dist: dask[complete]>=2025.5.0
15
+ Requires-Dist: lightning>=2.5.2
16
+ Requires-Dist: loguru>=0.7.3
17
+ Requires-Dist: numpy>=2.2.6
18
+ Requires-Dist: rdflib>=7.1.4
19
+ Requires-Dist: torch>=2.7.1
20
+ Requires-Dist: tqdm>=4.67.1
21
+ Description-Content-Type: text/markdown
22
+
23
+ ## gpuRDF2Vec
24
+ A scalable GPU based implementation of RDF2Vec embeddings for large and dense Knowledge Graphs.
25
+
26
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
27
+
28
+ ![RDF2VecGPU_Image](img/github_repo_header.png)
29
+
30
+ > [!IMPORTANT]
31
+ > This package is under active development in the beta phase. The overall class/ method design will most probably change and introduce breaking changes between releases
32
+
33
+ ## Table of contents
34
+ The content of this repository readme can be found here:
35
+ - [gpuRDF2Vec](#gpurdf2vec)
36
+ - [Table of contents](#table-of-contents)
37
+ - [Repository setup](#repository-setup)
38
+ - [gpuRDF2Vec overview](#gpurdf2vec-overview)
39
+ - [Repository Structure](#repository-structure)
40
+ - [Capability overview](#capability-overview)
41
+ - [Quick start](#quick-start)
42
+ - [Implementation Details](#implementation-details)
43
+ - [License](#license)
44
+ - [Roadmap](#roadmap)
45
+ - [Report issues and bugs](#report-issues-and-bugs)
46
+
47
+
48
+ ## Repository setup
49
+ The repository setup builds on top of two major libraries. Both Pytorch lightning as well as the RAPIDS libraries cuDF and cuGraph. We provide the exeplanatory installation details for Cuda 12.6:
50
+ 1. Pytorch [installation page](https://pytorch.org/get-started/locally/)
51
+ Cuda 12.6 installation
52
+ ```bash
53
+ pip install torch torchvision torchaudio
54
+ ```
55
+ 2. Detailed cudf installation instruction [here](https://docs.rapids.ai/install/).
56
+ Cudf Cuda 12 install
57
+ ```bash
58
+ pip install \
59
+ --extra-index-url=https://pypi.nvidia.com \
60
+ "cudf-cu12==25.4.*" "dask-cudf-cu12==25.4.*" \
61
+ "cugraph-cu12==25.4.*" "nx-cugraph-cu12==25.4.*" \
62
+ "nx-cugraph-cu12==25.4.*"
63
+ ```
64
+ The requirement files and conda environment files can be found here:
65
+ - [Conda environment](performance/env_files/rdf2vecgpu_environment.yml)
66
+ - [Requirement file](performance/env_files/rdf2vecgpu_requirements.txt)
67
+ ## gpuRDF2Vec overview
68
+ RDF2Vec is a powerful technique to generate vector embeddings of entities in RDF graphs via random walks and Word2Vec. This repository provides a GPU-optimized reimplementation, enabling:
69
+
70
+ - **Speedups** on dense graphs with millions of nodes
71
+ - **Scalability** to industrial-scale knowledge bases
72
+ - **Reproducible experiments** to test and qualify the overall implementation details
73
+ ### Repository Structure
74
+ ```bash
75
+ .
76
+ ├── README.md
77
+ ├── data
78
+ ├── data_preparation
79
+ │ ├── converstion_to_ttl.py
80
+ │ └── merge_text_file.py
81
+ ├── img
82
+ │ └── github_repo_header.png
83
+ ├── jrdf2vec-1.3-SNAPSHOT.jar
84
+ ├── performance
85
+ │ ├── env_files
86
+ │ │ ├── jrdf2vec_environment.yml
87
+ │ │ ├── jrdf2vec_requirements.txt
88
+ │ │ ├── pyrdf2vec_environment.yml
89
+ │ │ ├── pyrdf2vec_requirements.txt
90
+ │ │ ├── rdf2vecgpu_environment.yml
91
+ │ │ ├── rdf2vecgpu_requirements.txt
92
+ │ │ ├── sparkrdf2vec_environment.yml
93
+ │ │ └── sparkrdf2vec_requirements.txt
94
+ │ ├── evaluation_parameters.py
95
+ │ ├── gpu_rdf2vec_performance.py
96
+ │ ├── graph_creation.py
97
+ │ ├── graph_statistics.py
98
+ │ ├── jrdf2vec_based_performance.py
99
+ │ ├── pyrdf2vec_based_performance.py
100
+ │ ├── spark_rdf2vec_performance.py
101
+ │ └── wandb_analysis.py
102
+ ├── src
103
+ │ ├── __init__.py
104
+ │ ├── corpus
105
+ │ │ ├── __init__.py
106
+ │ │ └── walk_corpus.py
107
+ │ ├── cpu_based_rdf2vec_approach.py
108
+ │ ├── embedders
109
+ │ │ ├── __init__.py
110
+ │ │ ├── word2vec.py
111
+ │ │ └── word2vec_loader.py
112
+ │ ├── gpu_rdf2vec.py
113
+ │ ├── helper
114
+ │ │ ├── __init__.py
115
+ │ │ └── functions.py
116
+ │ └── reader
117
+ │ ├── __init__.py
118
+ │ └── kg_reader.py
119
+ └── test
120
+ ├── helper
121
+ └── reader
122
+ ├── functions_test.py
123
+ └── kg_reader_test.py
124
+ ```
125
+ ### Capability overview
126
+ - GPU-backed walk generation over CUDA Kernels
127
+ - Batched Word2Vec training with Pytorch lightning
128
+ - Pluggable rdf loaders and parquet, csv, txt integration
129
+ - Performance comparison can be found in the following [folder](performance/)
130
+
131
+ ## Quick start
132
+ ```python
133
+ from src.gpu_rdf2vec import GPU_RDF2Vec
134
+ # Instantiate the gpu RDF2Vec library settings
135
+ gpu_rdf2vec_model = GPU_RDF2Vec(
136
+ walk_strategy="random",
137
+ walk_depth=4,
138
+ walk_number=100,
139
+ embedding_model="skipgram",
140
+ epochs=5,
141
+ batch_size=None,
142
+ vector_size=100,
143
+ window_size=5,
144
+ min_count=1,
145
+ learning_rate=0.01,
146
+ negative_samples=5,
147
+ random_state=42,
148
+ reproducible=False,
149
+ multi_gpu=False,
150
+ generate_artifact=False,
151
+ cpu_count=20
152
+ )
153
+ # Path to the triple dataset
154
+ path = "data/wikidata5m/wikidata5m_kg.parquet"
155
+ # Load data and receive edge data
156
+ edge_data = gpu_rdf2vec_model.load_data(path)
157
+ # Fit the Word2Vec model and transform the dataset to an embedding
158
+ embeddings = gpu_rdf2vec_model.fit_transform(edge_df=edge_data, walk_vertices=None)
159
+ # Write embedding to file format. Return format is a cuDf dataframe
160
+ embeddings.to_parquet("data/wikidata5m/wikidata5m_embeddings.parquet", index=False)
161
+ ```
162
+ - Supported file formats:
163
+ - .csv
164
+ - .txt
165
+ - .parquet
166
+ - .nt
167
+ - All supported [RDFlib file formats](https://rdflib.readthedocs.io/en/stable/plugin_parsers.html)
168
+ - gpuRDF2Vec Parameters:
169
+ - walk_strategy: `[random, bfs]`
170
+ - walk_depth: `int`
171
+ - walk_number: `int`
172
+ - embedding_model: `[skipgram, cbow]`
173
+ - epochs: `int`
174
+ - batch_size: `[None | int]` --> If the batch size is None, we guess internally the batch size based on the data loader and the number of CPU counts provided
175
+ - vector_size
176
+ - window_size: `int`
177
+ - min_count: `int`
178
+ - learning_rate: `float`
179
+ - negative_samples: `int`
180
+ - random_state: `int`
181
+ - reproducible: `bool`
182
+ - multi_gpu: `bool`
183
+ - generate_artifact: `bool`
184
+ - cpu_count: `int`
185
+ ## Implementation Details
186
+
187
+ We achieve order-of-magnitude for large and dense graphs over CPU-bound RDF2Vec by engineering both the **walk extraction** and the **Word2Vec training** pipelines:
188
+ 1. **GPU-Native Walk Extraction**
189
+ - All random-walk and BFS operations leverage cuDF/cuGraph kernels to avoid CPU–GPU data transfers and minimize latency.
190
+ - To generate *k* walks per node in one pass, we replicate node indices in a single cuDF DataFrame rather than looping—fully utilizing GPU parallelism and eliminating Python-loop overhead (∼15× speedup).
191
+ - BFS walks currently use GPU-side recursive joins; future work will reconstruct walks entirely in CUDA to remove join overhead.
192
+
193
+ 2. **cuDF→PyTorch Lightning Handoff**
194
+ - Replaced Lightning’s default CPU-based DataLoader with a cuDF-backed pipeline: context/center columns live on GPU as DLPack tensors.
195
+ - Initial deep-copy loads incur extra VRAM, but thereafter all sampling/preprocessing occurs on-device, eliminating PCIe stalls.
196
+ - An “index-only” strategy (workers pull tensor indices instead of slices) uses CUDA’s pointer arithmetic for constant-time access, collapsing DataLoader overhead from ~85% of epoch time to near parity with model compute.
197
+
198
+ 3. **Optimized Word2Vec Training**
199
+ - **Batch-Size Heuristic:** Estimate per-sample GPU footprint from cuDF loader, then set initial batch = (total VRAM) / (4 × footprint). This “divide-by-four” rule quickly homes in on a viable batch size, reducing tuning runs.
200
+ - **Kernel Fusion:** All sampling and tensor transforms migrated into PyTorch’s C++ back end, removing Python loops and the GIL, for consistent high throughput.
201
+
202
+ 4. **Scalable Data-Parallel Training**
203
+ - We use PyTorch Distributed + NCCL: each GPU holds the same graph shard but a unique walk corpus.
204
+ - Gradients are synchronized via `all_reduce` at regular intervals (~500 ms), amortizing PCIe/NVLink costs and ensuring linear scaling across nodes.
205
+ ## License
206
+ The overview of the used MIT license can be found [here](LICENSE)
207
+ ## Roadmap
208
+ - [ ] Order aware Word2Vec following the details of [Ling, Wang, et al. "Two/too simple adaptations of word2vec for syntax problems.](https://aclanthology.org/N15-1142.pdf). [Issue item](https://github.com/MartinBoeckling/rdf2vecgpu/issues/2)
209
+ - [ ] Provide spilling to single GPU training to work around potential OOM issues faced during rdf2vec training [Issue Item](https://github.com/MartinBoeckling/rdf2vecgpu/issues/3)
210
+ - [ ] Provide weighted walks for spatial datasets [Issue item](https://github.com/MartinBoeckling/rdf2vecgpu/issues/4)
211
+ - [ ] Provide logging capabilities of complete Word2Vec pipeline for [Wandb](https://wandb.ai/site/) and [mlflow](https://mlflow.org/). [Issue item](https://github.com/MartinBoeckling/rdf2vecgpu/issues/5)
212
+ ## Report issues and bugs
213
+ In case you have found a bug or unexpected behaviour, please reach out by opening an issue:
214
+ 1. When opening an issue, please tag the issue with the label **Bug**. Please include the following information:
215
+ - **Environment**: OS, Python/CUDA/PyTorch/RAPIDS versions (cuDF, cuGraph)
216
+ - **Reproduction steps**: Exact commands or small code snippet
217
+ - **Input data** graph format & size (attach a minimal sample if possible)
218
+ - **Observed vs. expected behavior**
219
+ - **Error messages/ stack traces** (copy-paste or attach logs)
220
+
221
+ 2. We aim to respond to open issues within 3 business days
222
+ 3. If you have identified a fix, fork the repo, branch off `main`, implement & test then open a PR referencing the issue.
@@ -0,0 +1,200 @@
1
+ ## gpuRDF2Vec
2
+ A scalable GPU based implementation of RDF2Vec embeddings for large and dense Knowledge Graphs.
3
+
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ ![RDF2VecGPU_Image](img/github_repo_header.png)
7
+
8
+ > [!IMPORTANT]
9
+ > This package is under active development in the beta phase. The overall class/ method design will most probably change and introduce breaking changes between releases
10
+
11
+ ## Table of contents
12
+ The content of this repository readme can be found here:
13
+ - [gpuRDF2Vec](#gpurdf2vec)
14
+ - [Table of contents](#table-of-contents)
15
+ - [Repository setup](#repository-setup)
16
+ - [gpuRDF2Vec overview](#gpurdf2vec-overview)
17
+ - [Repository Structure](#repository-structure)
18
+ - [Capability overview](#capability-overview)
19
+ - [Quick start](#quick-start)
20
+ - [Implementation Details](#implementation-details)
21
+ - [License](#license)
22
+ - [Roadmap](#roadmap)
23
+ - [Report issues and bugs](#report-issues-and-bugs)
24
+
25
+
26
+ ## Repository setup
27
+ The repository setup builds on top of two major libraries. Both Pytorch lightning as well as the RAPIDS libraries cuDF and cuGraph. We provide the exeplanatory installation details for Cuda 12.6:
28
+ 1. Pytorch [installation page](https://pytorch.org/get-started/locally/)
29
+ Cuda 12.6 installation
30
+ ```bash
31
+ pip install torch torchvision torchaudio
32
+ ```
33
+ 2. Detailed cudf installation instruction [here](https://docs.rapids.ai/install/).
34
+ Cudf Cuda 12 install
35
+ ```bash
36
+ pip install \
37
+ --extra-index-url=https://pypi.nvidia.com \
38
+ "cudf-cu12==25.4.*" "dask-cudf-cu12==25.4.*" \
39
+ "cugraph-cu12==25.4.*" "nx-cugraph-cu12==25.4.*" \
40
+ "nx-cugraph-cu12==25.4.*"
41
+ ```
42
+ The requirement files and conda environment files can be found here:
43
+ - [Conda environment](performance/env_files/rdf2vecgpu_environment.yml)
44
+ - [Requirement file](performance/env_files/rdf2vecgpu_requirements.txt)
45
+ ## gpuRDF2Vec overview
46
+ RDF2Vec is a powerful technique to generate vector embeddings of entities in RDF graphs via random walks and Word2Vec. This repository provides a GPU-optimized reimplementation, enabling:
47
+
48
+ - **Speedups** on dense graphs with millions of nodes
49
+ - **Scalability** to industrial-scale knowledge bases
50
+ - **Reproducible experiments** to test and qualify the overall implementation details
51
+ ### Repository Structure
52
+ ```bash
53
+ .
54
+ ├── README.md
55
+ ├── data
56
+ ├── data_preparation
57
+ │ ├── converstion_to_ttl.py
58
+ │ └── merge_text_file.py
59
+ ├── img
60
+ │ └── github_repo_header.png
61
+ ├── jrdf2vec-1.3-SNAPSHOT.jar
62
+ ├── performance
63
+ │ ├── env_files
64
+ │ │ ├── jrdf2vec_environment.yml
65
+ │ │ ├── jrdf2vec_requirements.txt
66
+ │ │ ├── pyrdf2vec_environment.yml
67
+ │ │ ├── pyrdf2vec_requirements.txt
68
+ │ │ ├── rdf2vecgpu_environment.yml
69
+ │ │ ├── rdf2vecgpu_requirements.txt
70
+ │ │ ├── sparkrdf2vec_environment.yml
71
+ │ │ └── sparkrdf2vec_requirements.txt
72
+ │ ├── evaluation_parameters.py
73
+ │ ├── gpu_rdf2vec_performance.py
74
+ │ ├── graph_creation.py
75
+ │ ├── graph_statistics.py
76
+ │ ├── jrdf2vec_based_performance.py
77
+ │ ├── pyrdf2vec_based_performance.py
78
+ │ ├── spark_rdf2vec_performance.py
79
+ │ └── wandb_analysis.py
80
+ ├── src
81
+ │ ├── __init__.py
82
+ │ ├── corpus
83
+ │ │ ├── __init__.py
84
+ │ │ └── walk_corpus.py
85
+ │ ├── cpu_based_rdf2vec_approach.py
86
+ │ ├── embedders
87
+ │ │ ├── __init__.py
88
+ │ │ ├── word2vec.py
89
+ │ │ └── word2vec_loader.py
90
+ │ ├── gpu_rdf2vec.py
91
+ │ ├── helper
92
+ │ │ ├── __init__.py
93
+ │ │ └── functions.py
94
+ │ └── reader
95
+ │ ├── __init__.py
96
+ │ └── kg_reader.py
97
+ └── test
98
+ ├── helper
99
+ └── reader
100
+ ├── functions_test.py
101
+ └── kg_reader_test.py
102
+ ```
103
+ ### Capability overview
104
+ - GPU-backed walk generation over CUDA Kernels
105
+ - Batched Word2Vec training with Pytorch lightning
106
+ - Pluggable rdf loaders and parquet, csv, txt integration
107
+ - Performance comparison can be found in the following [folder](performance/)
108
+
109
+ ## Quick start
110
+ ```python
111
+ from src.gpu_rdf2vec import GPU_RDF2Vec
112
+ # Instantiate the gpu RDF2Vec library settings
113
+ gpu_rdf2vec_model = GPU_RDF2Vec(
114
+ walk_strategy="random",
115
+ walk_depth=4,
116
+ walk_number=100,
117
+ embedding_model="skipgram",
118
+ epochs=5,
119
+ batch_size=None,
120
+ vector_size=100,
121
+ window_size=5,
122
+ min_count=1,
123
+ learning_rate=0.01,
124
+ negative_samples=5,
125
+ random_state=42,
126
+ reproducible=False,
127
+ multi_gpu=False,
128
+ generate_artifact=False,
129
+ cpu_count=20
130
+ )
131
+ # Path to the triple dataset
132
+ path = "data/wikidata5m/wikidata5m_kg.parquet"
133
+ # Load data and receive edge data
134
+ edge_data = gpu_rdf2vec_model.load_data(path)
135
+ # Fit the Word2Vec model and transform the dataset to an embedding
136
+ embeddings = gpu_rdf2vec_model.fit_transform(edge_df=edge_data, walk_vertices=None)
137
+ # Write embedding to file format. Return format is a cuDf dataframe
138
+ embeddings.to_parquet("data/wikidata5m/wikidata5m_embeddings.parquet", index=False)
139
+ ```
140
+ - Supported file formats:
141
+ - .csv
142
+ - .txt
143
+ - .parquet
144
+ - .nt
145
+ - All supported [RDFlib file formats](https://rdflib.readthedocs.io/en/stable/plugin_parsers.html)
146
+ - gpuRDF2Vec Parameters:
147
+ - walk_strategy: `[random, bfs]`
148
+ - walk_depth: `int`
149
+ - walk_number: `int`
150
+ - embedding_model: `[skipgram, cbow]`
151
+ - epochs: `int`
152
+ - batch_size: `[None | int]` --> If the batch size is None, we guess internally the batch size based on the data loader and the number of CPU counts provided
153
+ - vector_size
154
+ - window_size: `int`
155
+ - min_count: `int`
156
+ - learning_rate: `float`
157
+ - negative_samples: `int`
158
+ - random_state: `int`
159
+ - reproducible: `bool`
160
+ - multi_gpu: `bool`
161
+ - generate_artifact: `bool`
162
+ - cpu_count: `int`
163
+ ## Implementation Details
164
+
165
+ We achieve order-of-magnitude for large and dense graphs over CPU-bound RDF2Vec by engineering both the **walk extraction** and the **Word2Vec training** pipelines:
166
+ 1. **GPU-Native Walk Extraction**
167
+ - All random-walk and BFS operations leverage cuDF/cuGraph kernels to avoid CPU–GPU data transfers and minimize latency.
168
+ - To generate *k* walks per node in one pass, we replicate node indices in a single cuDF DataFrame rather than looping—fully utilizing GPU parallelism and eliminating Python-loop overhead (∼15× speedup).
169
+ - BFS walks currently use GPU-side recursive joins; future work will reconstruct walks entirely in CUDA to remove join overhead.
170
+
171
+ 2. **cuDF→PyTorch Lightning Handoff**
172
+ - Replaced Lightning’s default CPU-based DataLoader with a cuDF-backed pipeline: context/center columns live on GPU as DLPack tensors.
173
+ - Initial deep-copy loads incur extra VRAM, but thereafter all sampling/preprocessing occurs on-device, eliminating PCIe stalls.
174
+ - An “index-only” strategy (workers pull tensor indices instead of slices) uses CUDA’s pointer arithmetic for constant-time access, collapsing DataLoader overhead from ~85% of epoch time to near parity with model compute.
175
+
176
+ 3. **Optimized Word2Vec Training**
177
+ - **Batch-Size Heuristic:** Estimate per-sample GPU footprint from cuDF loader, then set initial batch = (total VRAM) / (4 × footprint). This “divide-by-four” rule quickly homes in on a viable batch size, reducing tuning runs.
178
+ - **Kernel Fusion:** All sampling and tensor transforms migrated into PyTorch’s C++ back end, removing Python loops and the GIL, for consistent high throughput.
179
+
180
+ 4. **Scalable Data-Parallel Training**
181
+ - We use PyTorch Distributed + NCCL: each GPU holds the same graph shard but a unique walk corpus.
182
+ - Gradients are synchronized via `all_reduce` at regular intervals (~500 ms), amortizing PCIe/NVLink costs and ensuring linear scaling across nodes.
183
+ ## License
184
+ The overview of the used MIT license can be found [here](LICENSE)
185
+ ## Roadmap
186
+ - [ ] Order aware Word2Vec following the details of [Ling, Wang, et al. "Two/too simple adaptations of word2vec for syntax problems.](https://aclanthology.org/N15-1142.pdf). [Issue item](https://github.com/MartinBoeckling/rdf2vecgpu/issues/2)
187
+ - [ ] Provide spilling to single GPU training to work around potential OOM issues faced during rdf2vec training [Issue Item](https://github.com/MartinBoeckling/rdf2vecgpu/issues/3)
188
+ - [ ] Provide weighted walks for spatial datasets [Issue item](https://github.com/MartinBoeckling/rdf2vecgpu/issues/4)
189
+ - [ ] Provide logging capabilities of complete Word2Vec pipeline for [Wandb](https://wandb.ai/site/) and [mlflow](https://mlflow.org/). [Issue item](https://github.com/MartinBoeckling/rdf2vecgpu/issues/5)
190
+ ## Report issues and bugs
191
+ In case you have found a bug or unexpected behaviour, please reach out by opening an issue:
192
+ 1. When opening an issue, please tag the issue with the label **Bug**. Please include the following information:
193
+ - **Environment**: OS, Python/CUDA/PyTorch/RAPIDS versions (cuDF, cuGraph)
194
+ - **Reproduction steps**: Exact commands or small code snippet
195
+ - **Input data** graph format & size (attach a minimal sample if possible)
196
+ - **Observed vs. expected behavior**
197
+ - **Error messages/ stack traces** (copy-paste or attach logs)
198
+
199
+ 2. We aim to respond to open issues within 3 business days
200
+ 3. If you have identified a fix, fork the repo, branch off `main`, implement & test then open a PR referencing the issue.
@@ -0,0 +1,5 @@
1
+ __version__ = "0.1.0"
2
+
3
+ __all__ = [
4
+ "GPU_RDF2Vec"
5
+ ]
File without changes