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

Limit position embeddings in inference #1598

Merged
merged 2 commits into from
Dec 12, 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
6 changes: 6 additions & 0 deletions examples/text-generation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ def setup_distributed_model(args, model_dtype, model_kwargs, logger):
if load_to_meta:
# Construct model with fake meta tensors, later will be replaced on devices during ds-inference ckpt load
with deepspeed.OnDevice(dtype=model_dtype, device="meta"):
if (
config.rope_scaling
and config.rope_scaling["rope_type"] == "llama3"
and config.max_position_embeddings > 8192
):
config.max_position_embeddings = 8192
model = AutoModelForCausalLM.from_config(config, torch_dtype=model_dtype)

# Model loaded to meta is managed differently
Expand Down
3 changes: 0 additions & 3 deletions optimum/habana/transformers/models/llama/modeling_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ def __init__(
else:
self.rope_type = "default"
self.max_seq_len_cached = config.max_position_embeddings
# Truncate the cached max sequence length to 8k to limit cached register buffer size
if not self.training and config.max_position_embeddings > 8192 and self.rope_type == "llama3":
self.max_seq_len_cached = 8192
self.original_max_seq_len = config.max_position_embeddings

self.config = config
Expand Down