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

Test (example/llm): Refactor and add basic tests for the LLM entry-point #1002

Merged
merged 53 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
7a4642f
feat (example/llm): Moved argument parser to separate function.
nickfraser Aug 19, 2024
cd73b14
Refactor (example/llm): Refactor to prepare for automated tests.
nickfraser Aug 19, 2024
dcd6a78
test (example/llm): Added inital end-to-end example for LLM entry-point.
nickfraser Aug 19, 2024
3ef28d4
setup (requirements): added requirements file for LLM example for eas…
nickfraser Aug 19, 2024
5aad69e
Fix: pre-commit
nickfraser Aug 20, 2024
25d79e3
test (ex/llm): reorg code a little bit.
nickfraser Aug 20, 2024
e3575f4
test (ex/llm): removed quant_ppl to model definition
nickfraser Aug 20, 2024
6f8b186
test (ex/llm): removed replace MHA from toggle tests
nickfraser Aug 20, 2024
a5eedeb
test (ex/llm): added accuracy tests for some basic configurations
nickfraser Aug 20, 2024
89ffa00
test (ex/llm): Added initial tests that layers are inserted properly.
nickfraser Aug 21, 2024
cb149b4
test (ex/llm): allowed testing of multiple layer types
nickfraser Aug 21, 2024
5e7a7e7
test (ex/llm): Added extra layer replacement checks
nickfraser Aug 21, 2024
9dd38aa
Fix (ex/gen): Bugfix when applying MX as activation quantization type
nickfraser Aug 21, 2024
9940a9f
test (ex/llm): Added tests for FP8, MX datatypes
nickfraser Aug 21, 2024
b84a645
setup (ex/llm): Renamed requirements to match other examples.
nickfraser Aug 21, 2024
9f23bfb
req (ex/llm): Added explicit dependencies
nickfraser Aug 21, 2024
af6af4b
test (ex/llm): added weight-only test
nickfraser Aug 21, 2024
70145da
precommit
nickfraser Aug 21, 2024
f0ec89e
Feat (ex/llm): Allow supplying a prefix for the exported ONNX/TS model
nickfraser Aug 21, 2024
c9d9b66
test (ex/llm): Added ONNX export and torchscript tests.
nickfraser Aug 21, 2024
9a6e509
test (ex/llm): marked llm tests.
nickfraser Aug 23, 2024
c39749b
test (ex/llm): Added commented-out mixtral model
nickfraser Aug 23, 2024
f214f7c
test (ex/llm): Renamed llm test file.
nickfraser Aug 23, 2024
852714f
test (ex/llm): improved test compatibility with test infrastructure
nickfraser Aug 23, 2024
c778818
precommit
nickfraser Aug 23, 2024
c659e64
test (gha/ex/llm): Added new workflow to testing LLM example
nickfraser Aug 23, 2024
1deb288
test (ex/llm): Removed onnx dependency when collecting tests.
nickfraser Aug 23, 2024
7b63723
test (ex/llm): softened accuracy conditions
nickfraser Aug 23, 2024
0235b5c
test (ex/llm): reorganise to prevent export issues
nickfraser Aug 23, 2024
bedf1b3
precommit
nickfraser Aug 23, 2024
79c271a
test (ex/llm): remove upgrade flag to prevent new pytorch from being …
nickfraser Aug 23, 2024
44d2e56
test (gha/ex/llm): Added custom pytorch versions for LLM tests.
nickfraser Aug 23, 2024
32ea1ef
test (ex/llm/gha): Fixed custom pytorch versions for LLM test
nickfraser Aug 23, 2024
0a8d7ee
Bugfixes
nickfraser Aug 23, 2024
b3bcedd
test (ex/llm/nox): Better exclusion for examples.
nickfraser Aug 23, 2024
47d7cbb
Revert "test (ex/llm): reorganise to prevent export issues"
nickfraser Aug 23, 2024
9e3638b
Revert "test (ex/llm): Removed onnx dependency when collecting tests."
nickfraser Aug 23, 2024
a60911e
Precommit
nickfraser Aug 23, 2024
a48c74e
test (nox): Updated pytorch torchvision version list
nickfraser Aug 23, 2024
2c5e01a
Updated install method for PT>=2.4
nickfraser Aug 23, 2024
36c6037
test (llm/nox/gha): Updated env setup
nickfraser Aug 23, 2024
6215aa9
test (ex/llm): Updated test settings across multiple versions
nickfraser Aug 23, 2024
3cac63e
test (ex/llm): partitioned tests between pytorch versions.
nickfraser Aug 23, 2024
b0d6c63
test (ex/llm): Check input_view_impl for MX types
nickfraser Aug 26, 2024
f5dbed2
test (example/llm): Switched to PyTest cases. Added ids for more read…
nickfraser Sep 2, 2024
c544d57
test (example/llm): Added comment about Mixtral case
nickfraser Sep 2, 2024
08b8b73
pre-commit
nickfraser Sep 2, 2024
6d33990
test (example/llm): Removed JIT clause for accuracy tests.
nickfraser Sep 2, 2024
e59287b
test (example/test): Removed extra JIT checks.
nickfraser Sep 2, 2024
1399d84
test (example/llm): refactor run tests.
nickfraser Sep 2, 2024
0e762f7
test (example/llm): Added comments about PT versions.
nickfraser Sep 2, 2024
6e9283a
test (example/llm): Added tests to ensure all args to `main` are also…
nickfraser Sep 10, 2024
d071199
test (example/llm): fixed indentation for `toggle_run_args`
nickfraser Sep 11, 2024
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
65 changes: 65 additions & 0 deletions .github/workflows/examples_llm_pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Examples LLM Pytest

on:
push:
branches: [ master, dev ]
pull_request:
types:
- review_requested

jobs:
build:
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false


matrix:
python_version: ['3.8', '3.9']
pytorch_version: ['2.2.2', '2.3.1', '2.4.0']
platform: ['windows-latest', 'ubuntu-latest', 'macos-latest']
jit_status: ['jit_disabled', 'jit_enabled']


exclude:
- pytorch_version: '1.9.1'
platform: 'macos-latest'

- pytorch_version: '1.9.1'
jit_status: 'jit_enabled'



if: ${{ !github.event.pull_request.draft }}
steps:

- name: Checkout repo
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python_version }}

- name: Install Nox dependencies
shell: bash
run: pip install -r requirements/requirements-nox.txt

- name: Install update
shell: bash
run: sudo apt-get update
if: startsWith(runner.os, 'Linux') == true

- name: Install libsndfile and libgomp1 on Ubuntu
shell: bash
run: sudo apt-get install -y libsndfile-dev libgomp1
if: startsWith(runner.os, 'Linux') == true

- name: Install libomp on macOS
shell: bash
run: brew install libomp
if: startsWith(runner.os, 'macOS') == true

- name: Run Nox session for brevitas_examples pytest
shell: bash
run: nox -v -s tests_brevitas_examples_llm-${{ matrix.python_version }}\(${{ matrix.jit_status }}\,\ pytorch_${{ matrix.pytorch_version }}\)
35 changes: 35 additions & 0 deletions .github/workflows/gen_github_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
BASE_YML_REDUCED_TEMPLATE = 'base_reduced.yml.template'
PYTEST_YML = 'pytest.yml'
EXAMPLES_PYTEST_YML = 'examples_pytest.yml'
EXAMPLES_LLM_PYTEST_YML = 'examples_llm_pytest.yml'
DEVELOP_INSTALL_YML = 'develop_install.yml'
FINN_INTEGRATION_YML = 'finn_integration.yml'
ORT_INTEGRATION_YML = 'ort_integration.yml'
Expand All @@ -25,6 +26,10 @@
('pytorch_version', list(PYTORCH_LIST_REDUCED)),
('platform', PLATFORM_LIST_REDUCED)])

EXAMPLES_LLM_PYTEST_MATRIX_REDUCED = od([('python_version', list(PYTHON_VERSIONS_REDUCED)),
('pytorch_version', list(
('2.4.0',))), ('platform', PLATFORM_LIST_REDUCED)])

FINN_MATRIX_REDUCED = od([('python_version', list(PYTHON_VERSIONS_REDUCED)),
('pytorch_version', list(PYTORCH_LIST_REDUCED)),
('platform', PLATFORM_LIST_REDUCED)])
Expand Down Expand Up @@ -61,6 +66,11 @@
MATRIX = od([('python_version', list(PYTHON_VERSIONS)), ('pytorch_version', list(PYTORCH_VERSIONS)),
('platform', PLATFORM_LIST)])

EXAMPLES_LLM_PYTEST_PYTORCH_VERSIONS = ('2.2.2', '2.3.1', '2.4.0')
EXAMPLES_LLM_PYTEST_MATRIX = od([('python_version', list(PYTHON_VERSIONS)),
('pytorch_version', list(EXAMPLES_LLM_PYTEST_PYTORCH_VERSIONS)),
('platform', PLATFORM_LIST)])

FINN_MATRIX = od([('python_version', list(PYTHON_VERSIONS)),
('pytorch_version', list(PYTORCH_VERSIONS)), ('platform', FINN_PLATFORM_LIST)])

Expand All @@ -80,6 +90,13 @@
'nox -v -s tests_brevitas_examples_cpu-${{ matrix.python_version }}\(${{ matrix.jit_status }}\,\ pytorch_${{ matrix.pytorch_version }}\)'
)]),]

EXAMPLES_LLM_PYTEST_STEP_LIST = [
od([('name', 'Run Nox session for brevitas_examples pytest'), ('shell', 'bash'),
(
'run',
'nox -v -s tests_brevitas_examples_llm-${{ matrix.python_version }}\(${{ matrix.jit_status }}\,\ pytorch_${{ matrix.pytorch_version }}\)'
)]),]

FINN_INTEGRATION_STEP_LIST = [
od([('name', 'Install protobuf on Ubuntu'), ('shell', 'bash'),
('run', 'sudo apt-get install protobuf-compiler libprotoc-dev'),
Expand Down Expand Up @@ -167,6 +184,23 @@ def gen_examples_pytest_yml():
pytest.gen_yaml(BASE_YML_REDUCED_TEMPLATE, 'reduced_' + EXAMPLES_PYTEST_YML)


def gen_examples_llm_pytest_yml():
pytest = Action(
'Examples LLM Pytest',
EXCLUDE_LIST + JIT_EXCLUDE_LIST,
combine_od_list([EXAMPLES_LLM_PYTEST_MATRIX, PYTEST_MATRIX_EXTRA]),
EXAMPLES_LLM_PYTEST_STEP_LIST,
STRATEGY)
pytest.gen_yaml(BASE_YML_TEMPLATE, EXAMPLES_LLM_PYTEST_YML)
pytest = Action(
'Examples LLM Pytest',
EXCLUDE_LIST,
combine_od_list([EXAMPLES_LLM_PYTEST_MATRIX_REDUCED, PYTEST_MATRIX_EXTRA_REDUCED]),
EXAMPLES_LLM_PYTEST_STEP_LIST,
STRATEGY)
pytest.gen_yaml(BASE_YML_REDUCED_TEMPLATE, 'reduced_' + EXAMPLES_LLM_PYTEST_YML)


def gen_test_develop_install_yml():
test_develop_install = Action(
'Test develop install', EXCLUDE_LIST, MATRIX, TEST_INSTALL_DEV_STEP_LIST, STRATEGY)
Expand Down Expand Up @@ -243,6 +277,7 @@ def gen_test_brevitas_end_to_end():
if __name__ == '__main__':
gen_pytest_yml()
gen_examples_pytest_yml()
gen_examples_llm_pytest_yml()
gen_test_develop_install_yml()
gen_test_brevitas_finn_integration()
gen_test_brevitas_ort_integration()
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/reduced_examples_llm_pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Examples LLM Pytest

on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review


jobs:
build:
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false


matrix:
python_version: ['3.8']
pytorch_version: ['2.4.0']
platform: ['ubuntu-latest']
jit_status: ['jit_disabled']


exclude:
- pytorch_version: '1.9.1'
platform: 'macos-latest'



if: ${{ !github.event.pull_request.draft }}
steps:

- name: Checkout repo
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python_version }}

- name: Install Nox dependencies
shell: bash
run: pip install -r requirements/requirements-nox.txt

- name: Install update
shell: bash
run: sudo apt-get update
if: startsWith(runner.os, 'Linux') == true

- name: Install libsndfile and libgomp1 on Ubuntu
shell: bash
run: sudo apt-get install -y libsndfile-dev libgomp1
if: startsWith(runner.os, 'Linux') == true

- name: Install libomp on macOS
shell: bash
run: brew install libomp
if: startsWith(runner.os, 'macOS') == true

- name: Run Nox session for brevitas_examples pytest
shell: bash
run: nox -v -s tests_brevitas_examples_llm-${{ matrix.python_version }}\(${{ matrix.jit_status }}\,\ pytorch_${{ matrix.pytorch_version }}\)
55 changes: 46 additions & 9 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@

import nox
from packaging import version
from packaging.version import parse

sys.path.append(os.path.join(os.path.dirname(__file__), os.path.join('.', '.github', 'workflows')))
from gen_github_actions import EXAMPLES_LLM_PYTEST_PYTORCH_VERSIONS
from gen_github_actions import JIT_STATUSES
from gen_github_actions import PYTHON_VERSIONS
from gen_github_actions import PYTORCH_VERSIONS

IS_OSX = system() == 'Darwin'
PYTORCH_STABLE_WHEEL_SRC = 'https://download.pytorch.org/whl/torch_stable.html'
PYTORCH_STABLE_WHEEL_SRC = 'https://download.pytorch.org/whl/cpu'
PYTORCH_STABLE_WHEEL_SRC_LEGACY = 'https://download.pytorch.org/whl/torch_stable.html'
PYTORCH_IDS = tuple([f'pytorch_{i}' for i in PYTORCH_VERSIONS])
EXAMPLES_LLM_PYTEST_PYTORCH_IDS = tuple([
f'pytorch_{i}' for i in EXAMPLES_LLM_PYTEST_PYTORCH_VERSIONS])
JIT_IDS = tuple([f'{i}'.lower() for i in JIT_STATUSES])
LSTM_EXPORT_MIN_PYTORCH = '1.10.1'

Expand All @@ -26,14 +31,21 @@
'1.12.1': '0.13.1',
'1.13.0': '0.14.0',
'2.0.1': '0.15.2',
'2.1.0': '0.16.0'}
'2.1.0': '0.16.0',
'2.2.2': '0.17.2',
'2.3.1': '0.18.1',
'2.4.0': '0.19.0'}

PARSED_TORCHVISION_VERSION_DICT = {version.parse(k): v for k, v in TORCHVISION_VERSION_DICT.items()}


def install_pytorch(pytorch, session):
if not IS_OSX:
cmd = [f'torch=={pytorch}+cpu', '-f', PYTORCH_STABLE_WHEEL_SRC]
if parse(pytorch) < parse('2.4.0'):
cmd = [f'torch=={pytorch}+cpu', '-f', PYTORCH_STABLE_WHEEL_SRC_LEGACY]
else:
cmd = [f'torch=={pytorch}', '--index-url', PYTORCH_STABLE_WHEEL_SRC]

else:
cmd = [f'torch=={pytorch}']
session.install(*cmd)
Expand All @@ -42,11 +54,18 @@ def install_pytorch(pytorch, session):
def install_torchvision(pytorch, session):
torchvision = PARSED_TORCHVISION_VERSION_DICT[version.parse(pytorch)]
if not IS_OSX:
cmd = [
f'torch=={pytorch}+cpu', # make sure correct pytorch version is kept
f'torchvision=={torchvision}+cpu',
'-f',
PYTORCH_STABLE_WHEEL_SRC]
if parse(pytorch) < parse('2.4.0'):
cmd = [
f'torch=={pytorch}+cpu', # make sure correct pytorch version is kept
f'torchvision=={torchvision}+cpu',
'-f',
PYTORCH_STABLE_WHEEL_SRC_LEGACY]
else:
cmd = [
f'torch=={pytorch}',
f'torchvision=={torchvision}',
'--index-url',
PYTORCH_STABLE_WHEEL_SRC]
else:
cmd = [f'torch=={pytorch}', f'torchvision=={torchvision}']
session.install(*cmd)
Expand Down Expand Up @@ -105,7 +124,25 @@ def tests_brevitas_examples_cpu(session, pytorch, jit_status):
install_pytorch(pytorch, session)
install_torchvision(pytorch, session) # For CV eval scripts
session.install('--upgrade', '.[test, tts, stt, vision]')
session.run('pytest', '-n', 'logical', 'tests/brevitas_examples')
session.run(
'pytest',
'-n',
'logical',
'--ignore-glob',
nickfraser marked this conversation as resolved.
Show resolved Hide resolved
'tests/brevitas_examples/*llm*',
'tests/brevitas_examples')


@nox.session(python=PYTHON_VERSIONS)
@nox.parametrize(
"pytorch", EXAMPLES_LLM_PYTEST_PYTORCH_VERSIONS, ids=EXAMPLES_LLM_PYTEST_PYTORCH_IDS)
@nox.parametrize("jit_status", JIT_STATUSES, ids=JIT_IDS)
def tests_brevitas_examples_llm(session, pytorch, jit_status):
session.env['BREVITAS_JIT'] = '{}'.format(int(jit_status == 'jit_enabled'))
install_pytorch(pytorch, session)
install_torchvision(pytorch, session) # Optimum seems to require torchvision
session.install('-e', '.[test, llm, export]')
session.run('pytest', '-n', 'logical', '-k', 'llm', 'tests/brevitas_examples/test_llm.py')


@nox.session(python=PYTHON_VERSIONS)
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ log_cli_format = %(message)s

# pytest-mock should use Pypi's mock rather than Python's built-in
mock_use_standalone_module = true

markers =
llm: mark a test which tests brevitas_examples/llm
3 changes: 3 additions & 0 deletions requirements/requirements-llm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
optimum-amd[brevitas] @ git+https://github.com/huggingface/optimum-amd.git@main
tqdm
transformers
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def read_requirements(filename):
"test": read_requirements('requirements-test.txt'),
"tts": read_requirements('requirements-tts.txt'),
"stt": read_requirements('requirements-stt.txt'),
"llm": read_requirements('requirements-llm.txt'),
"vision": read_requirements('requirements-vision.txt'),
"finn_integration": read_requirements('requirements-finn-integration.txt'),
"ort_integration": read_requirements('requirements-ort-integration.txt')},
Expand Down
6 changes: 4 additions & 2 deletions src/brevitas_examples/common/generative/quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@
'sym': Int8DynamicActPerGroupFloat}}},
'po2_scale': {
'stats': {
'per_group': MXInt8Act}}}},
'per_group': {
'sym': MXInt8Act}}}}},
'float': {
'static': {
'float_scale': {
Expand All @@ -175,7 +176,8 @@
'dynamic': {
'po2_scale': {
'stats': {
'per_group': MXFloat8e4m3Act}}}},
'per_group': {
'sym': MXFloat8e4m3Act}}}}},
'float_fnuz': {
'static': {
'float_scale': {
Expand Down
Loading
Loading