-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring OGA under test and fix OGA server. Improve llm-prompt. (#272)
Co-authored-by: Akshay Sonawane <[email protected]> Co-authored-by: amd-pworfolk <[email protected]>
- Loading branch information
1 parent
bc33e79
commit c1463b0
Showing
6 changed files
with
220 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 TinyPixel/small-llama2 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 TinyPixel/small-llama2 oga-load --device cpu --dtype int4 llm-prompt -p "tell me a story" --max-new-tokens 5 | ||
python test/oga_cpu_api.py | ||
This file contains 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 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 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 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 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 = "TinyPixel/small-llama2" | ||
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=5) | ||
|
||
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() |