-
Notifications
You must be signed in to change notification settings - Fork 57
[WIP- FINAL][AQUA][GPU Shape Recommendation] Support for Service Managed Models #1252 #1267
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
Merged
+2,168
−224
Merged
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -46,18 +46,18 @@ def kv_cache_memory(self) -> float: | |
Uses num_attention_heads (assumes no GQA, each attention head has its own query, key, value) for estimation. | ||
""" | ||
seq_len = self.seq_len or self.llm_config.max_seq_len | ||
c = self.llm_config | ||
llm_config = self.llm_config | ||
kv_cache_dtype_bytes = QUANT_MAPPING.get( | ||
c.weight_dtype, 2 | ||
llm_config.weight_dtype, 2 | ||
) # vLLM uses model's weight applied to KV cache | ||
|
||
total_bytes = ( | ||
self.batch_size | ||
* c.num_hidden_layers | ||
* llm_config.num_hidden_layers | ||
* 2 | ||
* c.num_attention_heads | ||
* llm_config.num_attention_heads | ||
* seq_len | ||
* c.head_dim | ||
* llm_config.head_dim | ||
* kv_cache_dtype_bytes | ||
) | ||
return total_bytes / 1e9 | ||
|
@@ -69,15 +69,17 @@ def model_memory(self) -> float: | |
|
||
Model Parameter estimation: Standard decoder-only, untied/tied embeddings possible. | ||
""" | ||
c = self.llm_config | ||
embedding_count = 1 if getattr(c, "tie_word_embeddings", True) else 2 | ||
llm_config = self.llm_config | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we could just do self.llm_config below instead of declaring a new var, just personal preference. We can keep it as is for now. |
||
embedding_count = 1 if llm_config.tie_word_embeddings else 2 | ||
embedding_params = ( | ||
embedding_count * c.vocab_size * c.hidden_size | ||
embedding_count * llm_config.vocab_size * llm_config.hidden_size | ||
) # input and output untied | ||
layer_params = 12 * c.num_hidden_layers * (c.hidden_size**2) # GPT-style | ||
layer_params = ( | ||
12 * llm_config.num_hidden_layers * (llm_config.hidden_size**2) | ||
) # GPT-style | ||
num_params = layer_params + embedding_params | ||
|
||
return num_params * c.bytes_per_parameter / 1e9 | ||
return num_params * llm_config.bytes_per_parameter / 1e9 | ||
|
||
@property | ||
def total_memory(self) -> float: | ||
|
@@ -120,17 +122,24 @@ def construct_deployment_params(self) -> str: | |
------- | ||
str: Parameter string for model deployment. | ||
""" | ||
c = self.llm_config | ||
llm_config = self.llm_config | ||
params = [] | ||
if self.seq_len < c.max_seq_len: | ||
if self.seq_len < llm_config.max_seq_len: | ||
params.append(VLLM_PARAMS["max_model_len"]) | ||
params.append(str(self.seq_len)) | ||
|
||
# Only suggest in-flight quantization for unquantized models when such quantization is requested | ||
if not c.quantization and c.in_flight_quantization in IN_FLIGHT_QUANTIZATION: | ||
if ( | ||
not llm_config.quantization | ||
and llm_config.in_flight_quantization in IN_FLIGHT_QUANTIZATION | ||
): | ||
# vLLM only supports 4bit in-flight quantization | ||
params.append(VLLM_PARAMS["in_flight_quant"]) | ||
|
||
# add trust-remote-code if custom modules are specified | ||
if llm_config.trust_remote_code: | ||
params.append(VLLM_PARAMS["trust_remote_code"]) | ||
|
||
params = " ".join(params) if params else "" | ||
return params | ||
|
||
|
@@ -154,12 +163,12 @@ def suggest_param_advice(self, allowed: float) -> str: | |
wt_gb = self.model_memory | ||
batch_size = self.batch_size | ||
seq_len = self.seq_len | ||
weight_size = getattr(self.llm_config, "weight_dtype", "unknown") | ||
weight_size = self.llm_config.weight_dtype | ||
config = self.llm_config | ||
|
||
suggested_quant_msg = None | ||
quant_advice = ", ".join(config.suggested_quantizations) | ||
quantization = getattr(config, "quantization", None) | ||
quantization = config.quantization | ||
|
||
advice = [] | ||
|
||
|
@@ -246,7 +255,7 @@ def limiting_factor( | |
) | ||
else: | ||
advice = ( | ||
f"No override PARAMS needed. \n\nModel fits well within the allowed compute shape " | ||
f"Model fits well within the allowed compute shape " | ||
f"({required:.1f}GB used / {allowed_gpu_memory:.1f}GB allowed)." | ||
) | ||
return advice | ||
|
@@ -268,22 +277,22 @@ def model_memory(self) -> float: | |
Returns estimated model parameter memory (in GB), accurately accounting | ||
for Llama-style attention and MLP, and tied or untied embeddings. | ||
""" | ||
c = self.llm_config | ||
llm_config = self.llm_config | ||
|
||
embedding_params, attn_params = self._calc_attn_embed_params() | ||
|
||
# MLP params | ||
gate_proj = c.hidden_size * c.intermediate_size | ||
up_proj = c.hidden_size * c.intermediate_size | ||
down_proj = c.intermediate_size * c.hidden_size | ||
gate_proj = llm_config.hidden_size * llm_config.intermediate_size | ||
up_proj = llm_config.hidden_size * llm_config.intermediate_size | ||
down_proj = llm_config.intermediate_size * llm_config.hidden_size | ||
mlp_params = gate_proj + up_proj + down_proj | ||
|
||
# Total per-layer | ||
layer_params = attn_params + mlp_params | ||
# Total params | ||
num_params = c.num_hidden_layers * layer_params + embedding_params | ||
num_params = llm_config.num_hidden_layers * layer_params + embedding_params | ||
|
||
return num_params * c.bytes_per_parameter / 1e9 | ||
return num_params * llm_config.bytes_per_parameter / 1e9 | ||
|
||
@property | ||
def kv_cache_memory(self) -> float: | ||
|
@@ -293,18 +302,18 @@ def kv_cache_memory(self) -> float: | |
Grouped Query Attention uses num_key_value_heads, which groups of Q heads share a K and V projection. | ||
num_key_value_heads < num_attention_heads, which reduces the KV Cache size. | ||
""" | ||
c = self.llm_config | ||
seq_len = self.seq_len or getattr(c, "max_seq_len", 2048) | ||
kv_cache_dtype_bytes = QUANT_MAPPING.get(c.weight_dtype, 2) | ||
kv_heads = c.num_key_value_heads | ||
llm_config = self.llm_config | ||
seq_len = self.seq_len or llm_config.max_seq_len | ||
kv_cache_dtype_bytes = QUANT_MAPPING.get(llm_config.weight_dtype, 2) | ||
kv_heads = llm_config.num_key_value_heads | ||
|
||
total_bytes = ( | ||
self.batch_size | ||
* c.num_hidden_layers | ||
* llm_config.num_hidden_layers | ||
* 2 | ||
* kv_heads | ||
* seq_len | ||
* c.head_dim | ||
* llm_config.head_dim | ||
* kv_cache_dtype_bytes | ||
) | ||
return total_bytes / 1e9 | ||
|
@@ -313,17 +322,23 @@ def _calc_attn_embed_params(self) -> tuple: | |
""" | ||
Returns the embedding parameter count and attention parameter count for Llama-family (GQA) models. | ||
""" | ||
c = self.llm_config | ||
llm_config = self.llm_config | ||
|
||
# Embedding parameters | ||
# assume tied embeddings unless tie_word_embeddings = False | ||
embedding_count = 1 if getattr(c, "tie_word_embeddings", True) else 2 | ||
embedding_params = embedding_count * c.vocab_size * c.hidden_size | ||
embedding_count = 1 if llm_config.tie_word_embeddings else 2 | ||
embedding_params = ( | ||
embedding_count * llm_config.vocab_size * llm_config.hidden_size | ||
) | ||
|
||
q_proj = c.hidden_size * c.hidden_size | ||
k_proj = c.hidden_size * (c.num_key_value_heads * c.head_dim) | ||
v_proj = c.hidden_size * (c.num_key_value_heads * c.head_dim) | ||
o_proj = c.hidden_size * c.hidden_size | ||
q_proj = llm_config.hidden_size * llm_config.hidden_size | ||
k_proj = llm_config.hidden_size * ( | ||
llm_config.num_key_value_heads * llm_config.head_dim | ||
) | ||
v_proj = llm_config.hidden_size * ( | ||
llm_config.num_key_value_heads * llm_config.head_dim | ||
) | ||
o_proj = llm_config.hidden_size * llm_config.hidden_size | ||
attn_params = q_proj + k_proj + v_proj + o_proj | ||
|
||
return embedding_params, attn_params | ||
|
@@ -342,21 +357,24 @@ def model_memory(self) -> float: | |
|
||
Returns the estimated memory size of the MoE Model (in GB). | ||
""" | ||
c = self.llm_config | ||
llm_config = self.llm_config | ||
# Attention parameter count (Llama-style) | ||
embedding_params, attn_params = self._calc_attn_embed_params() | ||
|
||
# MoE MLP params per layer | ||
moe_params_per_layer = ( | ||
c.num_local_experts * 3 * c.hidden_size * c.intermediate_size | ||
llm_config.num_local_experts | ||
* 3 | ||
* llm_config.hidden_size | ||
* llm_config.intermediate_size | ||
) | ||
total_params = ( | ||
c.num_hidden_layers * (attn_params + moe_params_per_layer) | ||
llm_config.num_hidden_layers * (attn_params + moe_params_per_layer) | ||
+ embedding_params | ||
) | ||
|
||
# Convert to GB | ||
return total_params * c.bytes_per_parameter / 1e9 | ||
return total_params * llm_config.bytes_per_parameter / 1e9 | ||
|
||
|
||
def get_estimator(llm_config, **kwargs) -> MemoryEstimator: | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add a validation here to check if kwargs has model id before passing to get_deployment_config.