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 to make sure SiLU and SiLUActivation are aliases #2223

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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"
mgoin marked this conversation as resolved.
Show resolved Hide resolved


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()
mgoin marked this conversation as resolved.
Show resolved Hide resolved
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)
Loading