/images/avatar.png

vllbc

shortcode(置顶)

贴一下可以玩的shortcode。

音乐播放

播放列表

夏日口袋专辑:

播放单曲

最爱的一首(我是紬厨):

视频播放

bilibili

有多P可以选择集数

admonition

类型有:note、abstract、info、tip、success、question、warning、failure、danger、bug、example、quote。

技巧
一个 技巧 横幅

MCTS和PRM

核心总结

  • PRM和MCTS实际上是两种可以独立使用的技术,只不过,往往它们组合使用时往往能产生1+1>2的效果。例如,
    • 单独使用PRM:我们可以让模型对同一个prompt采样多个不同solution,无需MCTS,只需利用模型的temperature等随机参数让每次生成结果不同,然后用PRM对每个solution的每一步打分,最终选择分数最高的路径返回。
    • 单独使用MCTS:使用MCTS生成多个解题路径时,不一定要用PRM来决定哪个节点值得扩展,可以用外部大模型(如GPT-4)来选择,也可以用模型自身的perplexity来判断。本质上,我们需要的是找到最值得扩展的节点,PRM只是挑选的众多方法之一。
  • PRM 和 MCTS 既可以应用于优化训练数据,也可以用来预测用
    • 用于得到高质量训练数据:如rStar论文中,可以用PRM和MCTS的方式来迭代地筛选得到质量更好的思维链SFT数据或者RLHF数据,还可以生成更精确的reward model训练数据。
    • 用于推理:很简单,推理用MCTS的方式把 test-scaling 做上来,再结合PRM的方式从众多路径中挑选最佳答案。
  • PRM和MCTS的缺点
    这方面 DeepSeek-R1和 kimi1.5的论文已经说得很情况了。
  • Process Reward Model(PRM) 在实际应用中有三大局限:
    • 第一,难以清晰界定一般推理中的细粒度步骤,说白了,怎么定义什么为一个步骤。
    • 第二,判断当前步骤的正误难度大,模型自动化标注不如人意,人工标注又难以拓展。
    • 第三,引入基于模型的PRM易致reward hacking,有时为了训练 policy model,但反而更多时间去优化 reward model 去了。
  • 对MCTS的看法:
    • 文本的生成搜索空间指数级增长,为应对,给节点设扩展上限,却容易让模型陷入局部最优解困境。
    • MCTS往往要结合一个精确的PRM来用才能发挥最大效果,但PRM又有上述的问题,陷入一个死循环。 ## 参考 https://zhuanlan.zhihu.com/p/27278317894 rStar-Math: Small LLMs Can Master Math Reasoning with Self-Evolved Deep Thinking

LEGB

a = 'global'

def outer():

    # def len(in_var):
    #     print('called my len() function: ', end="")
    #     l = 0
    #     for i in in_var:
    #         l += 1
    #     return l

    a = 'local'

    def inner():
        nonlocal a
        a += ' variable'
    inner()
    print('a is', a)
    # print(len(a))


outer()

# print(len(a))
print('a is', a)

此时为nonlocal a,会按照local-闭包-global的顺序找到闭包变量a。a的值为local variable

debugger

python调试工具,类似于vscode的调试工具,使用命令行进行调试。

使用方法

插入式

import pdb; pdb.set_trace()

或者

breakpoint()

非插入式

python -m pdb [-c command] (-m module | pyfile) [args ...]

常用命令

h

即help,可用命令如下 image.png

generate

理论部分在这:generate相关 ## generate参数

    def generate(
        self,
        inputs: Optional[torch.Tensor] = None,
        generation_config: Optional[GenerationConfig] = None,
        logits_processor: Optional[LogitsProcessorList] = None,
        stopping_criteria: Optional[StoppingCriteriaList] = None,
        prefix_allowed_tokens_fn: Optional[Callable[[int, torch.Tensor], List[int]]] = None,
        synced_gpus: Optional[bool] = None,
        assistant_model: Optional["PreTrainedModel"] = None,
        streamer: Optional["BaseStreamer"] = None,
        negative_prompt_ids: Optional[torch.Tensor] = None,
        negative_prompt_attention_mask: Optional[torch.Tensor] = None,
        **kwargs,
    ) -> Union[GenerateOutput, torch.LongTensor]:

在代码中可以看到在函数入口显式的定义了很多参数。他们的具体含义如下

einsum

einops.einsum calls einsum operations with einops-style named axes indexing, computing tensor products with an arbitrary number of tensors. Unlike typical einsum syntax, here you must pass tensors first, and then the pattern.

Also, note that rearrange operations such as "(batch chan) out", or singleton axes (), are not currently supported.

爱因斯坦求和

image.png image.png

pack and unpack

pack

Packs several tensors into one. See einops tutorial for introduction into packing (and how it replaces stack and concatenation).

image.png ## unpack >Unpacks a single tensor into several by splitting over a selected axes. See einops tutorial for introduction into packing (and how it replaces stack and concatenation).

image.png

rearrange

einops.rearrange is a reader-friendly smart element reordering for multidimensional tensors. This operation includes functionality of transpose (axes permutation), reshape (view), squeeze, unsqueeze, stack, concatenate and other operations.

代替reshape,给维度命名。可以用…代表不想动的维度。 image.png image.png

repeat

einops.repeat allows reordering elements and repeating them in arbitrary combinations. This operation includes functionality of repeat, tile, and broadcast functions.

repeat是使维度增加,与reduce相反。 image.png image.png ## 应用 比如说repeat_kv函数就可以用einops.repeat很方便的实现