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

[Bugfix] Fix spec decoding when seed is none in a batch #10863

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wallashss
Copy link
Contributor

@wallashss wallashss commented Dec 3, 2024

The issue was in the rejection_sampler in a custom _multinomial function. When a batch contains a seed as None, the calculation fails because the access with non-spec indices does not change in place. So, I changed to every request to be calculated the same way as seeded using ranges.

Concise script to repro the bug
from vllm import EngineArgs, LLMEngine
from vllm.sampling_params import SamplingParams
from vllm.platforms import current_platform

model='meta-llama/Llama-3.1-8B-Instruct'
speculative_model='ibm-fms/llama3-8b-accelerator'

current_platform.seed_everything(0)
engine_args = EngineArgs(model=model,
                            gpu_memory_utilization=0.95, 
                            use_v2_block_manager=True,
                            enforce_eager=True,
                            speculative_model=speculative_model, 
                            num_speculative_tokens=4
                            )
engine = LLMEngine.from_engine_args(engine_args)

prompts = [
    # Expected: "I will never miss any tokens."...
    # Wrong: "I!!!!!!!! will"...
    ('Write the following phrase exactly 20 times: I will never miss any tokens.\n1: I will never miss any tokens.\n2: ', 
     SamplingParams(temperature=0.1, stop=['20:'], seed=None, min_tokens=10, max_tokens=10, logprobs=1)),
    ('How to make pizza??? ', 
     SamplingParams(temperature=0.1, seed=1, logprobs=1)),
]
for i, (prompt, params) in enumerate(prompts):
    engine.add_request(
        f"request-id-{i}",
        prompt,
        params,
    )

while engine.has_unfinished_requests():
    res = engine.step()
    if not res:
        continue
    for r in res:
        if r.finished:
            print(r.outputs[0].text)


print('_______')
current_platform.seed_everything(0)
# Patch to all request be seed None
prompts[1][1].seed = None 
for i, (prompt, params) in enumerate(prompts):
    engine.add_request(
        f"request-id-{i+2}",
        prompt,
        params,
    )
    
while engine.has_unfinished_requests():
    res = engine.step()
    if not res:
        continue
    for r in res:
        if r.finished:
            print(r.outputs[0].text)

FIX #9441 (link existing issues this PR will resolve)

Copy link

github-actions bot commented Dec 3, 2024

👋 Hi! Thank you for contributing to the vLLM project.
Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

@DarkLight1337 DarkLight1337 requested a review from njhill December 3, 2024 14:53
@wallashss wallashss changed the title Fix spec decoding when seed is none in a batch [Bugfix] Fix spec decoding when seed is none in a batch Dec 3, 2024
@joerunde
Copy link
Contributor

joerunde commented Dec 6, 2024

Looks like a network timeout on the tests :(

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.

[Bug]: Speculative decoding generate gibberish when receiving parallel requests with different seeds
2 participants