#69264·Paddle

SOT Guard 机制性能优化

Author: zrr1999Created Nov 9, 2024Updated Sep 29, 2026
LabelsPFCCSOT

Guard 节点实现

Guard 类型汇总

通过统计 make_stringified_guard 中出现的 StringifiedExpression,可以大致得到需要的 Guard 类型。

基础 Guard 进度跟踪

Guard 类型 Guard 描述 当前进度 相关 PR
TypeMatchGuard 检查类型是否匹配 ✅ #69313
ValueMatchGuard 检查值是否匹配 ✅ #69313
LengthMatchGuard 检查长度是否匹配 ✅ #69313
DtypeMatchGuard 检查 dtype 是否匹配 ✅ #69313
ShapeMatchGuard 检查 shape 是否匹配 ✅ #69353
AttributeMatchGuard 检查某个对象的 attr 是否匹配 ✅ #69411
IdMatchGuard 检查是否相同的对象 ✅ #69672
InstanceCheckGuard 检查一个对象是否是某个类或其子类 ✅ #69975
NumpyDtypeMatchGuard 检查两个 numpy 的 dtype 是否匹配 ✅ #71900
NumPyArrayValueMatchGuard 检查两个 numpy array 是否匹配 ✅ #71979
WeakRefMatchGuard 对自身进行弱引用,在 check 的时候检查自身是否为 None,并且于传入值相等 ✅ #72081

特殊 Guard 进度跟踪

Guard 类型 Guard 描述 当前进度 相关 PR
LambdaGuard 支持 lambda 表达式作为 Guard ✅ #69313

组合 Guard 进度跟踪

Guard 类型 Guard 描述 当前进度 相关 PR
GuardGroup 合并多个 Guard 作为一组,对外的行为与单个 Guard 一致 ✅ #69313
TensorMetaMatchGuard 检查 Tensor 元信息是否匹配
LayerMatchGuard 检查是否是同一个 Layer,并且 training 状态一致 ✅(目前不继承自 GuardGroup) #69313
RangeMatchGuard 检查是否同样的 range ✅ #69411,#70362

make_stringified_guard 的 FasterStringifiedExpression 适配

进度跟踪

函数/类 所在文件 用途 单测情况 当前进度 相关 PR
object_equal_stringified_guard guard.py ✅ ✅ #72081
VariableBase base.py ✅ ✅ #69411
NumpyVariable basic.py #71216
NumpyNumberVariable basic.py ✅ ✅ #71900
NumpyArrayVariable basic.py ✅ ✅ #71979
SliceVariable basic.py ✅ ✅ #69975
TensorVariable basic.py #72327
TensorDtypeVariable basic.py ✅ ✅ #69353
LayerVariable callable.py ✅ ✅ #69411
ContainerLayerVariable callable.py ✅ ✅ #69411
RangeVariable container.py ✅ ✅ #70362
ContainerVariable container.py ✅ ✅ #69975

Guard Tree 机制实现

  • #70154
  • #71994
  • #72438
  • #72285
  • #69836

Guard 节点融合

验证机制优化

  • 同时生成非 faster 和 faster guard,然后同时跑这俩,比较下 guard 自己的结果 #71239
  • 添加一个新的环境变量 ENV_SOT_ENABLE_CHECK_FASTER_GUARD, 开启后跑 guard_fn 和 guard_fn.faster_guard, 并检查这两次的结果 #71239
  • 性能测试项目 PaddleGuardBenchmark

TODO

  • log信息改进