verl icon indicating copy to clipboard operation
verl copied to clipboard

vLLM 0.8 generate token id out of vocabulary with Qwen2.5-7B

Open Skevinci opened this issue 1 year ago • 8 comments

Hi,

After installing vllm0.8.3 and the latest version of verl, it always reports error that vLLM generate token id that is out of vocabulary. I'm using Qwen2.5-7B model, and I've seen an issue in vLLM Qwen/Qwen2.5-1.5B-Instruct generates out of vocabulary tokens that shows roughly the same error.

Therefore, I'm wondering is there any method to solve this problem? I've tried the methods mentioned in the vllm issue but nothing helps. Moreover, since the problem exists with vllm0.8.3 but not vllm 0.6.3 (I was using vllm 0.6.3 before), if it's hard to figure out a solution, I'm also curious about how to use vllm 0.6.3 with the latest version of verl? There is no installation description for it and I found out that the torch vision always conflicts between vllm 0.6.3 and the latest version of verl. Since I need the "resume from checkpoint" function from the latest verl repo, I can't downgrade verl back to verl 0.1.

Thank you.

Skevinci avatar May 05 '25 03:05 Skevinci

try to use VLLM_USE_V1=0(in ray environments, or export it before ray start in every nodes) and

# make sure that you have started ray cluster with this yaml, else it will not work automatically
working_dir: ./
excludes: ["/.git/"]
pip:
  - math_verify
  - accelerate
env_vars:
  TORCH_NCCL_AVOID_RECORD_STREAMS: "1"
  VLLM_USE_V1: "0"
# verl/workers/rollout/vllm_rollout/vllm_rollout_spmd.py
		### ADD
        if model_hf_config.vocab_size > tokenizer.vocab_size:
            print(f"use fix_oov_logits_processor, {model_hf_config.vocab_size=} is out of {tokenizer.vocab_size=}")
            def fix_oov(token_ids, logits):
                logits[tokenizer.vocab_size:] = -float("inf")
                return logits
            kwargs['logits_processors'] = [fix_oov]
		###
        self.sampling_params = SamplingParams(**kwargs)

Hopes that vllm community can offer a better solution for V1 Engine, I even doubt that V0 Engine will neven meet OOV problem even without logits_processor......

huiyeruzhou avatar May 07 '25 07:05 huiyeruzhou

Update: simple use VLLM_USE_V1=0 can solve this problem. This is exactly a bug in V1 Engine. I try to set OOV logits to +inf and V0 Engine will just sample token 0 (an "!" for Qwen model)

huiyeruzhou avatar May 07 '25 07:05 huiyeruzhou

You may also want to know about another workaround, use allowed_token_ids, here is an adaptive workaround for both V0 and V1. (no need to modify any environment variable or disabling V1 Engine)

        # fix OOV: https://github.com/vllm-project/vllm/issues/13175
        from vllm import envs
        if envs.VLLM_USE_V1:
            # I have no better idea.
            kwargs['allowed_token_ids'] = list(range(tokenizer.vocab_size))

huiyeruzhou avatar May 07 '25 07:05 huiyeruzhou

Thanks!

Skevinci avatar May 08 '25 20:05 Skevinci

You may also want to know about another workaround, use allowed_token_ids, here is an adaptive workaround for both V0 and V1. (no need to modify any environment variable or disabling V1 Engine)

    # fix OOV: https://github.com/vllm-project/vllm/issues/13175
    from vllm import envs
    if envs.VLLM_USE_V1:
        # I have no better idea.
        kwargs['allowed_token_ids'] = list(range(tokenizer.vocab_size))

I tried this solution, and it does work, but it significantly slows down the rollout process. For those who want to fix the issue without noticeably increasing the rollout time, I’d recommend trying the method mentioned above instead.

bingshuailiu avatar Aug 14 '25 07:08 bingshuailiu

Update: simple use VLLM_USE_V1=0 can solve this problem. This is exactly a bug in V1 Engine. I try to set OOV logits to +inf and V0 Engine will just sample token 0 (an "!" for Qwen model) @huiyeruzhou Hi, Although setting VLLM_USE_V1=0 can solve the OOV problem, the following problem occurs. Do you know how to solve it?

Image

xjtupy avatar Sep 15 '25 03:09 xjtupy

You may also want to know about another workaround, use allowed_token_ids, here is an adaptive workaround for both V0 and V1. (no need to modify any environment variable or disabling V1 Engine)

    # fix OOV: https://github.com/vllm-project/vllm/issues/13175
    from vllm import envs
    if envs.VLLM_USE_V1:
        # I have no better idea.
        kwargs['allowed_token_ids'] = list(range(tokenizer.vocab_size))

Thanks, this should be a simple solution

yangzhch6 avatar Jan 14 '26 03:01 yangzhch6

English: This issue appears actionable to close as answered/resolved. The thread already contains working mitigations: VLLM_USE_V1=0 was reported to solve the OOV sampling issue in https://github.com/verl-project/verl/issues/1398#issuecomment-2857420478, and allowed_token_ids=list(range(tokenizer.vocab_size)) was provided as an alternative workaround in https://github.com/verl-project/verl/issues/1398#issuecomment-2857446940. The original reporter later replied “Thanks” in https://github.com/verl-project/verl/issues/1398#issuecomment-2864149028.

Current verl main also has a direct guard for this class of issue: monkey_patch_compute_logits masks logits beyond the tokenizer vocabulary to -inf in https://github.com/verl-project/verl/blob/main/verl/workers/rollout/vllm_rollout/utils.py#L122-L135, monkey_patch_model applies it in https://github.com/verl-project/verl/blob/main/verl/workers/rollout/vllm_rollout/utils.py#L235-L238, and the vLLM async server calls it with len(self.model_config.tokenizer) in https://github.com/verl-project/verl/blob/main/verl/workers/rollout/vllm_rollout/vllm_async_server.py#L412-L418. This matches the upstream vLLM discussion that masking OOV logits is the robust fix: https://github.com/vllm-project/vllm/issues/13175#issuecomment-3626758754.

中文: 这个 issue 可以按“已回答/已解决”关闭。线程里已经有可用规避方案:VLLM_USE_V1=0 被反馈可以解决该 OOV 采样问题(https://github.com/verl-project/verl/issues/1398#issuecomment-2857420478),同时也给出了 allowed_token_ids=list(range(tokenizer.vocab_size)) 的替代方案(https://github.com/verl-project/verl/issues/1398#issuecomment-2857446940)。原报告者随后也在 https://github.com/verl-project/verl/issues/1398#issuecomment-2864149028 回复了感谢。

当前 verl main 对这类问题已有直接防护:monkey_patch_compute_logits 会把 tokenizer vocab 之外的 logits mask 为 -inf(https://github.com/verl-project/verl/blob/main/verl/workers/rollout/vllm_rollout/utils.py#L122-L135),monkey_patch_model 会应用该 patch(https://github.com/verl-project/verl/blob/main/verl/workers/rollout/vllm_rollout/utils.py#L235-L238),vLLM async server 启动后会用 len(self.model_config.tokenizer) 调用该 patch(https://github.com/verl-project/verl/blob/main/verl/workers/rollout/vllm_rollout/vllm_async_server.py#L412-L418)。这也与 vLLM 上游讨论中“mask OOV logits”是完整解决方式的判断一致:https://github.com/vllm-project/vllm/issues/13175#issuecomment-3626758754。

If this still reproduces on current verl main, please open a fresh issue or comment with the exact verl commit, vLLM version, rollout backend/config, model/tokenizer path, and generated token ids before decoding.

如果在当前 verl main 仍然复现,请补充或新开 issue,提供准确的 verl commit、vLLM 版本、rollout backend/config、模型和 tokenizer 路径,以及解码前的 generated token ids。 This response was generated by a scheduled Codex GPT5.5 issue processing task.

Kirrito-k423 avatar Jul 05 '26 01:07 Kirrito-k423