采样配置#
对于OpenAI协议,top_p和temperature在外部协议中指定,而其他采样参数在extra_configs中指定。示例:
{
"model":"Qwen_14B_pressure_test",
"messages":[
{
"role":"system",
"content":"You are a helpful assistant."
},
{
"role":"user",
"content":"Hello, what's the weather like in Hangzhou today"
}
],
"stream":true,
"temperature":1,
"max_tokens":1024,
"top_p":0.8,
"extra_configs" : {
"top_k": 1
}
}
原始协议通过generate_config指定采样参数。示例:
{
"model":"m6-13b-v1",
"prompt":"Human: write a list for trip\n\nAssitant:","generate_config":{
"top_k": 1,
"top_p": 0
}
}
基本控制参数#
参数名称 |
核心功能 |
|---|---|
温度 |
控制采样随机性: |
top_k |
候选集截断策略: |
top_p |
核采样策略: |
最大新token数 |
最大生成长度: |
最小新token数 |
强制最小生成长度 |
高级控制参数#
参数名称 |
功能描述 |
|---|---|
重复惩罚 |
重复抑制因子: |
频率惩罚 |
此参数用于阻止模型在生成文本中过于频繁地重复相同的单词或短语。它是一个值,每次在生成文本中出现token时都会加到该token的对数概率上。较高的frequency_penalty值将使模型在使用重复token时更加保守。 |
存在惩罚 |
此参数用于鼓励模型在生成文本中包含各种不同的token。它是一个值,每次生成token时都会从该token的对数概率中减去。较高的presence_penalty值将使模型更有可能生成尚未包含在生成文本中的token。 |
停止词列表 |
Token ID停止词(性能更好): |
停止词字符串 |
字符串停止词(兼容性更好): |
随机种子 |
随机种子控制: |
# Stop Words Configuration Example
{
"stop_words_str": ["<|im_end|>", "\nObservation:"],
"stop_words_list": [[20490, 25], [50256]]
}
返回控制参数#
参数名称 |
效果 |
使用场景 |
|---|---|---|
返回logits |
返回每个位置的logits矩阵 |
输出分析/后处理 |
返回隐藏状态 |
返回transformer层的隐藏状态 |
模型调试/特征提取 |
返回输入IDs |
返回输入序列编码结果 |
输入验证 |
返回输出IDs |
返回输出序列编码结果 |
输出解码验证 |
特殊模式参数#
模式名称 |
控制参数 |
功能描述 |
|---|---|---|
思考模式 |
in_think_mode=True |
代理特定场景: |
流式输出 |
yield_generator=True |
启用分块返回机制 |
并行解码 |
pd_separation=True |
启用并行解码优化(需要硬件支持) |
Environment Variable Description#
# Force override stop words configuration
export FORCE_STOP_WORDS=true
export STOP_WORDS_STR="[\"</end>\",\"\\n\"]"
# Hybrid mode (default)
export FORCE_STOP_WORDS=false # union of environment variables, model defaults, and configuration parameters
Sampling Strategy Description#
Combined Strategy Example#
{
"temperature": 0.7,
"top_k": 50,
"top_p": 0.95,
"repetition_penalty": 1.2,
"top_p_decay": 0.9, # 10% decay per token
"top_p_min": 0.5 # Minimum decay threshold
}
Strategy Recommended Values#
Scenario |
温度 |
top_p |
top_k |
|---|---|---|---|
Code Generation |
0.2-0.4 |
0.9 |
40 |
Creative Writing |
0.7-1.0 |
0.95 |
100 |
Factual Q&A |
0.1-0.3 |
0.8 |
20 |
Parameter Usage Notes#
Stop Words Selection Principles
Performance priority: Use
stop_words_listfor high-frequency triggering scenariosCompatibility priority: Use
stop_words_strfor complex pattern matching
Length Limit Coordination
Actual maximum length = min( input_token_len + max_new_tokens, MAX_SEQ_LEN )Thinking Mode Special Constraints
# Need to configure simultaneously { "in_think_mode": True, "max_thinking_tokens": 512, # Control thinking phase length "max_new_tokens": 2048 # Control total output length }
Streaming Output Limitations
Need to enable
yield_generator=Truesimultaneouslyreturn_logitsonly returns complete data in non-streaming mode