Skip to content
Open
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
11 changes: 8 additions & 3 deletions modelopt/torch/sparsity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""API for sparsification algorithms."""
"""API for sparsification algorithms.
from . import mode, module, plugins
from .sparsification import *
This module provides access to both weight sparsity and attention sparsity algorithms.
For backward compatibility, weight sparsity APIs are re-exported at the module level.
"""

# Import weight sparsity for backward compatibility
from .weight_sparsity import mode, module, plugins
from .weight_sparsity.sparsification import *
23 changes: 23 additions & 0 deletions modelopt/torch/sparsity/weight_sparsity/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

"""API for weight sparsification algorithms."""

from . import mode, module, plugins

# Explicitly expose commonly used items
from .mode import SparsityModeRegistry
from .module import SparseModule, SpDMRegistry
from .sparsification import *
4 changes: 2 additions & 2 deletions tests/unit/torch/opt/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import pytest
import torch.nn as nn

from modelopt.torch.sparsity.config import SparseMagnitudeConfig
from modelopt.torch.sparsity.module import SparseModule, SpDMRegistry
from modelopt.torch.sparsity.weight_sparsity.config import SparseMagnitudeConfig
from modelopt.torch.sparsity.weight_sparsity.module import SparseModule, SpDMRegistry


def test_rule_based_config():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import modelopt.torch.opt as mto
import modelopt.torch.sparsity as mts
from modelopt.torch.opt.utils import is_dynamic
from modelopt.torch.sparsity.magnitude import MagnitudeSearcher
from modelopt.torch.sparsity.weight_sparsity.magnitude import MagnitudeSearcher
from modelopt.torch.utils.random import _set_deterministic_seed

try:
Expand Down