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

LLM: unify memory optimization env variables. #11549

Merged
merged 2 commits into from
Jul 11, 2024
Merged
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
8 changes: 5 additions & 3 deletions python/llm/src/ipex_llm/transformers/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,11 @@ def _replace_with_low_bit_linear(model, qtype, modules_to_not_convert=None,
optimize_lm_head = False
if is_lm_head(name, model_config, out_features):
model_type = getattr(model_config, "model_type", None)
if model_type in ["gptj", "llama", "qwen2"] and \
os.environ.get("IPEX_LLM_LAST_LM_HEAD", None) == "1":
optimize_lm_head = True
if model_type in ["gptj", "llama", "qwen2"]:
if os.environ.get("IPEX_LLM_LAST_LM_HEAD", None) is not None:
optimize_lm_head = os.environ.get("IPEX_LLM_LAST_LM_HEAD", None) == "1"
elif os.environ.get("IPEX_LLM_LOW_MEM", None) is not None:
optimize_lm_head = os.environ.get("IPEX_LLM_LOW_MEM", None) == "1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should disable optimize_lm_head when using speculative or lookahead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have conditions to avoid impacting speculative . But magic value 10 maybe not a good value. in

if shape[1] > 10:
shape[1] = 1
x = x[:, -1, :].view(shape)
return x

with init_empty_weights():
new_linear = None
is_gptq = is_gptq_linear(module)
Expand Down
2 changes: 2 additions & 0 deletions python/llm/src/ipex_llm/transformers/models/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ def should_split_qkv_tensor(query_states, bsz, num_heads, q_len, kv_seq_len, out
if not output_attentions:
if os.environ.get("IPEX_LLM_SPLIT_QKV", None) is not None:
return os.environ.get("IPEX_LLM_SPLIT_QKV", None) == "1"
elif os.environ.get("IPEX_LLM_LOW_MEM", None) is not None:
return os.environ.get("IPEX_LLM_LOW_MEM", None) == "1"
elif query_states.dtype == torch.float16 and \
query_states.shape[2] >= 6800:
# split tensor for memory block limitation
Expand Down
2 changes: 2 additions & 0 deletions python/llm/src/ipex_llm/transformers/models/mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def should_split_qkv_tensor(query_states, bsz, num_heads, q_len, kv_seq_len, out
if not output_attentions:
if os.environ.get("IPEX_LLM_SPLIT_QKV", None) is not None:
return os.environ.get("IPEX_LLM_SPLIT_QKV", None) == "1"
elif os.environ.get("IPEX_LLM_LOW_MEM", None) is not None:
return os.environ.get("IPEX_LLM_LOW_MEM", None) == "1"
elif query_states.dtype == torch.float16 and \
query_states.shape[2] >= 6300:
# split tensor for memory block limitation
Expand Down
Loading