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

When using sglang as the inference framework, if a word starting with "\n" appears in the stop parameter, the sglang will Missing '\n' during inference #3467

Open
nstl-zyb opened this issue Aug 6, 2024 · 3 comments

Comments

@nstl-zyb
Copy link

nstl-zyb commented Aug 6, 2024

LLM model: Qwen2-72B-lora-awq-4bit

python:3.10

sglang:0.2.7

@nstl-zyb nstl-zyb changed the title When using sglang as the inference framework, if a word starting with a line break appears in the stop parameter, the sglang will not wrap during inference When using sglang as the inference framework, if a word starting with "\n" appears in the stop parameter, the sglang will not wrap during inference Aug 6, 2024
@nstl-zyb
Copy link
Author

nstl-zyb commented Aug 6, 2024

EG:
prompt = 请换行输出1-10个数字
stop = ['<|endoftext|>', '<|im_end|>', '<|im_start|>']
1
2
3
4
5
6
7
8
9
10

prompt = 请换行输出1-10个数字
stop = ['\n<|endoftext|>', '<|im_end|>', '<|im_start|>']
12345678910

"\n" can be followed by any character, and there will be no line break.

@nstl-zyb nstl-zyb changed the title When using sglang as the inference framework, if a word starting with "\n" appears in the stop parameter, the sglang will not wrap during inference When using sglang as the inference framework, if a word starting with "\n" appears in the stop parameter, the sglang will Missing '\n' during inference Aug 7, 2024
@nstl-zyb
Copy link
Author

nstl-zyb commented Aug 7, 2024

After Test, its looks wrong in sglang_worker.py where check stop_str. But dont know how to fix.

    async for out, meta_info in state.text_async_iter(
        var_name="response", return_meta_data=True
    ):
        partial_stop = any(is_partial_stop(out, i) for i in stop)

        # prevent yielding partial stop sequence
        if partial_stop:
            continue

        entire_output += out
        prompt_tokens = meta_info["prompt_tokens"]
        completion_tokens = meta_info["completion_tokens"]

        ret = {
            "text": entire_output,
            "usage": {
                "prompt_tokens": prompt_tokens,
                "completion_tokens": completion_tokens,
                "total_tokens": prompt_tokens + completion_tokens,
            },
            "error_code": 0,
        }
        yield ret

@nstl-zyb
Copy link
Author

nstl-zyb commented Aug 8, 2024

This is the bug code when deal stop_str.

bug1
bug2
is_partila_stop

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

No branches or pull requests

1 participant