Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitnet #568

Draft
wants to merge 5 commits into
base: rc_054
Choose a base branch
from
Draft
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
24 changes: 23 additions & 1 deletion aphrodite/modeling/layers/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def adjust_marlin_shard(param, shard_size, shard_offset):
return shard_size * marlin_tile_size, shard_offset * marlin_tile_size


def adjust_bitblas_shard(param, shard_size, shard_offset):
bitblas_tile_size = getattr(param, "bitblas_tile_size", None)
weight_propagation = getattr(param, "weight_propagation", None)
if weight_propagation and bitblas_tile_size is not None:
return (shard_size // bitblas_tile_size,
shard_offset // bitblas_tile_size)

return shard_size, shard_offset


class LinearMethodBase(QuantizeMethodBase):
"""Base class for different (maybe quantized) linear methods."""

Expand Down Expand Up @@ -262,7 +272,10 @@ def weight_loader(self, param: Parameter, loaded_weight: torch.Tensor):
param_data, loaded_weight = fp8_scales_shard_indexer(param_data,
loaded_weight,
shard_id=0)
assert param_data.shape == loaded_weight.shape
assert param_data.dtype == loaded_weight.dtype, (
f"{param_data.dtype} != {loaded_weight.dtype}")
assert param_data.shape == loaded_weight.shape, (
f"{param_data.shape} != {loaded_weight.shape}")
param_data.copy_(loaded_weight)

def forward(self, input_):
Expand Down Expand Up @@ -382,6 +395,9 @@ def weight_loader(self,
shard_size, shard_offset = adjust_marlin_shard(
param, shard_size, shard_offset)

shard_size, shard_offset = adjust_bitblas_shard(
param, shard_size, shard_offset)

loaded_weight_shard = loaded_weight.narrow(
output_dim, shard_offset, shard_size)
self.weight_loader(param, loaded_weight_shard, shard_id)
Expand All @@ -404,6 +420,8 @@ def weight_loader(self,
# account for the tiling.
shard_size, shard_offset = adjust_marlin_shard(
param, shard_size, shard_offset)
shard_size, shard_offset = adjust_bitblas_shard(
param, shard_size, shard_offset)

param_data = param_data.narrow(output_dim, shard_offset,
shard_size)
Expand Down Expand Up @@ -565,6 +583,8 @@ def weight_loader(self,
# account for the tiling.
shard_size, shard_offset = adjust_marlin_shard(
param, shard_size, shard_offset)
shard_size, shard_offset = adjust_bitblas_shard(
param, shard_size, shard_offset)

loaded_weight_shard = loaded_weight.narrow(
output_dim, shard_offset, shard_size)
Expand Down Expand Up @@ -596,6 +616,8 @@ def weight_loader(self,
# account for the tiling.
shard_size, shard_offset = adjust_marlin_shard(
param, shard_size, shard_offset)
shard_size, shard_offset = adjust_bitblas_shard(
param, shard_size, shard_offset)

param_data = param_data.narrow(output_dim, shard_offset,
shard_size)
Expand Down
1 change: 1 addition & 0 deletions aphrodite/modeling/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"BaiChuanForCausalLM": ("baichuan", "BaiChuanForCausalLM"), # baichuan-7b
"BaichuanForCausalLM": ("baichuan", "BaichuanForCausalLM"), # baichuan-13b
"BloomForCausalLM": ("bloom", "BloomForCausalLM"),
"BitnetForCausalLM": ("bitnet", "BitnetForCausalLM"),
"ChatGLMModel": ("chatglm", "ChatGLMForCausalLM"),
"ChatGLMForConditionalGeneration": ("chatglm", "ChatGLMForCausalLM"),
"CohereForCausalLM": ("commandr", "CohereForCausalLM"),
Expand Down
Loading