-
Notifications
You must be signed in to change notification settings - Fork 25
Bring OGA under test and fix OGA server. Improve llm-prompt. #272
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
22fcc66
Improve llm-prompt. Bring OGA under test.
jeremyfowers 6fe0c7b
Fix streaming mode
jeremyfowers b43c0e9
Completely revert OGA 0.6 change
jeremyfowers ac1a740
Better compatibility for OGA
jeremyfowers 0a9897e
improve oga test speed
jeremyfowers 1d20ec7
Make sure llm-prompt never returns bad characters to the monitor
jeremyfowers 6d76740
Allow dev0 of OGA
jeremyfowers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
||
name: Lint and Test Lemonade for OGA on CPU | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
make-oga-cpu-lemonade: | ||
env: | ||
LEMONADE_CI_MODE: "True" | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Miniconda with 64-bit Python | ||
uses: conda-incubator/setup-miniconda@v2 | ||
with: | ||
miniconda-version: "latest" | ||
activate-environment: lemon | ||
python-version: "3.10" | ||
run-post: "false" | ||
- name: Install dependencies | ||
shell: bash -el {0} | ||
run: | | ||
python -m pip install --upgrade pip | ||
conda install pylint | ||
python -m pip check | ||
pip install -e .[llm-oga-cpu] | ||
- name: Lint with Black | ||
uses: psf/black@stable | ||
with: | ||
options: "--check --verbose" | ||
src: "./src" | ||
- name: Lint with PyLint | ||
shell: bash -el {0} | ||
run: | | ||
pylint src/lemonade --rcfile .pylintrc --disable E0401 | ||
- name: Test OGA+CPU server | ||
if: runner.os == 'Windows' | ||
timeout-minutes: 10 | ||
uses: ./.github/actions/server-testing | ||
with: | ||
conda_env: -n lemon | ||
load_command: -i Qwen/Qwen2.5-0.5B-Instruct oga-load --device cpu --dtype int4 | ||
hf_token: "${{ secrets.HUGGINGFACE_ACCESS_TOKEN }}" # Required by OGA model_builder in OGA 0.4.0 but not future versions | ||
- name: Run lemonade tests | ||
shell: bash -el {0} | ||
env: | ||
HF_TOKEN: "${{ secrets.HUGGINGFACE_ACCESS_TOKEN }}" # Required by OGA model_builder in OGA 0.4.0 but not future versions | ||
run: | | ||
lemonade -i Qwen/Qwen2.5-0.5B-Instruct oga-load --device cpu --dtype int4 llm-prompt -p "hi what is your name" --max-new-tokens 10 | ||
python test/oga_cpu_api.py | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import unittest | ||
import shutil | ||
import os | ||
import urllib3 | ||
from turnkeyml.state import State | ||
import turnkeyml.common.test_helpers as common | ||
import turnkeyml.common.filesystem as fs | ||
from lemonade.tools.ort_genai.oga import OgaLoad | ||
from lemonade.tools.chat import LLMPrompt | ||
from lemonade.tools.mmlu import AccuracyMMLU | ||
from lemonade.tools.humaneval import AccuracyHumaneval | ||
|
||
ci_mode = os.getenv("LEMONADE_CI_MODE", False) | ||
|
||
checkpoint = "Qwen/Qwen2.5-0.5B-Instruct" | ||
device = "cpu" | ||
dtype = "int4" | ||
force = False | ||
prompt = "Alice and Bob" | ||
|
||
try: | ||
url = "https://people.eecs.berkeley.edu/~hendrycks/data.tar" | ||
resp = urllib3.request("GET", url, preload_content=False) | ||
if 200 <= resp.status < 400: | ||
eecs_berkeley_edu_cannot_be_reached = False | ||
else: | ||
eecs_berkeley_edu_cannot_be_reached = True | ||
resp.release_conn() | ||
except urllib3.exceptions.HTTPError: | ||
eecs_berkeley_edu_cannot_be_reached = True | ||
|
||
|
||
class Testing(unittest.TestCase): | ||
|
||
def setUp(self) -> None: | ||
shutil.rmtree(cache_dir, ignore_errors=True) | ||
|
||
def test_001_ogaload(self): | ||
# Test the OgaLoad and LLMPrompt tools on an NPU model | ||
|
||
state = State(cache_dir=cache_dir, build_name="test") | ||
|
||
state = OgaLoad().run( | ||
state, input=checkpoint, device=device, dtype=dtype, force=force | ||
) | ||
state = LLMPrompt().run(state, prompt=prompt, max_new_tokens=10) | ||
|
||
assert len(state.response) > len(prompt), state.response | ||
|
||
@unittest.skipIf( | ||
eecs_berkeley_edu_cannot_be_reached, | ||
"eecs.berkeley.edu cannot be reached for dataset download", | ||
) | ||
def test_002_accuracy_mmlu(self): | ||
# Test MMLU benchmarking with known model | ||
subject = ["management"] | ||
|
||
state = State( | ||
cache_dir=cache_dir, | ||
build_name="test", | ||
) | ||
|
||
state = OgaLoad().run(state, input=checkpoint, device=device, dtype=dtype) | ||
state = AccuracyMMLU().run(state, ntrain=5, tests=subject) | ||
|
||
stats = fs.Stats(state.cache_dir, state.build_name).stats | ||
assert stats[f"mmlu_{subject[0]}_accuracy"] > 0 | ||
|
||
def test_003_accuracy_humaneval(self): | ||
"""Test HumanEval benchmarking with known model""" | ||
|
||
state = State( | ||
cache_dir=cache_dir, | ||
build_name="test", | ||
) | ||
|
||
# Enable code evaluation for HumanEval | ||
os.environ["HF_ALLOW_CODE_EVAL"] = "1" | ||
|
||
state = OgaLoad().run(state, input=checkpoint, device=device, dtype=dtype) | ||
state = AccuracyHumaneval().run( | ||
state, | ||
first_n_samples=1, # Test only one problem for speed | ||
k_samples=1, # Single attempt per problem | ||
timeout=30.0, | ||
) | ||
|
||
# Verify results | ||
stats = fs.Stats(state.cache_dir, state.build_name).stats | ||
assert "humaneval_pass@1" in stats, "HumanEval pass@1 metric not found" | ||
assert isinstance( | ||
stats["humaneval_pass@1"], (int, float) | ||
), "HumanEval pass@1 metric should be numeric" | ||
|
||
|
||
if __name__ == "__main__": | ||
cache_dir, _ = common.create_test_dir( | ||
"lemonade_oga_cpu_api", base_dir=os.path.abspath(".") | ||
) | ||
unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.