Skip to content

Commit d246b93

Browse files
committed
Add new lemonade examples and installer. Update source code.
1 parent a648f21 commit d246b93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1559
-276
lines changed

Diff for: .github/workflows/test_lemonade.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ jobs:
5555
- name: Run lemonade tests
5656
shell: bash -el {0}
5757
run: |
58-
lemonade -i facebook/opt-125m huggingface-load llm-prompt -p "hi" --max-new-tokens 10
59-
python test/llm_api.py
58+
# Test CLI
59+
lemonade -m -i facebook/opt-125m huggingface-load llm-prompt -p "hi" --max-new-tokens 10
6060
61+
# Test low-level APIs
62+
python test/lemonade/llm_api.py
63+
64+
65+
# Test high-level LEAP APIs
66+
python examples/lemonade/leap_basic.py
67+
python examples/lemonade/leap_streaming.py
6168

Diff for: .github/workflows/test_lemonade_oga_cpu.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ jobs:
5555
env:
5656
HF_TOKEN: "${{ secrets.HUGGINGFACE_ACCESS_TOKEN }}" # Required by OGA model_builder in OGA 0.4.0 but not future versions
5757
run: |
58+
# Test CLI
5859
lemonade -i TinyPixel/small-llama2 oga-load --device cpu --dtype int4 llm-prompt -p "tell me a story" --max-new-tokens 5
59-
python test/oga_cpu_api.py
60+
61+
# Test low-level APIs
62+
python test/lemonade/oga_cpu_api.py
63+
64+
# Test high-level LEAP APIs
65+
python examples/lemonade/leap_oga_cpu.py
66+
python examples/lemonade/leap_oga_cpu_streaming.py
6067

Diff for: .github/workflows/test_turnkey.yml

+16-47
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ on:
88
branches: ["main", "canary", "refresh"]
99
pull_request:
1010
branches: ["main", "canary", "refresh"]
11+
paths:
12+
- src/turnkeyml/**
13+
- test/turnkey/**
14+
- examples/turnkey/**
15+
- .github/workflows/test_turnkey.yml
1116

1217
permissions:
1318
contents: read
@@ -50,68 +55,32 @@ jobs:
5055
shell: bash -el {0}
5156
run: |
5257
# Unit tests
53-
python test/unit.py
58+
python test/turnkey/unit.py
5459
5560
# turnkey examples
5661
# Note: we clear the default cache location prior to each block of example runs
5762
rm -rf ~/.cache/turnkey
58-
python examples/api/onnx_opset.py --onnx-opset 15
59-
python examples/api/loading_a_build.py
63+
python examples/turnkey/api/onnx_opset.py --onnx-opset 15
64+
python examples/turnkey/api/loading_a_build.py
6065
6166
rm -rf ~/.cache/turnkey
62-
turnkey -i examples/cli/scripts/hello_world.py discover export-pytorch benchmark
67+
turnkey -i examples/turnkey/cli/scripts/hello_world.py discover export-pytorch benchmark
6368
rm -rf ~/.cache/turnkey
64-
turnkey -i examples/cli/scripts/multiple_invocations.py discover export-pytorch benchmark
69+
turnkey -i examples/turnkey/cli/scripts/multiple_invocations.py discover export-pytorch benchmark
6570
rm -rf ~/.cache/turnkey
66-
turnkey -i examples/cli/scripts/max_depth.py discover --max-depth 1 export-pytorch benchmark
71+
turnkey -i examples/turnkey/cli/scripts/max_depth.py discover --max-depth 1 export-pytorch benchmark
6772
rm -rf ~/.cache/turnkey
68-
turnkey -i examples/cli/scripts/two_models.py discover export-pytorch benchmark
73+
turnkey -i examples/turnkey/cli/scripts/two_models.py discover export-pytorch benchmark
6974
rm -rf ~/.cache/turnkey
70-
turnkey -i examples/cli/onnx/hello_world.onnx load-onnx benchmark
75+
turnkey -i examples/turnkey/cli/onnx/hello_world.onnx load-onnx benchmark
7176
7277
# E2E tests
73-
cd test/
78+
cd test/turnkey
7479
python cli.py
7580
python analysis.py
7681
- name: Test example plugins
7782
shell: bash -el {0}
7883
run: |
7984
rm -rf ~/.cache/turnkey
80-
pip install -e examples/cli/plugins/example_tool
81-
turnkey -i examples/cli/scripts/hello_world.py discover export-pytorch example-plugin-tool benchmark
82-
# - name: Install and Start Slurm
83-
# if: runner.os != 'Windows'
84-
# shell: bash -el {0}
85-
# run: |
86-
# sudo apt update -y
87-
# sudo apt install slurm-wlm -y
88-
# cp test/helpers/slurm.conf test/helpers/slurm_modified.conf
89-
# sed -i "s/YOUR_HOSTNAME_HERE/$HOSTNAME/" test/helpers/slurm_modified.conf
90-
# sudo mv test/helpers/slurm_modified.conf /etc/slurm/slurm.conf
91-
# sudo service slurmd start
92-
# sudo service slurmctld start
93-
# sudo service munge start
94-
# - name: Test turnkey on Slurm
95-
# if: runner.os != 'Windows'
96-
# shell: bash -el {0}
97-
# run: |
98-
# # Create conda environment for Slurm using srun (sbatch + wait)
99-
# export SKIP_REQUIREMENTS_INSTALL="True"
100-
# export TORCH_CPU="True"
101-
# srun src/turnkeyml/cli/setup_venv.sh
102-
103-
# # Run tests on Slurm
104-
# export TURNKEY_SLURM_USE_DEFAULT_MEMORY="True"
105-
# turnkey -i models/selftest/linear.py --use-slurm --cache-dir local_cache discover export-pytorch
106-
# bash test/helpers/check_slurm_output.sh slurm-2.out
107-
108-
# Below tests are commented out as the GitHub runner runs out of space installing the requirements
109-
# - name: Check installation of requirements.txt and their compatibility with turnkey
110-
# shell: bash -el {0}
111-
# run: |
112-
# conda create --name test-requirements python=3.8
113-
# conda activate test-requirements
114-
# pip install -r models/requirements.txt
115-
# python -m pip check
116-
# python -c "import torch_geometric"
117-
# conda deactivate
85+
pip install -e examples/turnkey/cli/plugins/example_tool
86+
turnkey -i examples/turnkey/cli/scripts/hello_world.py discover export-pytorch example-plugin-tool benchmark

Diff for: README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
We are on a mission to make it easy to use the most important tools in the ONNX ecosystem. TurnkeyML accomplishes this by providing no-code CLIs and low-code APIs for both general ONNX workflows with `turnkey` as well as LLMs with `lemonade`.
99

10-
| [**Lemonade**](https://github.com/onnx/turnkeyml/tree/main/src/turnkeyml/llm) | [**Turnkey**](https://github.com/onnx/turnkeyml/blob/main/docs/classic_getting_started.md) |
10+
| [**Lemonade**](https://github.com/onnx/turnkeyml/tree/main/src/turnkeyml/llm) | [**Turnkey**](https://github.com/onnx/turnkeyml/blob/main/docs/turnkey/getting_started.md) |
1111
|:----------------------------------------------: |:-----------------------------------------------------------------: |
12-
| Serve and benchmark LLMs on CPU, GPU, and NPU. <br/> [Click here to get started with `lemonade`.](https://github.com/onnx/turnkeyml/blob/main/docs/lemonade_getting_started.md) | Export and optimize ONNX models for CNNs and Transformers. <br/> [Click here to get started with `turnkey`.](https://github.com/onnx/turnkeyml/blob/main/docs/classic_getting_started.md) |
13-
| <img src="img/llm_demo.png"/> | <img src="img/classic_demo.png"/> |
12+
| Serve and benchmark LLMs on CPU, GPU, and NPU. <br/> [Click here to get started with `lemonade`.](https://github.com/onnx/turnkeyml/blob/main/docs/lemonade/getting_started.md) | Export and optimize ONNX models for CNNs and Transformers. <br/> [Click here to get started with `turnkey`.](https://github.com/onnx/turnkeyml/blob/main/docs/turnkey/getting_started.md) |
13+
| <img src="https://github.com/onnx/turnkeyml/blob/main/img/llm_demo.png?raw=true"/> | <img src="https://github.com/onnx/turnkeyml/blob/main/img/classic_demo.png?raw=true"/> |
1414

1515

1616
## How It Works

Diff for: docs/code.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
The TurnkeyML source code has a few major top-level directories:
66
- `docs`: documentation for the entire project.
77
- `examples`: example scripts for use with the TurnkeyML tools.
8-
- `examples/cli`: tutorial series starting in `examples/cli/readme.md` to help learn the `turnkey` CLI.
9-
- `examples/cli/scripts`: example scripts that can be fed as input into the `turnkey` CLI. These scripts each have a docstring that recommends one or more `turnkey` CLI commands to try out.
10-
- `examples/api`: examples scripts that invoke `Tools` via APIs.
8+
- `examples/turnkey/cli`: tutorial series starting in `examples/turnkey/cli/readme.md` to help learn the `turnkey` CLI.
9+
- `examples/turnkey/cli/scripts`: example scripts that can be fed as input into the `turnkey` CLI. These scripts each have a docstring that recommends one or more `turnkey` CLI commands to try out.
10+
- `examples/turnkey/api`: examples scripts that invoke `Tools` via APIs.
1111
- `models`: the corpora of models that makes up the TurnkeyML models (see [the models readme](https://github.com/onnx/turnkeyml/blob/main/models/readme.md)).
1212
- Each subdirectory under `models` represents a corpus of models pulled from somewhere on the internet. For example, `models/torch_hub` is a corpus of models from [Torch Hub](https://github.com/pytorch/hub).
1313
- `src/turnkeyml`: source code for the TurnkeyML package.
@@ -20,8 +20,8 @@ The TurnkeyML source code has a few major top-level directories:
2020
- `src/turnkeyml/state.py`: implements the `State` class.
2121
- `src/turnkeyml/files_api.py`: implements the `evaluate_files()` API, which is the top-level API called by the CLI.
2222
- `test`: tests for the TurnkeyML tools.
23-
- `test/analysis.py`: tests focusing on the `discover` `Tool`.
24-
- `test/cli.py`: tests focusing on top-level CLI features.
23+
- `test/turnkey/analysis.py`: tests focusing on the `discover` `Tool`.
24+
- `test/turnkey/cli.py`: tests focusing on top-level CLI features.
2525

2626
## Tool Classes
2727

Diff for: docs/contribute.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ We require the following naming scheme:
8888

8989
### Example
9090

91-
See the [example_tool](https://github.com/onnx/turnkeyml/tree/main/examples/cli/plugins/example_tool) plugin for an example.
91+
See the [example_tool](https://github.com/onnx/turnkeyml/tree/main/examples/turnkey/cli/plugins/example_tool) plugin for an example.
9292

9393
The `__init__.py` file with its `implements` dictionary looks like:
9494

Diff for: docs/lemonade/getting_started.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ That command will run a few warmup iterations, then a few generation iterations
6464

6565
The prompt size, number of output tokens, and number iterations are all parameters. Learn more by running `lemonade huggingface-bench -h`.
6666

67+
## Memory Usage
68+
69+
The peak memory used by the lemonade build is captured in the build output. To capture more granular
70+
memory usage information, use the `--memory` flag. For example:
71+
72+
`lemonade -i facebook/opt-125m --memory huggingface-load huggingface-bench`
73+
74+
In this case a `memory_usage.png` file will be generated and stored in the build folder. This file
75+
contains a figure plotting the memory usage over the build time. Learn more by running `lemonade -h`.
76+
6777
## Serving
6878

6979
You can launch a WebSocket server for your LLM with:
@@ -111,9 +121,9 @@ You can also try Phi-3-Mini-128k-Instruct with the following commands:
111121

112122
`lemonade -i microsoft/Phi-3-mini-4k-instruct oga-load --device igpu --dtype int4 serve`
113123

114-
You can learn more about the CPU and iGPU support in our [OGA documentation](https://github.com/onnx/turnkeyml/blob/main/docs/ort_genai_igpu.md).
124+
You can learn more about the CPU and iGPU support in our [OGA documentation](https://github.com/onnx/turnkeyml/blob/main/docs/lemonade/ort_genai_igpu.md).
115125

116-
> Note: early access to AMD's RyzenAI NPU is also available. See the [RyzenAI NPU OGA documentation](https://github.com/onnx/turnkeyml/blob/main/docs/ort_genai_npu.md) for more information.
126+
> Note: early access to AMD's RyzenAI NPU is also available. See the [RyzenAI NPU OGA documentation](https://github.com/onnx/turnkeyml/blob/main/docs/lemonade/ort_genai_npu.md) for more information.
117127
118128
## Install RyzenAI NPU for PyTorch
119129

@@ -131,7 +141,7 @@ If you decide to contribute, please:
131141

132142
- do so via a pull request.
133143
- write your code in keeping with the same style as the rest of this repo's code.
134-
- add a test under `test/llm_api.py` that provides coverage of your new feature.
144+
- add a test under `test/lemonade/llm_api.py` that provides coverage of your new feature.
135145

136146
The best way to contribute is to add new tools to cover more devices and usage scenarios.
137147

Diff for: docs/readme.md

+33-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
# TurnkeyML Documentation
22

3-
This directory contains documentation for the TurnkeyML project:
3+
## LLMs: `lemonade` tooling
4+
5+
The `docs/lemonade` directory has documentation for the LLM-focused `lemonade` tooling:
6+
- [Getting Started](https://github.com/onnx/turnkeyml/blob/main/docs/lemonade/getting_started.md): start here for LLMs.
7+
- Accuracy tests (task performance):
8+
- [HumanEval](https://github.com/onnx/turnkeyml/blob/main/docs/lemonade/humaneval_accuracy.md): details of the HumanEval coding task test.
9+
- [MMLU](https://github.com/onnx/turnkeyml/blob/main/docs/lemonade/mmlu_accuracy.md): details of the MMLU general reasoning test.
10+
- [Perplexity](https://github.com/onnx/turnkeyml/blob/main/docs/lemonade/perplexity.md): details of the Perplexity test for LLMs.
11+
- Tool-specific setup guides:
12+
- [llama.cpp](https://github.com/onnx/turnkeyml/blob/main/docs/lemonade/llamacpp.md)
13+
- OnnxRuntime GenaI:
14+
- [iGPU/NPU hybrid](https://github.com/onnx/turnkeyml/blob/main/docs/lemonade/ort_genai_hybrid.md)
15+
- [iGPU](https://github.com/onnx/turnkeyml/blob/main/docs/lemonade/ort_genai_igpu.md)
16+
- [NPU](https://github.com/onnx/turnkeyml/blob/main/docs/lemonade/ort_genai_npu.md)
17+
18+
## CNNs and Transformers: `turnkey` tooling
19+
20+
The `docs/turnkey` directory contains documentation for the CNN/Transformer-focused `turnkey` tooling:
21+
22+
- [getting_started.md](https://github.com/onnx/turnkeyml/blob/main/docs/turnkey/getting_started.md)
23+
- [tools_user_guide.md](https://github.com/onnx/turnkeyml/blob/main/docs/turnkey/tools_user_guide.md): User guide for the tools: the `turnkey` CLI and the APIs.
24+
25+
26+
There is more useful documentation available in:
27+
- [examples/turnkey/cli/readme.md](https://github.com/onnx/turnkeyml/blob/main/examples/turnkey/cli/readme.md): Tutorial series for learning the `turnkey` CLI.
28+
- [models/readme.md](https://github.com/onnx/turnkeyml/blob/main/models/readme.md): Tutorial for understanding the models and how to use `turnkey` to evaluate the models.
29+
30+
## General Information
31+
32+
This directory also contains documentation for the TurnkeyML project as a whole:
33+
434
- [code.md](https://github.com/onnx/turnkeyml/blob/main/docs/code.md): Code organization for the tools.
535
- [install.md](https://github.com/onnx/turnkeyml/blob/main/docs/install.md): Installation instructions for the tools.
6-
- [tools_user_guide.md](https://github.com/onnx/turnkeyml/blob/main/docs/tools_user_guide.md): User guide for the tools: the `turnkey` CLI and the APIs.
736
- [versioning.md](https://github.com/onnx/turnkeyml/blob/main/docs/versioning.md): Defines the semantic versioning rules for the `turnkey` package.
8-
9-
There is more useful documentation available in:
10-
- [examples/cli/readme.md](https://github.com/onnx/turnkeyml/blob/main/examples/cli/readme.md): Tutorial series for learning the `turnkey` CLI.
11-
- [models/readme.md](https://github.com/onnx/turnkeyml/blob/main/models/readme.md): Tutorial for understanding the models and how to use `turnkey` to evaluate the models.
37+
- [contribute.md](https://github.com/onnx/turnkeyml/blob/main/docs/contribute.md): Contribution guidelines for the project.
38+
- [converage.md](https://github.com/onnx/turnkeyml/blob/main/docs/coverage.md): How to run code coverage metrics.

Diff for: docs/turnkey/getting_started.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ The easiest way to learn more about `turnkey` is to explore the help menu with `
4141
We also provide the following resources:
4242

4343
- [Installation guide](https://github.com/onnx/turnkeyml/blob/main/docs/install.md): how to install from source, set up Slurm, etc.
44-
- [User guide](https://github.com/onnx/turnkeyml/blob/main/docs/tools_user_guide.md): explains the concepts of `turnkey's`, including the syntax for making your own tool sequence.
45-
- [Examples](https://github.com/onnx/turnkeyml/tree/main/examples/cli): PyTorch scripts and ONNX files that can be used to try out `turnkey` concepts.
44+
- [User guide](https://github.com/onnx/turnkeyml/blob/main/docs/turnkey/tools_user_guide.md): explains the concepts of `turnkey's`, including the syntax for making your own tool sequence.
45+
- [Examples](https://github.com/onnx/turnkeyml/tree/main/examples/turnkey/cli): PyTorch scripts and ONNX files that can be used to try out `turnkey` concepts.
4646
- [Code organization guide](https://github.com/onnx/turnkeyml/blob/main/docs/code.md): learn how this repository is structured.
4747
- [Models](https://github.com/onnx/turnkeyml/blob/main/models/readme.md): PyTorch model scripts that work with `turnkey`.
4848

@@ -101,4 +101,4 @@ The build tool has built-in support for a variety of interoperable `Tools`. If y
101101
> turnkey -i my_model.py discover export-pytorch my-custom-tool --my-args
102102
```
103103

104-
All of the built-in `Tools` are implemented against the plugin API. Check out the [example plugins](https://github.com/onnx/turnkeyml/tree/main/examples/cli/plugins) and the [plugin API guide](https://github.com/onnx/turnkeyml/blob/main/docs/contribute.md#contributing-a-plugin) to learn more about creating an installable plugin.
104+
All of the built-in `Tools` are implemented against the plugin API. Check out the [example plugins](https://github.com/onnx/turnkeyml/tree/main/examples/turnkey/cli/plugins) and the [plugin API guide](https://github.com/onnx/turnkeyml/blob/main/docs/contribute.md#contributing-a-plugin) to learn more about creating an installable plugin.

Diff for: docs/turnkey/tools_user_guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Name of one or more script (.py), ONNX (.onnx), or cached build (_state.yaml) fi
108108
Examples:
109109
- `turnkey -i models/selftest/linear.py`
110110
- `turnkey -i models/selftest/linear.py models/selftest/twolayer.py`
111-
- `turnkey -i examples/cli/onnx/sample.onnx`
111+
- `turnkey -i examples/turnkey/cli/onnx/sample.onnx`
112112

113113
You may also use [Bash regular expressions](https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_01.html) to locate the files you want to benchmark.
114114

Diff for: examples/lemonade/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Lemonade Examples
2+
3+
This folder contains examples of how to use `lemonade` via the high-level LEAP APIs. These APIs make it easy to load a model, generate responses, and also show how to stream those responses.
4+
5+
The `demos/` folder also contains some higher-level application demos of the LEAP APIs. Learn more in `demos/README.md`.
6+
7+
## LEAP Examples
8+
9+
This table shows which LEAP examples are available:
10+
11+
| Framework | CPU | GPU | NPU | Hybrid |
12+
|----------------------------|---------------------------|------------------|-----------------|--------------------|
13+
| Huggingface | leap_basic.py | - | - | - |
14+
| OGA | leap_oga_cpu.py | leap_oga_igpu.py | leap_oga_npu.py | leap_oga_hybrid.py |
15+
| Huggingface with streaming | leap_streaming.py | - | - | - |
16+
| OGA with streaming | leap_oga_cpu_streaming.py | leap_oga_igpu_streaming.py | leap_oga_npu_streaming.py | leap_oga_hybrid_streaming.py |
17+
18+
To run a LEAP example, first set up a conda environment with the appropriate framework and backend support. Then run the scripts with a command like `python leap_basic.py`.

0 commit comments

Comments
 (0)