Skip to content

Commit

Permalink
initial commit (#2223)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbogunowicz authored Apr 6, 2024
1 parent 88196d5 commit 5aae81b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/sparseml/transformers/sparsification/modification/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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."
Expand Down
62 changes: 62 additions & 0 deletions tests/sparseml/transformers/test_recipe_compatibility.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 5aae81b

Please sign in to comment.