From 89b45ed6b4310e625576f5f666028658cd09b91b Mon Sep 17 00:00:00 2001 From: dbogunowicz Date: Fri, 5 Apr 2024 12:54:42 +0000 Subject: [PATCH] initial commit --- .../sparsification/modification/base.py | 4 +- .../transformers/test_recipe_compatibility.py | 62 +++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 tests/sparseml/transformers/test_recipe_compatibility.py diff --git a/src/sparseml/transformers/sparsification/modification/base.py b/src/sparseml/transformers/sparsification/modification/base.py index 6d9435b8b8b..72d9cc5954a 100644 --- a/src/sparseml/transformers/sparsification/modification/base.py +++ b/src/sparseml/transformers/sparsification/modification/base.py @@ -24,7 +24,7 @@ __all__ = ["check_transformers_version"] _TRANSFORMERS_MIN_VERSION = "4.39.0" -_TRANSFORMERS_MAX_VERSION = "4.39.2" +_TRANSFORMERS_MAX_VERSION = "4.39.3" def check_transformers_version( @@ -56,7 +56,7 @@ def check_transformers_version( _LOGGER.warning( "Attempting to modify the transformers model to support " "the SparseML-specific functionalities. However, the detected " - f"transformers version ({current_version}) does not fall within the" + f"transformers version ({current_version}) does not fall within the " f"supported version range ({min_version} - {max_version}). " "This may lead to unexpected behavior. Please ensure that the " "correct transformers version is installed." diff --git a/tests/sparseml/transformers/test_recipe_compatibility.py b/tests/sparseml/transformers/test_recipe_compatibility.py new file mode 100644 index 00000000000..6e4f13b812c --- /dev/null +++ b/tests/sparseml/transformers/test_recipe_compatibility.py @@ -0,0 +1,62 @@ +# Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import shutil + +import pytest + +import sparseml.core.session as session_manager +from huggingface_hub import snapshot_download +from sparseml.transformers import SparseAutoModelForCausalLM + + +@pytest.fixture +def model_path(tmp_path): + yield snapshot_download("stas/tiny-random-llama-2", local_dir=tmp_path) + shutil.rmtree(tmp_path) + + +@pytest.fixture +def recipe(): + return """test_stage: + obcq_modifiers: + QuantizationModifier: + ignore: + - LlamaRotaryEmbedding + - LlamaRMSNorm + - {silu_activation} + scheme_overrides: + Embedding: + input_activations: null + weights: + num_bits: 8 + symmetric: false""" + + +def test_silu_alias_same_output(recipe, model_path): + model_ = SparseAutoModelForCausalLM.from_pretrained( + model_path, recipe=recipe.format(silu_activation="SiLU") + ) + session_manager.create_session() + session_manager.active_session().reset() + model = SparseAutoModelForCausalLM.from_pretrained( + model_path, recipe=recipe.format(silu_activation="SiLUActivation") + ) + + dummy_input = model.dummy_inputs + + out = model(**dummy_input) + out_ = model_(**dummy_input) + + out.logits.allclose(out_.logits)