采样配置#

对于OpenAI协议,top_ptemperature在外部协议中指定,而其他采样参数在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
    }
}

基本控制参数#

参数名称

核心功能

温度

控制采样随机性:
→ 0: 确定性模式
→ 1: 标准随机模式

top_k

候选集截断策略:
→ 0: 禁用
→ N: 取前N个高概率token

top_p

核采样策略:
→ 0.95: 取累积概率为95%的候选集

最大新token数

最大生成长度:
MIN(输入长度 + 最大新token数, MAX_SEQ_LEN)

最小新token数

强制最小生成长度

高级控制参数#

参数名称

功能描述

重复惩罚

重复抑制因子:
→ >1.0 抑制重复
→ <1.0 鼓励重复

频率惩罚

此参数用于阻止模型在生成文本中过于频繁地重复相同的单词或短语。它是一个值,每次在生成文本中出现token时都会加到该token的对数概率上。较高的frequency_penalty值将使模型在使用重复token时更加保守。

存在惩罚

此参数用于鼓励模型在生成文本中包含各种不同的token。它是一个值,每次生成token时都会从该token的对数概率中减去。较高的presence_penalty值将使模型更有可能生成尚未包含在生成文本中的token。

停止词列表

Token ID停止词(性能更好):
[[20490,25],[1024]]

停止词字符串

字符串停止词(兼容性更好):
["<end>","\nObservation"]

随机种子

随机种子控制:
→ None: 真随机
→ 固定值: 可重现生成

# 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

代理特定场景:
使用max_thinking_tokens控制思考阶段长度

流式输出

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
}

Parameter Usage Notes#

  1. Stop Words Selection Principles

    • Performance priority: Use stop_words_list for high-frequency triggering scenarios

    • Compatibility priority: Use stop_words_str for complex pattern matching

  2. Length Limit Coordination

    Actual maximum length = min(
        input_token_len + max_new_tokens,
        MAX_SEQ_LEN
    )
    
  3. 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
    }
    
  4. Streaming Output Limitations

    • Need to enable yield_generator=True simultaneously

    • return_logits only returns complete data in non-streaming mode