Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoin committed Aug 1, 2024
1 parent 614a38b commit 031042b
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions vllm/model_executor/layers/quantization/sparsity_24.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,19 @@
from torch.nn import Module
from torch.nn.parameter import Parameter

from vllm import _custom_ops as ops
from vllm.logger import init_logger
from vllm.model_executor.layers.linear import (LinearBase, LinearMethodBase,
UnquantizedLinearMethod)
from vllm.model_executor.layers.linear import LinearBase, LinearMethodBase
from vllm.model_executor.layers.quantization.base_config import (
QuantizationConfig, QuantizeMethodBase)
from vllm.model_executor.utils import set_weight_attrs
from vllm.platforms import current_platform
from vllm.utils import print_warning_once

ACTIVATION_SCHEMES = ["static", "dynamic"]

logger = init_logger(__name__)


class Sparsity24Config(QuantizationConfig):
"""Config class for 2:4 sparsity."""

def __init__(
self,
) -> None:
def __init__(self) -> None:
return

@classmethod
Expand Down Expand Up @@ -97,16 +89,16 @@ def create_weights(
"output_dim": 0,
})


def process_weights_after_loading(self, layer: Module) -> None:
from torch.sparse import to_sparse_semi_structured, SparseSemiStructuredTensor
from torch.sparse import to_sparse_semi_structured

layer.weight = torch.nn.Parameter(to_sparse_semi_structured(layer.weight), requires_grad=False)
layer.weight = torch.nn.Parameter(to_sparse_semi_structured(
layer.weight),
requires_grad=False)

def apply(self,
layer: torch.nn.Module,
x: torch.Tensor,
bias: Optional[torch.Tensor] = None) -> torch.Tensor:

return torch.nn.functional.linear(x, layer.weight, bias=bias)

0 comments on commit 031042b

Please sign in to comment.