Closed
[Requirement|需求建议]: stitch提前发射前端配置调整 #660
LordOfMysteriesAdd on Mar 13Closed at Mar 30
Mar 13 Added label: requirement
Mar 13 Added label: Machine
Mar 14 Assign LordOfMysteries as responsible person
Mar 14 changed custom priority from 无优先级 to 主要
Mar 14 associated Kanban: PyPTO
gaoxingwang
Mar 14 Comments:
Mar 14 Comments:
请处理


Mar 14 Modify description of issue
12 event messages are collapsed here。 See more
Mar 30 Close issue
Thanks for sending an requirement! Please fill in the following template to help quickly solve your problem.
Backgroud(背景信息)
目前算子tensor值依赖有两种场景:
(1)tensor的值在网络中是固定的,在模型启动(pypto算子stitch)前数据已经在device上准备好
(2)tensor的值在网络中是动态变化的,一般由模型中某些小算子计算出来的,可能pypto算子stitch时小算子还没算完。
一般第二种场景是普遍的,这种场景下pypto的stitch动作不能提前发射,需要等到aicore握手开始才认为值依赖tensor的数据是就绪的。
目前通过一个临时配置runtime_debug_mode=2来标记算子是否可以提前发射。
Origin(信息来源)
内部
Benefit / Necessity (价值/作用)
host ready tensor值依赖场景可以提升性能。修改前端配置更友好
Design(设计方案)
前端配置
增加如下option配置项:
runtime_options={ "ready_on_host_tensors": ["block_table", "kv_act_seqs"] }配置示例如下:
python前端将kernel入参中ready_on_host的tensor入参名配置到新增option中,默认所有值依赖tensor都是ready_on_aicore。
然后在ctrlflow表达式构建的过程中识别出哪些tensor的值依赖是不能提前发射的,然后在首次访问Tensor值之前插入wait aicore握手的阻塞代码。
换言之,如果算子值依赖的tensor配置成了ready_on_host,那么此处值依赖的控制流代码可以提前发射,减少头开销。
machine框架处理
原本machine在识别到算子是值依赖场景且不能提前发射时,会在stitch之前等待aicore握手,这样即使stitch前半部分没访问到值依赖tensor的部分也会被阻塞。
新的方案将wait的动作插入到controlflow源码中访问值依赖tensor之前,这样前部分stitch可以提前发射。
插入后的代码大致如下: