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] 如何不打印logprobs #3246

Closed
ChenglongChen opened this issue Mar 12, 2025 · 10 comments
Closed

[Feature] 如何不打印logprobs #3246

ChenglongChen opened this issue Mar 12, 2025 · 10 comments

Comments

@ChenglongChen
Copy link

设置logprobs=1之后,会打印logprobs,如何不打印呢?

如:
18054 {34426: -0.9241080284118652}
7196 {1077: -1.350784182548523}
8168 {3158: -0.5630294680595398}

@lvhan028
Copy link
Collaborator

没太理解问题,是指日志中打印了这些信息么?

@ChenglongChen
Copy link
Author

没太理解问题,是指日志中打印了这些信息么?

是的。是需要设置log_level吗?

@lvhan028
Copy link
Collaborator

容我晚些时候测试看看。用的pipeline接口么?

@ChenglongChen
Copy link
Author

容我晚些时候测试看看。用的pipeline接口么?

对,用的是以下代码:

llm = pipeline(
    config.model_path,
    backend_config=TurbomindEngineConfig(
        tp=1,
        max_batch_size=config.max_batch_size,
        enable_prefix_caching=True,
        session_len=config.max_model_len,
        cache_max_entry_count=config.gpu_memory_utilization
    )
)
gen_config = GenerationConfig(
    n=1,
    max_new_tokens=config.max_tokens,
    # top_k=-1,
    top_p=config.top_p,
    min_p=config.min_p,
    temperature=1.0,
    do_sample=True,
    logprobs=1,
    skip_special_tokens=False
)

@lvhan028
Copy link
Collaborator

lvhan028 commented Mar 12, 2025

from lmdeploy import pipeline, TurbomindEngineConfig, GenerationConfig

llm = pipeline(
    # config.model_path,
    'Qwen/Qwen2.5-7B-Instruct',
    backend_config=TurbomindEngineConfig(
        tp=1,
        # max_batch_size=config.max_batch_size,
        enable_prefix_caching=True,
        # session_len=config.max_model_len,
        # cache_max_entry_count=config.gpu_memory_utilization
    )
)
gen_config = GenerationConfig(
    n=1,
    # max_new_tokens=config.max_tokens,
    # # top_k=-1,
    # top_p=config.top_p,
    # min_p=config.min_p,
    temperature=1.0,
    do_sample=True,
    logprobs=1,
    skip_special_tokens=False
)

response = llm('1+1=?', gen_config=gen_config)
print(response)

The result is shown as follows:

root@SH-IDC1-10-140-24-140:/workspace/llmdeploy# python examples/workspace/test_log_probs.py 
Fetching 14 files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 14/14 [00:00<00:00, 35631.22it/s]
[TM][WARNING] [LlamaTritonModel] `max_context_token_num` is not set, default to 32768.
2025-03-12 15:53:20,081 - lmdeploy - WARNING - turbomind.py:214 - get 255 model params
[WARNING] gemm_config.in is not found; using default GEMM algo                                                                                                                                                                                                                                                 
Response(text='1+1 equals 2.', generate_token_len=7, input_token_len=33, finish_reason='stop', token_ids=[16, 10, 16, 16819, 220, 17, 13], logprobs=[{16: 0.0}, {10: -0.0024050953797996044}, {16: 0.0}, {16819: -0.012469434179365635}, {220: 0.0}, {17: 0.0}, {13: -0.002392965368926525}, {151645: -0.008891315199434757}], logits=None, last_hidden_state=None, index=0)

It didn't output the logprob values unless I use print

@ChenglongChen
Copy link
Author

thx!我单独测试也没有问题了,我再看看是不是别的地方设置有问题。

@ChenglongChen
Copy link
Author

ChenglongChen commented Mar 13, 2025

Hi, 我看了下lmdeploy的源码,如果采样的token_id不在topn里面,是会打印的,具体是这里

tok_res = {idx[i].item(): val[i].item() for i in range(topn)}
token_id = output_ids[pos]
if token_id not in tok_res:
    print(token_id, tok_res)
    valid_n = n.item()
    tok_res[token_id] = \
        val[:valid_n][idx[:valid_n] == token_id].item()

请问,是否可以加一个参数来控制是否打印呢?或者用logging来代替print?

@ChenglongChen ChenglongChen reopened this Mar 13, 2025
@ChenglongChen ChenglongChen changed the title 如何不打印logprobs [Feature] 如何不打印logprobs Mar 13, 2025
@lvhan028
Copy link
Collaborator

这个应该要删掉 😅

@lvhan028
Copy link
Collaborator

#3252 I removed it in this PR

@ChenglongChen
Copy link
Author

Thanks for the fix~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants