Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 691cb49

Browse files
[Export Refactor] Feature Branch (#1858)
* initial commit * respond to PR comments * [Export Refactor][Image Classification] `create_model` function (#1878) * initial commit * looking good, time to cleanup * Delete src/sparseml/export/helpers.py * Delete tests/sparseml/export/test_helpers.py * ready for review * improve design * tests pass * reuse _validate_dataset_num_classes * [Export Refactor][Image Classification] `create_dummy_input` function (#1880) * initial commit * looking good, time to cleanup * Delete src/sparseml/export/helpers.py * Delete tests/sparseml/export/test_helpers.py * ready for review * improve design * tests pass * reuse _validate_dataset_num_classes * initial commit * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * ready for review * Update src/sparseml/export/export.py * Update src/sparseml/integration_helper_functions.py * [Export Refactor][Image Classification] `export_model` function (#1883) * initial commit * looking good, time to cleanup * Delete src/sparseml/export/helpers.py * Delete tests/sparseml/export/test_helpers.py * ready for review * improve design * tests pass * reuse _validate_dataset_num_classes * initial commit * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * ready for review * Update src/sparseml/export/export.py * Update src/sparseml/integration_helper_functions.py * initial commit * fixes * ready for review * nit * add return * make export function more general * [Export Refactor][Image Classification] `apply_optimizations` function (#1884) * initial commit * looking good, time to cleanup * Delete src/sparseml/export/helpers.py * Delete tests/sparseml/export/test_helpers.py * ready for review * improve design * tests pass * reuse _validate_dataset_num_classes * initial commit * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * ready for review * Update src/sparseml/export/export.py * Update src/sparseml/integration_helper_functions.py * initial commit * fixes * ready for review * nit * add return * initial commit * [Export Refactor][Image Classification] `export_sample_inputs_outputs` function (#1888) * initial commit * looking good, time to cleanup * Delete src/sparseml/export/helpers.py * Delete tests/sparseml/export/test_helpers.py * ready for review * improve design * tests pass * reuse _validate_dataset_num_classes * initial commit * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * ready for review * Update src/sparseml/export/export.py * Update src/sparseml/integration_helper_functions.py * initial commit * fixes * ready for review * nit * add return * initial commit * initial commit * PR comments * beautification * remove duplicated function * [Export Refactor][Image Classification] `create_deployment_folder` function (#1889) * initial commit * looking good, time to cleanup * Delete src/sparseml/export/helpers.py * Delete tests/sparseml/export/test_helpers.py * ready for review * improve design * tests pass * reuse _validate_dataset_num_classes * initial commit * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * ready for review * Update src/sparseml/export/export.py * Update src/sparseml/integration_helper_functions.py * initial commit * fixes * ready for review * nit * add return * initial commit * initial commit * initial commit * fix rebase, tests_work * ready to push * [Export Refactor][Image Classification] `validate_correctness` function (#1890) * initial commit * looking good, time to cleanup * Delete src/sparseml/export/helpers.py * Delete tests/sparseml/export/test_helpers.py * ready for review * improve design * tests pass * reuse _validate_dataset_num_classes * initial commit * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * ready for review * Update src/sparseml/export/export.py * Update src/sparseml/integration_helper_functions.py * initial commit * fixes * ready for review * nit * add return * initial commit * initial commit * initial commit * initial commit * Delete tests/sparseml/test_integration_helper_functions.py * ready to merge * [Export Refactor] End to end testing (#1898) * initial commit * looking good, time to cleanup * Delete src/sparseml/export/helpers.py * Delete tests/sparseml/export/test_helpers.py * ready for review * improve design * tests pass * reuse _validate_dataset_num_classes * initial commit * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * ready for review * Update src/sparseml/export/export.py * Update src/sparseml/integration_helper_functions.py * initial commit * fixes * ready for review * nit * add return * initial commit * initial commit * initial commit * initial commit * Delete tests/sparseml/test_integration_helper_functions.py * ready to merge * add structure validator * ready for review * Delete tests/sparseml/export/model.onnx * Delete tests/sparseml/export/image_classification/model.onnx * Delete tests/sparseml/export/image_classification/conftest.py * PR comments * remove onnx * [Export Refactor] Prepare the module to be more general (before including `transformers`) (#1908) * adapt the export script to handle transformers * Update src/sparseml/pytorch/image_classification/integration_helper_functions.py * Delete tests/sparseml/export/transformers/__init__.py * Delete tests/sparseml/export/transformers/test_generative_transformers.py * Delete tests/sparseml/export/transformers/test_transformers.py * Update src/sparseml/export/export.py Co-authored-by: Benjamin Fineran <[email protected]> * addressing review comments * [Export Refactor] Export `transformers` (#1909) * cleanup * Delete src/sparseml/transformers/integration_helper_functions_generative.py * Delete src/sparseml/transformers/utils/optimizations.py * Delete tests/sparseml/export/transformers/test_generative_transformers.py * Delete tests/sparseml/transformers/test_integration_helper_functions_generative.py * addressing PR reviews * [Export Refactor] Export generative transformers(#1910) * make tests green, remove using task to resolve the integration type * fix all the tests after the merge, make integration resolution independent of the task name * fold generative transformers into transformer helper functions * complete tests for export_data.py * Update src/sparseml/export/export.py * add tests that confirms that kv cache injection has been added * move applying optimizations into integration helper functions --------- Co-authored-by: Benjamin Fineran <[email protected]> * [Export Refactor][Transformers] Enable loading SparseModels (#1921) * initial commit * adressing review comments * Fix the tests * fix tests with help from sara * [Export][Transformers] Enable loading `text-generation` datasets (#1938) * add suport for past_key_values in sample-outputs * [Export][Transformers] Implementation of correctness validation (#1935) * fix tests with help from sara * Update src/sparseml/transformers/utils/initializers.py * swap sparsezoo validator for custom one (top k match) * add more informative error message * add correctness validation for LLMs * remove past_key_values from outputs * remove past_key_values from outputs (2) * small note comment for the future * tests fixed * fix test * [Export refactor] final manual testing fixes (#1948) * [Export refactor] final manual testing fixes * review --------- Co-authored-by: Benjamin Fineran <[email protected]>
1 parent db9cbfc commit 691cb49

Some content is hidden

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

43 files changed

+3925
-291
lines changed

.github/workflows/test-check.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
deepsparse: ${{ steps.deepsparse-check.outputs.output }}
1919
onnx: ${{ steps.onnx-check.outputs.output }}
2020
pytorch: ${{ steps.pytorch-check.outputs.output }}
21+
export: ${{ steps.export-check.outputs.output }}
2122
transformers: ${{ steps.transformers-check.outputs.output }}
2223
steps:
2324
- uses: actions/checkout@v2
@@ -54,6 +55,10 @@ jobs:
5455
((git diff --name-only origin/main HEAD | grep -E "[src|tests]/sparseml/pytorch|setup.py|.github")
5556
|| (echo $GITHUB_REF | grep -E "refs/heads/[release/|main]"))
5657
&& echo "::set-output name=output::1" || echo "::set-output name=output::0"
58+
- name: "Checking if sparseml.export was changed"
59+
id: export-check
60+
run: >
61+
((git diff --name-only origin/main HEAD | grep -E "[src|tests]/sparseml/export|setup.py|.github")
5762
- name: "Checking if sparseml.transformers was changed"
5863
id: transformers-check
5964
run: >
@@ -228,3 +233,28 @@ jobs:
228233
run: pip3 install .[dev,torch,transformers]
229234
- name: "🔬 Running transformers tests"
230235
run: make test TARGETS=transformers
236+
export-tests:
237+
runs-on: ubuntu-22.04
238+
env:
239+
SPARSEZOO_TEST_MODE: "true"
240+
needs: test-setup
241+
if: ${{needs.test-setup.outputs.export == 1}}
242+
steps:
243+
- uses: actions/setup-python@v4
244+
with:
245+
python-version: '3.11'
246+
- uses: actions/checkout@v2
247+
- uses: actions/checkout@v2
248+
with:
249+
repository: "neuralmagic/sparsezoo"
250+
path: "sparsezoo"
251+
ref: ${{needs.test-setup.outputs.branch}}
252+
- name: "⚙️ Install sparsezoo dependencies"
253+
run: pip3 install -U pip && pip3 install setuptools sparsezoo/
254+
- name: "Clean sparsezoo directory"
255+
run: rm -r sparsezoo/
256+
- name: "⚙️ Install dependencies"
257+
run: pip3 install .[dev,torch,transformers,torchvision,onnxruntime]
258+
- name: "🔬 Running export tests"
259+
run: make test TARGETS=export
260+

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ MDCHECKFILES := CODE_OF_CONDUCT.md CONTRIBUTING.md DEVELOPING.md README.md
99
SPARSEZOO_TEST_MODE := "true"
1010

1111
BUILD_ARGS := # set nightly to build nightly release
12-
TARGETS := "" # targets for running pytests: deepsparse,keras,onnx,pytorch,pytorch_models,pytorch_datasets,tensorflow_v1,tensorflow_v1_models,tensorflow_v1_datasets
12+
TARGETS := "" # targets for running pytests: deepsparse,keras,onnx,pytorch,pytorch_models,export,pytorch_datasets,tensorflow_v1,tensorflow_v1_models,tensorflow_v1_datasets
1313
PYTEST_ARGS ?= ""
1414
PYTEST_INTEG_ARGS ?= ""
1515
ifneq ($(findstring deepsparse,$(TARGETS)),deepsparse)
@@ -18,6 +18,9 @@ endif
1818
ifneq ($(findstring transformers,$(TARGETS)),transformers)
1919
PYTEST_ARGS := $(PYTEST_ARGS) --ignore tests/sparseml/transformers
2020
endif
21+
ifneq ($(findstring export,$(TARGETS)),export)
22+
PYTEST_ARGS := $(PYTEST_ARGS) --ignore tests/sparseml/export
23+
endif
2124
ifneq ($(findstring keras,$(TARGETS)),keras)
2225
PYTEST_ARGS := $(PYTEST_ARGS) --ignore tests/sparseml/keras
2326
endif

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ def _setup_extras() -> Dict:
170170
def _setup_entry_points() -> Dict:
171171
entry_points = {
172172
"console_scripts": [
173+
# export
174+
"sparseml.export=sparseml.export.export:main",
173175
# sparsification
174176
"sparseml.framework=sparseml.framework.info:_main",
175177
"sparseml.sparsification=sparseml.sparsification.info:_main",

src/sparseml/core/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def pre_initialize_structure(
100100
This will run the pre-initialize structure method for each modifier in the
101101
session's lifecycle. This will also set the session's state to the
102102
pre-initialized state. Takes care of cases when the model(s) structure
103-
has been previosuly modified by a modifier.
103+
has been previously modified by a modifier.
104104
105105
:param model: the model to pre-initialize the structure for
106106
:param recipe: the recipe to use for the sparsification, can be a path to a

src/sparseml/export/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing,
10+
# software distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# flake8: noqa
16+
17+
from .export import *

0 commit comments

Comments
 (0)