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

[Feature] Add a function to convert sampling_params to kwargs #1170

Merged
merged 10 commits into from
Aug 21, 2024
14 changes: 14 additions & 0 deletions python/sglang/srt/sampling_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,17 @@ def normalize(self, tokenizer):
else:
stop_str_max_len = max(stop_str_max_len, len(stop_str))
self.stop_str_max_len = stop_str_max_len

def to_srt_kwargs(self):
gryffindor-rr marked this conversation as resolved.
Show resolved Hide resolved
return {
"max_new_tokens": self.max_new_tokens,
"stop": self.stop_strs,
Copy link
Member

Choose a reason for hiding this comment

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

Does stop_strs need to be processed as a list, in the case of multiple stop str scenarios?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stop is either str or list of str, both type can be handled by json.dumps. the token_ids is a set which need to be converted to list.

"stop_token_ids": list(self.stop_token_ids),
"temperature": self.temperature,
"top_p": self.top_p,
"top_k": self.top_k,
"frequency_penalty": self.frequency_penalty,
"presence_penalty": self.presence_penalty,
"ignore_eos": self.ignore_eos,
"regex": self.regex,
}
Loading