|
| 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 | +import shutil |
| 16 | + |
| 17 | +import pytest |
| 18 | + |
| 19 | +import sparseml.core.session as session_manager |
| 20 | +from huggingface_hub import snapshot_download |
| 21 | +from sparseml.transformers import SparseAutoModelForCausalLM |
| 22 | + |
| 23 | + |
| 24 | +@pytest.fixture |
| 25 | +def model_path(tmp_path): |
| 26 | + yield snapshot_download("stas/tiny-random-llama-2", local_dir=tmp_path) |
| 27 | + shutil.rmtree(tmp_path) |
| 28 | + |
| 29 | + |
| 30 | +@pytest.fixture |
| 31 | +def recipe(): |
| 32 | + return """test_stage: |
| 33 | + obcq_modifiers: |
| 34 | + QuantizationModifier: |
| 35 | + ignore: |
| 36 | + - LlamaRotaryEmbedding |
| 37 | + - LlamaRMSNorm |
| 38 | + - {silu_activation} |
| 39 | + scheme_overrides: |
| 40 | + Embedding: |
| 41 | + input_activations: null |
| 42 | + weights: |
| 43 | + num_bits: 8 |
| 44 | + symmetric: false""" |
| 45 | + |
| 46 | + |
| 47 | +def test_silu_alias_same_output(recipe, model_path): |
| 48 | + model_ = SparseAutoModelForCausalLM.from_pretrained( |
| 49 | + model_path, recipe=recipe.format(silu_activation="SiLU") |
| 50 | + ) |
| 51 | + session_manager.create_session() |
| 52 | + session_manager.active_session().reset() |
| 53 | + model = SparseAutoModelForCausalLM.from_pretrained( |
| 54 | + model_path, recipe=recipe.format(silu_activation="SiLUActivation") |
| 55 | + ) |
| 56 | + |
| 57 | + dummy_input = model.dummy_inputs |
| 58 | + |
| 59 | + out = model(**dummy_input) |
| 60 | + out_ = model_(**dummy_input) |
| 61 | + |
| 62 | + out.logits.allclose(out_.logits) |
0 commit comments