This repository was archived by the owner on Oct 11, 2024. It is now read-only.
forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 10
Sparse fused gemm integration #12
Merged
LucasWilkinson
merged 23 commits into
main
from
lwilkinson/sparse-fused-gemm-integration
Feb 14, 2024
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b8810c7
.gitignore magic_wand dir
afeldman-nm d56b4c4
added 2:4 example (not actually using 2:4 yet\!)
afeldman-nm 1a8bc1c
use only cuda:0
afeldman-nm 2c6ff26
wip semi_structured_sparse_w16a16
afeldman-nm 2856b91
restructuring sparsity
afeldman-nm 708fe1b
difficulty creating sparse parameter class
afeldman-nm 40a8afb
first successful run with 2:4 sparse model; compat with magic_wand br…
afeldman-nm 017a296
Merge branch 'main' into semi_structured
afeldman-nm a344b60
woops uncommenting assert statement
afeldman-nm 7a2a7ed
fixes
afeldman-nm 0711a74
bfloat16
afeldman-nm fc85cac
hopefully removed magic_wand submodule
afeldman-nm d7b2f41
wip bench
afeldman-nm ef64711
initial integration
LucasWilkinson 202e655
disable the semi-sparse stuff temporarily
LucasWilkinson 7f67d62
Merge branch 'main' into lwilkinson/sparse-fused-gemm-integration
LucasWilkinson 131a0a5
format fix
LucasWilkinson 5c6a55e
remove sparse benchmark
LucasWilkinson ae57f2c
small format fix
LucasWilkinson fb95394
remove useless comments
LucasWilkinson b5ffb39
cleanup spacing
LucasWilkinson 9b69f56
revert
LucasWilkinson 1fbc82f
missed pack
LucasWilkinson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
import torch | ||
from vllm.model_executor.layers.parameters.sparsity import SparseParameter | ||
from vllm.model_executor.layers.parameters.lazy_compressed import LazyCompressedParameter | ||
|
||
|
||
def get_param_data(param: torch.nn.Parameter) -> torch.Tensor: | ||
"""Gets parameter data in dense format.""" | ||
if isinstance(param, SparseParameter): | ||
return param.get_dense_data() | ||
else: | ||
return param.data | ||
__all__ = [ | ||
"LazyCompressedParameter", | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import numpy | ||
import torch | ||
from torch.utils._pytree import tree_map | ||
|
||
from typing import Type | ||
from magic_wand import (CompressedStorageFormat, SparseBitmaskStorageFormat) | ||
|
||
|
||
class LazyCompressedParameter(torch.Tensor): | ||
|
||
@staticmethod | ||
def __new__(cls, | ||
uncompressed_data: torch.Tensor, | ||
storage_format_cls: Type[ | ||
CompressedStorageFormat] = SparseBitmaskStorageFormat, | ||
compress_transposed: bool = False): | ||
self = torch.Tensor._make_wrapper_subclass( | ||
cls, | ||
size=uncompressed_data.shape, | ||
dtype=uncompressed_data.dtype, | ||
requires_grad=False) | ||
self.storage_format_cls = storage_format_cls | ||
self.compressed_data = None | ||
self.uncompressed_data = uncompressed_data | ||
self.compress_transposed = compress_transposed | ||
self._is_param = True | ||
|
||
return self | ||
|
||
@property | ||
def has_compressed_data(self) -> bool: | ||
return (self.compressed_data is not None) | ||
|
||
@property | ||
def has_uncompressed_data(self) -> bool: | ||
return (self.uncompressed_data is not None) | ||
|
||
@classmethod | ||
def __torch_dispatch__(cls, func, types, args, kwargs): | ||
ret_storage_format_cls = None | ||
|
||
def unwrap(e): | ||
nonlocal ret_storage_format_cls | ||
if isinstance(e, LazyCompressedParameter): | ||
assert ret_storage_format_cls is None or ret_storage_format_cls == e.storage_format_cls | ||
ret_storage_format_cls = e.storage_format_cls | ||
return e.uncompressed_data if isinstance( | ||
e, LazyCompressedParameter) else e | ||
|
||
rs = func(*tree_map(unwrap, args), **tree_map(unwrap, kwargs)) | ||
|
||
def wrap(e): | ||
if isinstance(e, | ||
torch.Tensor) and ret_storage_format_cls is not None: | ||
return LazyCompressedParameter( | ||
e, storage_format_cls=ret_storage_format_cls) | ||
return e | ||
|
||
rs = tree_map(wrap, rs) | ||
return rs | ||
|
||
def compress(self) -> None: | ||
density = torch.count_nonzero( | ||
self.uncompressed_data).item() / numpy.prod(self.shape) | ||
|
||
# only compress if we have sufficient sparsity (>=45%), currently | ||
# this applies globally across all formats including 2:4 | ||
if (1 - density) < 0.45: | ||
return | ||
|
||
if self.uncompressed_data is None: | ||
raise ValueError( | ||
"Called compress() but uncompressed_data does not exist.") | ||
self.compressed_data = self.storage_format_cls.compress( | ||
self.uncompressed_data.t( | ||
) if self.compress_transposed else self.uncompressed_data) | ||
del self.uncompressed_data # free memory | ||
self.uncompressed_data = None |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.