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

Fix runtime.generate when sampling param is not passed #1582

Merged
merged 4 commits into from
Oct 6, 2024

Conversation

ByronHsu
Copy link
Collaborator

@ByronHsu ByronHsu commented Oct 5, 2024

Motivation

import sglang as sgl

model_path = "/shared/public/models/Qwen/Qwen2.5-1.5B-Instruct/"

if __name__ == "__main__":
    runtime = sgl.Runtime(model_path=model_path)

    print(runtime.generate("Who is Steve Jobs?"))
    runtime.shutdown()

The above code fails with

  File "/home/jobuser/sglang/python/sglang/srt/server.py", line 184, in generate_request
    ret = await tokenizer_manager.generate_request(obj, request).__anext__()
  File "/home/jobuser/sglang/python/sglang/srt/managers/tokenizer_manager.py", line 152, in generate_request
    obj.post_init()
  File "/home/jobuser/sglang/python/sglang/srt/managers/io_struct.py", line 83, in post_init
    self.parallel_sample_num = self.sampling_params[0].get("n", 1)

This is because sampling_params == None falls under to

else: # isinstance(self.sampling_params, list):

Modifications

Change line80 to elif

Test

After the fix, the above example can produce

{"text": " Steve Jobs is a renowned American entrepreneur, co-founder, president and CEO of Apple Inc., and a key force behind its growth and success. He has a significant impact on both the business world and popular culture. In addition to co-founding Apple Inc., Jobs was also the chairman and CEO of Pixar Animation Studios, was a cofounder of NeXT, and co-founder of the technology company Adobe. He is also regarded as one of the most influential figures in the technology industry of his time. More significantly, Jobs was a pioneer visionary in the technology industry, and a driving force behind the digital revolution. His contributions to the creation and development", "meta_info": {"prompt_tokens": 5, "completion_tokens": 128, "completion_tokens_wo_jump_forward": 128, "finish_reason": {"type": "length", "length": 128}, "id": "14fe8aff836d427aba0a262fcf25c721"}, "index": 0}

Checklist

  • Format your code according to the Contributor Guide.
  • Add unit tests as outlined in the Contributor Guide.
  • Update documentation as needed, including docstrings or example tutorials.

@ByronHsu ByronHsu changed the title Fix runtime.generate when sampling param is not passed [WIP] Fix runtime.generate when sampling param is not passed Oct 5, 2024
@ByronHsu ByronHsu changed the title [WIP] Fix runtime.generate when sampling param is not passed Fix runtime.generate when sampling param is not passed Oct 6, 2024
@Ying1123 Ying1123 enabled auto-merge (squash) October 6, 2024 00:33
@merrymercy merrymercy disabled auto-merge October 6, 2024 00:59
@merrymercy merrymercy merged commit 521f862 into sgl-project:main Oct 6, 2024
7 of 10 checks passed
@ByronHsu ByronHsu deleted the byhsu/runtime-no-sp-fail branch October 6, 2024 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants