|
| 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 pytest |
| 16 | +from compressed_tensors.config import SparsityStructure |
| 17 | + |
| 18 | + |
| 19 | +def test_sparsity_structure_valid_cases(): |
| 20 | + assert ( |
| 21 | + SparsityStructure("2:4") == SparsityStructure.TWO_FOUR |
| 22 | + ), "Failed to match '2:4' with TWO_FOUR" |
| 23 | + assert ( |
| 24 | + SparsityStructure("unstructured") == SparsityStructure.UNSTRUCTURED |
| 25 | + ), "Failed to match 'unstructured' with UNSTRUCTURED" |
| 26 | + assert ( |
| 27 | + SparsityStructure("UNSTRUCTURED") == SparsityStructure.UNSTRUCTURED |
| 28 | + ), "Failed to match 'UNSTRUCTURED' with UNSTRUCTURED" |
| 29 | + assert ( |
| 30 | + SparsityStructure(None) == SparsityStructure.UNSTRUCTURED |
| 31 | + ), "Failed to match None with UNSTRUCTURED" |
| 32 | + |
| 33 | + |
| 34 | +def test_sparsity_structure_invalid_case(): |
| 35 | + with pytest.raises(ValueError, match="invalid is not a valid SparsityStructure"): |
| 36 | + SparsityStructure("invalid") |
| 37 | + |
| 38 | + |
| 39 | +def test_sparsity_structure_case_insensitivity(): |
| 40 | + assert ( |
| 41 | + SparsityStructure("2:4") == SparsityStructure.TWO_FOUR |
| 42 | + ), "Failed to match '2:4' with TWO_FOUR" |
| 43 | + assert ( |
| 44 | + SparsityStructure("2:4".upper()) == SparsityStructure.TWO_FOUR |
| 45 | + ), "Failed to match '2:4'.upper() with TWO_FOUR" |
| 46 | + assert ( |
| 47 | + SparsityStructure("unstructured".upper()) == SparsityStructure.UNSTRUCTURED |
| 48 | + ), "Failed to match 'unstructured'.upper() with UNSTRUCTURED" |
| 49 | + assert ( |
| 50 | + SparsityStructure("UNSTRUCTURED".lower()) == SparsityStructure.UNSTRUCTURED |
| 51 | + ), "Failed to match 'UNSTRUCTURED'.lower() with UNSTRUCTURED" |
| 52 | + |
| 53 | + |
| 54 | +def test_sparsity_structure_default_case(): |
| 55 | + assert ( |
| 56 | + SparsityStructure(None) == SparsityStructure.UNSTRUCTURED |
| 57 | + ), "Failed to match None with UNSTRUCTURED" |
0 commit comments