Skip to content

Commit ccfb5ea

Browse files
author
Lingfei Wu
authored
Merge pull request #265 from graph4ai/distribution
Distribution
2 parents 076b424 + f65eb9f commit ccfb5ea

File tree

4 files changed

+86
-2
lines changed

4 files changed

+86
-2
lines changed

distribution/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Graph4NLP
2+
Graph4NLP is the library for the easy use of Graph Neural Networks for NLP
3+
4+
## Installation
5+
Users can install Graph4NLP using pip:
6+
```shell
7+
pip install graph4nlp # CPU Version
8+
```
9+
10+
For GPU supported versions, use the following commands:
11+
```shell
12+
pip install graph4nlp-cu92 # CUDA 9.2 Version
13+
pip install graph4nlp-cu101 # CUDA 10.1 Version
14+
pip install graph4nlp-cu102 # CUDA 10.2 Version
15+
pip install graph4nlp-cu110 # CUDA 11.0 Version
16+
```
17+
18+
## Distributing this package
19+
Currently releasing via PyPI is supported. An automated build and distributing shell script is `./build_and_upload_to_pypi.sh`.
20+
You can directly run this script after proper configuration, which will be elaborated below.
21+
22+
### Build the package
23+
To build the package, run `setup.py`. You need to specify whether the binary distribution file(wheel) or source code distribution(tgz)
24+
is wanted. If you want to build the binary version, run
25+
```shell
26+
python setup.py bdist_wheel --universal
27+
```
28+
The `bdist_wheel` option is to say that the binary distribution of wheel file will be built. And the `--universal` option
29+
means the wheel file will fit all platforms.
30+
31+
If you also want to package the source code for distribution, run
32+
```shell
33+
python setup.py sdist
34+
```
35+
Here `sdist` means source distribution. In `build_and_upload_to_pypi.sh` both options will be built.
36+
37+
### Inside `setup.py`
38+
#### Version
39+
Everytime the package is updated, a newer version number needs to be specified, otherwise the updated package
40+
cannot be uploaded to PyPI. To update the version number, you need to change the `version` parameter in the `setup()`
41+
function call in `setup.py`
42+
43+
#### CUDA Compatibility
44+
The only reason why we keep different packages for different CUDA versions is that DGL does so.
45+
In fact our current implementation has nothing to do with CUDA since it is basically a Python frontend of DGL.
46+
However, CUDA version still needs to be specified in order to make the DGL dependency explicit.
47+
48+
When running `setup.py`, you will be prompted to input the CUDA version.
49+
You may just input 'none' for a CPU distribution, otherwise you need to specify the version number explicitly, e.g. `10.2`.
50+
Then a prefix will be generated and appended to the package name, distinguishing among versions with different CUDA dependency.
51+
For example `graph4nlp-cu101`.
52+
53+
Note that this is just a temporal solution for the distribution of the library.
54+
This part needs to be optimized in the following releases.
55+
56+
### Uploading to PyPI
57+
The `twine` python package is used for uploading the package to PyPI. To use it, first install it using pip:
58+
```shell
59+
pip install twine
60+
```
61+
62+
Then you need to specify your credential, namely to authenticate your account that hosts Graph4NLP on PyPI.
63+
64+
Currently I am using my personal account (swangeh) to host this package and a dedicated account should be used in the future.
65+
You can manually input your username and password everytime you upload the package to PyPI by running
66+
```shell
67+
twine upload dist/*
68+
```
69+
In this way there will be prompts to guide you.
70+
To save your time you can also generate a credential on PyPI and save it locally in `~/.pypirc`.
71+
For example inside your `~/.pypirc` it will be
72+
```text
73+
[pypi]
74+
username = <your username>
75+
password = <your password>
76+
```
77+
For details please refer to PyPI.
78+
79+
### Putting them all together
80+
Above is the decomposition of what's inside `build_and_upload_to_pypi.sh`.
81+
You can just run this script to save your time for building and releasing the package.
File renamed without changes.

graph4nlp/pytorch/modules/config/graph_construction/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from ....modules.utils.config_utils import get_yaml_config
2-
import os
32

43
str2yaml = {"dependency": "dependency.yaml", "constituency": "constituency.yaml", "ie": "ie_graph_construction.yaml",
54
"node_emb": "node_emb.yaml", "node_emb_refined": "node_emb_refine.yaml"}
65

6+
import os
7+
8+
dir_path = os.path.dirname(os.path.realpath(__file__))
9+
710

811
def get_graph_construction_args(graph_construction_name):
912
"""
@@ -34,7 +37,7 @@ def get_graph_construction_args(graph_construction_name):
3437
"""
3538
if graph_construction_name in str2yaml.keys():
3639
yaml_name = str2yaml[graph_construction_name]
37-
path = os.path.join("graph4nlp/pytorch/modules/config/graph_construction", yaml_name)
40+
path = os.path.join(dir_path, yaml_name)
3841
config = get_yaml_config(path)
3942
return config
4043
else:

0 commit comments

Comments
 (0)