Skip to content

Commit

Permalink
Merge pull request #32 from heyselbi/rhoai-2-8-3
Browse files Browse the repository at this point in the history
added mlp and attn bias option to flash and paged llama models (opendatahub-io#85)
  • Loading branch information
openshift-merge-bot[bot] authored May 7, 2024
2 parents e5c6856 + 66a0790 commit 3853574
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
5 changes: 5 additions & 0 deletions server/text_generation_server/inference_engine/tgis_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def __init__(
model_class = FlashRWForCausalLM

elif model_type == "llama":
# See: https://github.com/ibm-granite/vllm_granite/blob/main/vllm/model_executor/models/llama.py#L353-L354
if self._config.tie_word_embeddings:
aliases = {
"lm_head.weight": ["model.embed_tokens.weight"]
}
if PAGED_ATTENTION:
from text_generation_server.models.custom_modeling.paged_llama_modeling import PagedLlamaForCausalLM
model_class = PagedLlamaForCausalLM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def __init__(
tie_word_embeddings=False,
rope_scaling=None,
rope_theta=10000.0,
attention_bias=False,
mlp_bias=False,
**kwargs,
):
self.vocab_size = vocab_size
Expand All @@ -85,6 +87,8 @@ def __init__(
self.use_cache = use_cache
self.rope_scaling = rope_scaling
self.rope_theta = rope_theta
self.attention_bias = attention_bias
self.mlp_bias = mlp_bias

super().__init__(
pad_token_id=pad_token_id,
Expand Down Expand Up @@ -169,7 +173,7 @@ def _load_gqa(config, prefix: str, weights):
config.hidden_size,
], f"{list(weight.shape)} != {[(num_heads + 2 * config.num_key_value_heads) * head_size, config.hidden_size]}"

return TensorParallelColumnLinear(get_linear(weight, bias=None, quantize=config.quantize))
return TensorParallelColumnLinear(get_linear(weight, bias=config.attention_bias, quantize=config.quantize))


class FlashLlamaAttention(torch.nn.Module):
Expand Down Expand Up @@ -220,13 +224,13 @@ def __init__(
prefixes=[f"{prefix}.q_proj", f"{prefix}.k_proj", f"{prefix}.v_proj"],
dim=0,
weights=weights,
bias=False,
bias=config.attention_bias,
)
self.o_proj = TensorParallelRowLinear.load(
config,
prefix=f"{prefix}.o_proj",
weights=weights,
bias=False,
bias=config.attention_bias,
)

def forward(
Expand Down Expand Up @@ -309,13 +313,13 @@ def __init__(self, prefix, config, weights):
prefixes=[f"{prefix}.gate_proj", f"{prefix}.up_proj"],
weights=weights,
dim=0,
bias=False,
bias=config.mlp_bias,
)
self.down_proj = TensorParallelRowLinear.load(
config,
prefix=f"{prefix}.down_proj",
weights=weights,
bias=False,
bias=config.mlp_bias,
)
self.intermediate_size = (
config.intermediate_size // weights.process_group.size()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def __init__(
tie_word_embeddings=False,
rope_scaling=None,
rope_theta=10000.0,
attention_bias=False,
mlp_bias=False,
**kwargs,
):
self.vocab_size = vocab_size
Expand All @@ -85,6 +87,8 @@ def __init__(
self.use_cache = use_cache
self.rope_scaling = rope_scaling
self.rope_theta = rope_theta
self.attention_bias = attention_bias
self.mlp_bias = mlp_bias

super().__init__(
pad_token_id=pad_token_id,
Expand Down Expand Up @@ -169,7 +173,7 @@ def _load_gqa(config, prefix: str, weights):
config.hidden_size,
], f"{list(weight.shape)} != {[(num_heads + 2 * config.num_key_value_heads) * head_size, config.hidden_size]}"

return TensorParallelColumnLinear(get_linear(weight, bias=None, quantize=config.quantize))
return TensorParallelColumnLinear(get_linear(weight, bias=config.attention_bias, quantize=config.quantize))


class PagedLlamaAttention(torch.nn.Module):
Expand Down Expand Up @@ -207,13 +211,13 @@ def __init__(
prefixes=[f"{prefix}.q_proj", f"{prefix}.k_proj", f"{prefix}.v_proj"],
dim=0,
weights=weights,
bias=False,
bias=config.attention_bias,
)
self.o_proj = TensorParallelRowLinear.load(
config,
prefix=f"{prefix}.o_proj",
weights=weights,
bias=False,
bias=config.attention_bias,
)

def forward(
Expand Down Expand Up @@ -280,13 +284,13 @@ def __init__(self, prefix, config, weights):
prefixes=[f"{prefix}.gate_proj", f"{prefix}.up_proj"],
weights=weights,
dim=0,
bias=False,
bias=config.mlp_bias,
)
self.down_proj = TensorParallelRowLinear.load(
config,
prefix=f"{prefix}.down_proj",
weights=weights,
bias=False,
bias=config.mlp_bias,
)
self.intermediate_size = (
config.intermediate_size // weights.process_group.size()
Expand Down

0 comments on commit 3853574

Please sign in to comment.