Skip to content

Commit

Permalink
make it easier to set flags needed to run native python
Browse files Browse the repository at this point in the history
  • Loading branch information
goliaro committed Jul 30, 2023
1 parent 3035099 commit 8bb5e33
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ if (FF_USE_PYTHON)
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/deps/legion/bindings/python
)
# create flexflow_python interpreter. When building from pip, we install the FF_HOME/python/flexflow_python script instead.
# create set_python_envs.sh script to set up the environment variables to run flexflow_python
if (NOT FF_BUILD_FROM_PYPI)
add_custom_command(TARGET flexflow
PRE_BUILD
Expand Down
7 changes: 4 additions & 3 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ export FF_HOME=/path/to/FlexFlow
### Run FlexFlow Python examples
The Python examples are in the [examples/python](https://github.com/flexflow/FlexFlow/tree/master/examples/python). The native, Keras integration and PyTorch integration examples are listed in `native`, `keras` and `pytorch` respectively.

To run the Python examples, you have two options: you can use the `flexflow_python` interpreter, available in the `build` folder, or you can use the native Python interpreter. If you choose to use the native Python interpreter, you should either install FlexFlow, or, if you prefer to build without installing, export the following flags:
To run the Python examples, you have two options: you can use the `flexflow_python` interpreter, available in the `build` folder, or you can use the native Python interpreter. If you choose to use the native Python interpreter, you should either install FlexFlow, or, if you prefer to build without installing, export the required environment flags by running the following command (edit the path if your build folder is not named `build`):

* `export PYTHONPATH="${FF_HOME}/python:${FF_HOME}/build/deps/legion/bindings/python:${PYTHONPATH}"`
* `export LD_LIBRARY_PATH="${FF_HOME}/build:${FF_HOME}/build/deps/legion/lib:${LD_LIBRARY_PATH}"`
```
source ./build/set_python_envs.sh
```

**We recommend that you run the** `mnist_mlp` **test under** `native` **using the following cmd to check if FlexFlow has been installed correctly:**

Expand Down
31 changes: 24 additions & 7 deletions python/flexflow_python_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
sys.exit(1)
build_dir = os.path.abspath(build_dir)
script_dir = os.path.abspath(os.path.dirname(__file__))
script_path = os.path.join(build_dir, "flexflow_python")
if not os.path.isdir(build_dir):
print(f"Folder {build_dir} does not exist")
sys.exit(1)
if not os.path.isdir(script_dir):
print(f"Folder {script_dir} does not exist")
sys.exit(1)
script_path = os.path.abspath(script_path)
# Build flexflow_python script
flexflow_python_path = os.path.join(build_dir, "flexflow_python")
flexflow_python_path = os.path.abspath(flexflow_python_path)
lines = [
'#! /usr/bin/env bash',
f'BUILD_FOLDER="{build_dir}"',
Expand All @@ -52,10 +53,26 @@
'\tlegion_python "$@"',
'fi'
]

with open(script_path, "w+") as script_file:
with open(flexflow_python_path, "w+") as flexflow_python_file:
for line in lines:
script_file.write(line + "\n")
flexflow_python_file.write(line + "\n")
cur_stat = os.stat(flexflow_python_path)
os.chmod(flexflow_python_path, cur_stat.st_mode | stat.S_IEXEC)

cur_stat = os.stat(script_path)
os.chmod(script_path, cur_stat.st_mode | stat.S_IEXEC)
# Build set_python_envs.sh
python_envs_path = os.path.join(build_dir, "set_python_envs.sh")
python_envs_path = os.path.abspath(python_envs_path)
lines = [
'#! /usr/bin/env bash',
f'BUILD_FOLDER="{build_dir}"',
f'PYTHON_FOLDER="{script_dir}"',
'PYLIB_PATH="$("$PYTHON_FOLDER"/flexflow/findpylib.py)"',
'PYLIB_DIR="$(dirname "$PYLIB_PATH")"',
'export LD_LIBRARY_PATH="$BUILD_FOLDER:$BUILD_FOLDER/deps/legion/lib:$PYLIB_DIR:$LD_LIBRARY_PATH"',
'export PYTHONPATH="$PYTHON_FOLDER:$BUILD_FOLDER/deps/legion/bindings/python:$PYTHONPATH"',
]
with open(python_envs_path, "w+") as python_envs_file:
for line in lines:
python_envs_file.write(line + "\n")
cur_stat = os.stat(python_envs_path)
os.chmod(python_envs_path, cur_stat.st_mode | stat.S_IEXEC)

0 comments on commit 8bb5e33

Please sign in to comment.