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

[Inference] Optimize request handler of llama #5512

Merged
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
2 changes: 1 addition & 1 deletion colossalai/inference/core/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ def search_tokens(self, generation_config: GenerationConfig, logits):
"""
# do logit processor
# NOTE: need to decide the granularity to process logits (sequence or batch)
config_dict = generation_config.to_dict()
for type in ["top_k", "top_p", "min_p"]:
config_dict = generation_config.to_dict()
if type in config_dict and config_dict[type] is not None:
logits = logit_processor(type, logits, config_dict[type])

Expand Down
14 changes: 8 additions & 6 deletions colossalai/inference/logit_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@ def top_p_logit_processor(logits, top_p: float):
cumulative_probs = torch.cumsum(F.softmax(sorted_logits, dim=-1), dim=-1)

sorted_indices_to_remove = cumulative_probs > top_p
sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone()

sorted_indices_to_remove = torch.roll(sorted_indices_to_remove, 1, -1)
sorted_indices_to_remove[..., 0] = 0

indices_to_remove = sorted_indices_to_remove.scatter(dim=1, index=sorted_indices, src=sorted_indices_to_remove)
logits[indices_to_remove] = -float("inf")
return logits

def logit_processor(processor:str, logits , attrs):

def logit_processor(processor: str, logits, attrs):
"""
do logit process for given logits.

Args:
processor(str): the type of logit processor
processor(str): the type of logit processor
logits(torch.Tensor): input logits
attrs(dict): attrs of the logit processor
attrs(dict): attrs of the logit processor

Returns:
logits after process
Expand All @@ -61,6 +63,6 @@ def logit_processor(processor:str, logits , attrs):
func = _LOGIT_PROCESSOR_MAP[processor]
try:
logits = func(logits, attrs)
except Exception as e:
except Exception:
return logits
return logits
return logits
Loading