Skip to content

Commit

Permalink
Set sharktank package deps during package build reliably. (#440)
Browse files Browse the repository at this point in the history
Progress on #294.

We could mirror requirements between `requirements.txt` and
`pyproject.toml` or keep them dynamic. For packaging, we probably don't
want to set explicit versions unless absolutely required. Developers may
want to pin to a specific version to make testing consistent though.

As part of this I added a dep on `iree-turbine` to sharktank's
`requirements.txt` and then switched workflows and user guides to
install `sharktank` first and _then_ install a newer/local version from
git if desired.

---------

Co-authored-by: Marius Brehler <marius.brehler@gmail.com>
  • Loading branch information
ScottTodd and marbre authored Nov 8, 2024
1 parent 0d949de commit 9d724a2
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 27 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci-llama-large-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ jobs:
# from non default locations first. Installing the PyTorch CPU
# wheels saves multiple minutes and a lot of bandwidth on runner setup.
pip install --no-compile -r pytorch-cpu-requirements.txt
pip install --no-compile -r requirements.txt -r sharktank/requirements-tests.txt -e sharktank/
# Install latest iree-tubrine.
pip install --no-compile -f https://iree.dev/pip-release-links.html --src deps \
-e "git+https://github.com/iree-org/iree-turbine.git#egg=iree-turbine"
pip install --no-compile -r requirements.txt -r sharktank/requirements-tests.txt -e sharktank/
# Test with pinned nightly releases, not what iree-turbine uses.
pip install -f https://iree.dev/pip-release-links.html --upgrade \
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ci-llama-quick-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ jobs:
# from non default locations first. Installing the PyTorch CPU
# wheels saves multiple minutes and a lot of bandwidth on runner setup.
pip install --no-compile -r pytorch-cpu-requirements.txt
pip install --no-compile -r requirements.txt -r sharktank/requirements-tests.txt -e sharktank/
# Install latest iree-tubrine.
pip install --no-compile -f https://iree.dev/pip-release-links.html --src deps \
-e "git+https://github.com/iree-org/iree-turbine.git#egg=iree-turbine"
pip install --no-compile -r requirements.txt -r sharktank/requirements-tests.txt -e sharktank/
# Test with pinned nightly releases, not what iree-turbine uses.
pip install -f https://iree.dev/pip-release-links.html --upgrade \
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/ci-shark-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ jobs:
# from non default locations first. Installing the PyTorch CPU
# wheels saves multiple minutes and a lot of bandwidth on runner setup.
pip install --no-compile -r pytorch-cpu-requirements.txt
pip install --no-compile -r requirements.txt -e sharktank/ shortfin/
# Install latest iree-tubrine.
pip install --no-compile -f https://iree.dev/pip-release-links.html --src deps \
-e "git+https://github.com/iree-org/iree-turbine.git#egg=iree-turbine"
pip install --no-compile -r requirements.txt -e sharktank/ shortfin/
# Try with the latest nightly releases, not what iree-turbine uses.
# Try with the latest IREE nightly releases, not what iree-turbine pins.
# We could also pin to a known working or stable version.
# This should eventually stabilize. Do the best we can for now.
pip install -f https://iree.dev/pip-release-links.html --upgrade \
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/ci-sharktank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ jobs:
# from non default locations first. Installing the PyTorch CPU
# wheels saves multiple minutes and a lot of bandwidth on runner setup.
pip install --no-compile -r pytorch-cpu-requirements.txt
pip install --no-compile -f https://iree.dev/pip-release-links.html --src deps \
-e "git+https://github.com/iree-org/iree-turbine.git#egg=iree-turbine"
pip install --no-compile -r requirements.txt -r sharktank/requirements-tests.txt -e sharktank/
# Update to the latest iree packages.
pip install -f https://iree.dev/pip-release-links.html --upgrade \
iree-compiler iree-runtime --src deps \
-e "git+https://github.com/iree-org/iree-turbine.git#egg=iree-turbine"
- name: Run sharktank tests
if: ${{ !cancelled() }}
run: |
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/ci_eval.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,20 @@ jobs:
# from non default locations first. Installing the PyTorch CPU
# wheels saves multiple minutes and a lot of bandwidth on runner setup.
pip install --no-compile -r pytorch-cpu-requirements.txt
pip install --no-compile -r requirements.txt -r sharktank/requirements-tests.txt -e sharktank/
# Install latest iree-tubrine.
pip install --no-compile -f https://iree.dev/pip-release-links.html --src deps \
-e "git+https://github.com/iree-org/iree-turbine.git#egg=iree-turbine"
pip install --no-compile -r requirements.txt -r sharktank/requirements-tests.txt -e sharktank/
# Try with the latest nightly releases, not what iree-turbine uses.
# Try with the latest IREE nightly releases, not what iree-turbine pins.
# We could also pin to a known working or stable version.
# This should eventually stabilize. Do the best we can for now.
pip install -f https://iree.dev/pip-release-links.html --upgrade \
iree-base-compiler \
iree-base-runtime \
"numpy<2.0"
- name: Run perplexity test with vmfb
run: pytest -n 8 -v -s sharktank/tests/evaluate/perplexity_vmfb_test.py --longrun --iree-device='hip://7' --iree-hip-target=gfx942 --iree-hal-target-backends=rocm --llama3-8b-f16-model-path=/data/llama3.1/8b/llama8b_f16.irpa --llama3-8b-tokenizer-path=/data/llama3.1/8b/tokenizer_config.json

Expand Down Expand Up @@ -113,9 +116,11 @@ jobs:
# from non default locations first. Installing the PyTorch CPU
# wheels saves multiple minutes and a lot of bandwidth on runner setup.
pip install --no-compile -r pytorch-cpu-requirements.txt
pip install --no-compile -r requirements.txt -r sharktank/requirements-tests.txt -e sharktank/
# Install latest iree-tubrine.
pip install --no-compile -f https://iree.dev/pip-release-links.html --src deps \
-e "git+https://github.com/iree-org/iree-turbine.git#egg=iree-turbine"
pip install --no-compile -r requirements.txt -r sharktank/requirements-tests.txt -e sharktank/
- name: Run perplexity test in eager mode
run: pytest -n 8 -v -s sharktank/tests/evaluate/perplexity_torch_test.py --longrun --llama3-8b-f16-model-path=/data/llama3.1/8b/llama8b_f16.irpa --llama3-8b-tokenizer-path=/data/llama3.1/8b/tokenizer_config.json
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ We recommend setting up a virtual environment (venv). The project is configured
to ignore `.venv` directories, and editors like VSCode pick them up by default.

```
python -m venv --prompt sharktank .venv
python -m venv .venv
source .venv/bin/activate
```

Expand All @@ -94,12 +94,12 @@ pip install -r pytorch-rocm-requirements.txt
### Install development packages

```
# Clone and install editable iree-turbine dep in deps/
pip install -f https://iree.dev/pip-release-links.html --src deps \
-e "git+https://github.com/iree-org/iree-turbine.git#egg=iree-turbine"
# Install editable local projects.
pip install -r requirements.txt -e sharktank/ shortfin/
# Optionally clone and install editable iree-turbine dep in deps/
pip install -f https://iree.dev/pip-release-links.html --src deps \
-e "git+https://github.com/iree-org/iree-turbine.git#egg=iree-turbine"
```

### Running tests
Expand Down
5 changes: 0 additions & 5 deletions docs/nightly_releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ source 3.11.venv/bin/activate
# Install 'sharktank' package from nightly releases.
python -m pip install sharktank -f https://github.com/nod-ai/SHARK-Platform/releases/expanded_assets/dev-wheels

# Install some other dependencies.
# TODO(#294): list these as "dependencies" in `pyproject.toml` or make optional?
python -m pip install gguf numpy huggingface-hub transformers datasets \
sentencepiece

# Test the installation.
python -c "from sharktank import ops; print('Sanity check passed')"

Expand Down
10 changes: 9 additions & 1 deletion sharktank/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ python -m sharktank.tools.dump_gguf --hf-dataset=open_llama_3b_v2_f16_gguf
* To build wheels for Linux:

```bash
sudo ./build_tools/build_linux_package.sh
./build_tools/build_linux_package.sh
```

That should produce
`build_tools/wheelhouse/sharktank-{X.Y.Z}.dev0-py3-none-any.whl`, which can
then be installed with

```bash
python3 -m pip install build_tools/wheelhouse/sharktank-{X.Y.Z}.dev0-py3-none-any.whl
```

* To build a wheel for your host OS/arch manually:
Expand Down
8 changes: 7 additions & 1 deletion sharktank/build_tools/build_linux_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

# build_linux_package.sh
#
# Builds sharktank Python package for Linux
# Builds sharktank Python package for Linux.
#
# Note: requires a modern Python (3.12+ seems to work). Troubleshooting help:
# * https://stackoverflow.com/a/77284076
# * https://stackoverflow.com/a/77364602
# Older versions like 3.10 don't include the package name and set as UNKNOWN?
# * Might just need some local packages updated?
#
# Usage:
# ./build_tools/build_linux_package.sh
Expand Down
13 changes: 7 additions & 6 deletions sharktank/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ classifiers = [
"Programming Language :: Python :: 3.13",
]
requires-python = ">= 3.11"
dependencies = ["iree-turbine"]
dynamic = ["version"] # the version is set via the `setup.py`

[project.optional-dependencies]
testing = ["pytest"]
# Version is set via the `setup.py` and requirements are set via files below.
dynamic = ["version", "dependencies", "optional-dependencies"]

[project.urls]
Repository = "https://github.com/nod-ai/SHARK-Platform"
Expand All @@ -36,8 +34,11 @@ namespaces = true
[tool.setuptools.package-data]
sharktank = ["py.typed", "kernels/templates/*.mlir"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
[tool.setuptools.dynamic.dependencies]
file = ["requirements.txt"]

[tool.setuptools.dynamic.optional-dependencies]
testing = {file = ["requirements-tests.txt"]}

[tool.pytest.ini_options]
addopts = [
Expand Down
5 changes: 5 additions & 0 deletions sharktank/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
iree-turbine

# Runtime deps.
gguf==0.6.0
numpy==1.26.3

# Needed for newer gguf versions (TODO: remove when gguf package includes this)
# sentencepiece>=0.1.98,<=0.2.0

# Model deps.
huggingface-hub==0.22.2
transformers==4.40.0
Expand Down

0 comments on commit 9d724a2

Please sign in to comment.