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

feat: remove hidden_dim == head_dim * num_heads constraint #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def __init__(self, config: InferenceConfig, tensor_model_parallel_group=None):
self.hidden_size = config.hidden_size
self.num_attention_heads = config.num_attention_heads
self.num_key_value_heads = config.num_key_value_heads
self.head_dim = self.hidden_size // self.num_attention_heads
self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
self.max_position_embeddings = config.max_position_embeddings
self.rope_theta = config.rope_theta
self.padding_side = config.neuron_config.padding_side
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ def __init__(self, tensor_model_parallel_group: Optional[ProcessGroup] = None):
self.o_proj_layer_name = "o_proj"

def init_gqa_properties(self):
if (self.head_dim * self.num_attention_heads) != self.hidden_size:
raise ValueError(
f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
f" and `num_heads`: {self.num_attention_heads})."
)

self.qkv_proj = GroupQueryAttention_QKV(
hidden_size=self.hidden_size,
head_dim=self.head_dim,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def _get_num_kv_heads_per_rank(self, config: InferenceConfig):
return num_kv_heads_per_rank

def _get_hidden_dim_per_head(self, config: InferenceConfig):
if hasattr(config, "head_dim"):
return config.head_dim

hidden_size = config.hidden_size
num_atten_head = config.num_attention_heads
hidden_dim_per_head = hidden_size // num_atten_head
Expand Down