Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove components that have been upstreamed. #655

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions .github/workflows/test.yml

This file was deleted.

19 changes: 13 additions & 6 deletions .github/workflows/test_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ jobs:
# with:
# python-version: ${{matrix.version}}

- name: "Checkout Code"
uses: actions/checkout@v2
- name: "Checkout This Repo"
uses: actions/checkout@v4

- name: "Checkout iree-turbine"
uses: actions/checkout@v4
with:
repository: iree-org/iree-turbine
# TODO: Let the ref be passed as a parameter to run integration tests.
path: iree-turbine

- name: Sync source deps
# build IREE from source with -DIREE_BUILD_TRACY=ON if getting tracy profile
Expand All @@ -42,10 +49,10 @@ jobs:
# Note: We install in three steps in order to satisfy requirements
# from non default locations first. Installing the PyTorch CPU
# wheels saves multiple minutes and a lot of bandwidth on runner setup.
pip install -r core/pytorch-cpu-requirements.txt
pip install --pre --upgrade -r core/requirements.txt
pip install --pre -e core[testing]
pip install --pre --upgrade -e models -r models/requirements.txt
pip install --no-compile -r ${{ github.workspace }}/iree-turbine/pytorch-cpu-requirements.txt
pip install --no-compile --pre --upgrade -r ${{ github.workspace }}/iree-turbine/requirements.txt
pip install --no-compile --pre -e ${{ github.workspace }}/iree-turbine[testing]
pip install --no-compile --pre --upgrade -e models -r models/requirements.txt

- name: Show current free memory
run: |
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/test_sdxl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,30 @@ jobs:
python-version: ${{matrix.version}}

- name: "Checkout Code"
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: ean-sd-fp16

- name: "Checkout iree-turbine"
uses: actions/checkout@v4
with:
repository: iree-org/iree-turbine
# TODO: Let the ref be passed as a parameter to run integration tests.
path: iree-turbine

- name: Sync source deps
# build IREE from source with -DIREE_BUILD_TRACY=ON if getting tracy profile
run: |
python -m pip install --upgrade pip
# Note: We install in three steps in order to satisfy requirements
# from non default locations first. Installing the PyTorch CPU
# wheels saves multiple minutes and a lot of bandwidth on runner setup.
pip install --index-url https://download.pytorch.org/whl/cpu \
-r core/pytorch-cpu-requirements.txt
pip install --upgrade -r core/requirements.txt
pip install -e core[testing,torch-cpu-nightly]
pip install --upgrade -r models/requirements.txt
pip install -e models
pip install --no-compile --index-url https://download.pytorch.org/whl/cpu \
-r ${{ github.workspace }}/iree-turbine//pytorch-cpu-requirements.txt
pip install --no-compile --upgrade -r ${{ github.workspace }}/iree-turbine/requirements.txt
pip install --no-compile -e ${{ github.workspace }}/iree-turbine/[testing,torch-cpu-nightly]
pip install --no-compile --upgrade -r models/requirements.txt
pip install --no-compile -e models

- name: Show current free memory
run: |
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/test_shark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ jobs:
path: SHARK
ref: "main"

- name: "Checkout iree-turbine"
uses: actions/checkout@v4
with:
repository: iree-org/iree-turbine
# TODO: Let the ref be passed as a parameter to run integration tests.
path: iree-turbine

# TODO: Replace with a sh script from shark repo
- name: "Install SHARK"
run: |
Expand Down
137 changes: 19 additions & 118 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,129 +1,30 @@
# SHARK Turbine

![image](https://netl.doe.gov/sites/default/files/2020-11/Turbine-8412270026_83cfc8ee8f_c.jpg)
This repo is Nod-AI's integration repository for various model bringup
activities and CI. In 2023 and early 2024, it played a different role
by being the place where FX/Dynamo based torch-mlir and IREE toolsets
were developed, including:

Turbine is the set of development tools that the [SHARK Team](https://github.com/nod-ai/SHARK)
is building for deploying all of our models for deployment to the cloud and devices. We
are building it as we transition from our TorchScript-era 1-off export and compilation
to a unified approach based on PyTorch 2 and Dynamo. While we use it heavily ourselves, it
is intended to be a general purpose model compilation and execution tool.
* [Torch-MLIR FxImporter](https://github.com/llvm/torch-mlir/blob/main/python/torch_mlir/extras/fx_importer.py)
* [Torch-MLIR ONNX Importer](https://github.com/llvm/torch-mlir/blob/main/python/torch_mlir/extras/onnx_importer.py)
* [Torch-MLIR's ONNX C Importer](https://github.com/llvm/torch-mlir/tree/main/projects/onnx_c_importer)
* [IREE Turbine](https://github.com/iree-org/iree-turbine)
* [Sharktank and Shortfin](https://github.com/nod-ai/sharktank)

Turbine provides a collection of tools:
As these have all found upstream homes, this repo is a bit bare. We will
continue to use it as a staging ground for things that don't have a
more defined spot and as a way to drive certain kinds of upstreaming
activities.

* *AOT Export*: For compiling one or more `nn.Module`s to compiled, deployment
ready artifacts. This operates via both a simple one-shot export API (Already upstreamed to [torch-mlir](https://github.com/llvm/torch-mlir/blob/main/python/torch_mlir/extras/fx_importer.py))
for simple models and an underlying [advanced API](https://github.com/nod-ai/SHARK-Turbine/blob/main/core/shark_turbine/aot/compiled_module.py) for complicated models
and accessing the full features of the runtime.
* *Eager Execution*: A `torch.compile` backend is provided and a Turbine Tensor/Device
is available for more native, interactive use within a PyTorch session.
* *Turbine Kernels*: (coming soon) A union of the [Triton](https://github.com/openai/triton) approach and
[Pallas](https://jax.readthedocs.io/en/latest/pallas/index.html) but based on
native PyTorch constructs and tracing. It is intended to complement for simple
cases where direct emission to the underlying, cross platform, vector programming model
is desirable.
* *Turbine-LLM*: a repository of layers, model recipes, and conversion tools
from popular Large Language Model (LLM) quantization tooling.

Under the covers, Turbine is based heavily on [IREE](https://github.com/openxla/iree) and
[torch-mlir](https://github.com/llvm/torch-mlir) and we use it to drive evolution
of both, upstreaming infrastructure as it becomes timely to do so.
## Current Projects

See [the roadmap](docs/roadmap.md) for upcoming work and places to contribute.
### turbine-models

## Contact Us
The `turbine-models` project (under models/) contains ports and adaptations
of various (mostly HF) models that we use in various ways.

Turbine is under active development. If you would like to participate as it comes online,
please reach out to us on the `#turbine` channel of the
[nod-ai Discord server](https://discord.gg/QMmR6f8rGb).
### CI

## Quick Start for Users
Integration CI for a variety of projects is rooted in this repo.

1. Install from source:

```
pip install shark-turbine
# Or for editable: see instructions under developers
```

The above does install some unecessary cuda/cudnn packages for cpu use. To avoid this you
can specify pytorch-cpu and install via:
```
pip install -r core/pytorch-cpu-requirements.txt
pip install shark-turbine
```

(or follow the "Developers" instructions below for installing from head/nightly)

2. Try one of the samples:

Generally, we use Turbine to produce valid, dynamic shaped Torch IR (from the
[`torch-mlir torch` dialect](https://github.com/llvm/torch-mlir/tree/main/include/torch-mlir/Dialect/Torch/IR)
with various approaches to handling globals). Depending on the use-case and status of the
compiler, these should be compilable via IREE with `--iree-input-type=torch` for
end to end execution. Dynamic shape support in torch-mlir is a work in progress,
and not everything works at head with release binaries at present.

* [AOT MLP With Static Shapes](https://github.com/nod-ai/SHARK-Turbine/blob/main/core/examples/aot_mlp/mlp_export_simple.py)
* [AOT MLP with a dynamic batch size](https://github.com/nod-ai/SHARK-Turbine/blob/main/core/examples/aot_mlp/mlp_export_dynamic.py)
* [AOT llama2](https://github.com/nod-ai/SHARK-Turbine/blob/main/core/examples/llama2_inference/llama2.ipynb):
Dynamic sequence length custom compiled module with state management internal to the model.
* [Eager MNIST with `torch.compile`](https://github.com/nod-ai/SHARK-Turbine/blob/main/core/examples/eager_mlp/mlp_eager_simple.py)

## Developers

### Getting Up and Running

If only looking to develop against this project, then you need to install Python
deps for the following:

* PyTorch
* iree-compiler (with Torch input support)
* iree-runtime

The pinned deps at HEAD require pre-release versions of all of the above, and
therefore require additional pip flags to install. Therefore, to satisfy
development, we provide a `requirements.txt` file which installs precise
versions and has all flags. This can be installed prior to the package:

Installing into a venv is highly recommended.

```
pip install -r core/pytorch-cpu-requirements.txt
pip install --upgrade -r core/requirements.txt
pip install --upgrade -e "core[torch-cpu-nightly,testing]"
```

Run tests:

```
pytest core/
```

### Using a development compiler

If doing native development of the compiler, it can be useful to switch to
source builds for iree-compiler and iree-runtime.

In order to do this, check out [IREE](https://github.com/openxla/iree) and
follow the instructions to [build from source](https://iree.dev/building-from-source/getting-started/), making
sure to specify [additional options for the Python bindings](https://iree.dev/building-from-source/getting-started/#building-with-cmake):

```
-DIREE_BUILD_PYTHON_BINDINGS=ON -DPython3_EXECUTABLE="$(which python)"
```

#### Configuring Python

Uninstall existing packages:

```
pip uninstall iree-compiler
pip uninstall iree-runtime
```

Copy the `.env` file from `iree/` to this source directory to get IDE
support and add to your path for use from your shell:

```
source .env && export PYTHONPATH
```
Loading
Loading