Merged
fix:apply_came_part4中图原型与算子原型参数名不一致 #13551
陈思Add on 18 days ago
fix:apply_came_part4中图原型与算子原型参数名不一致 #13551
Merged
陈思Add on 18 days ago
Total: 5 files changed+207-152
@@ -20,7 +20,7 @@ class ApplyCamePart4 : public OpDef {
20public:20public:
21 explicit ApplyCamePart4(const char* name) : OpDef(name)21 explicit ApplyCamePart4(const char* name) : OpDef(name)
22 {22 {
23- this->Input("param_in")23+ this->Input("param")
yuning_chen
yuning_chenyuning_chen18 days ago

这次改的是算子 IR 的输入输出名,但仓里引用旧名字的地方没有同步。

  • 现在代码看来本 PR 只动了 apply_came_part4_def.cpp 和 tests/assets/golden.py 两个文件,而 op_host/config/ascend950/apply_came_part4_binary.json 里的 "name" 字段仍然是 param_in / r_in / c_in / param_out / r_out / c_out,README.md 的参数表和约束说明、以及 apply_came_part4_tiling_arch35.cpp 里 OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON 传的 "c_in"/"r_in" 字面量也都还是旧名。
  • 可能存在有算子信息库与二进制配置对不上的问题,binary.json 的输入输出名是按 OpDef 注册的名字匹配的,改了一边没改另一边,二进制查找或算子信息校验会失配;另外 IR 名字属于对外接口,已有图里按 param_in 建边的场景也会直接断。
  • 建议可以把 binary.json、README 和 tiling 报错里的名字一起改掉;另外这次把输入和输出都叫 param / r / c,输入输出重名和仓里其他 Apply 系列用 _in / _out 后缀区分的做法不一致,如果是为了标识 ref 关系,建议确认下 OpDef 这边是否允许同名并在 PR 描述里说明。
likedislike
陈思
陈思
18 days ago Comments:
likedislike
24 .ParamType(REQUIRED)24 .ParamType(REQUIRED)
25 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})25 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})
26 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})26 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})
@@ -30,12 +30,12 @@ public:
30 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})30 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})
31 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})31 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})
32 .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});32 .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
33- this->Input("r_in")33+ this->Input("r")
34 .ParamType(REQUIRED)34 .ParamType(REQUIRED)
35 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})35 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})
36 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})36 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})
37 .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});37 .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
38- this->Input("c_in")38+ this->Input("c")
39 .ParamType(REQUIRED)39 .ParamType(REQUIRED)
40 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})40 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})
41 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})41 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})
@@ -80,17 +80,17 @@ public:
80 .DataType({ge::DT_INT64, ge::DT_INT64, ge::DT_INT64})80 .DataType({ge::DT_INT64, ge::DT_INT64, ge::DT_INT64})
81 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})81 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})
82 .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});82 .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
83- this->Output("param_out")83+ this->Output("param")
84 .ParamType(REQUIRED)84 .ParamType(REQUIRED)
85 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})85 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})
86 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})86 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})
87 .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});87 .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
88- this->Output("r_out")88+ this->Output("r")
89 .ParamType(REQUIRED)89 .ParamType(REQUIRED)
90 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})90 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})
91 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})91 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})
92 .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});92 .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
93- this->Output("c_out")93+ this->Output("c")
94 .ParamType(REQUIRED)94 .ParamType(REQUIRED)
95 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})95 .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16})
96 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})96 .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})
@@ -5,7 +5,7 @@
5 "bin_filename": "ApplyCamePart4_fp32_350",5 "bin_filename": "ApplyCamePart4_fp32_350",
6 "inputs": [6 "inputs": [
7 {7 {
8- "name": "param_in",8+ "name": "param",
9 "index": 0,9 "index": 0,
10 "dtype": "float32",10 "dtype": "float32",
11 "format": "ND",11 "format": "ND",
@@ -27,7 +27,7 @@
27 "format_match_mode": "FormatAgnostic"27 "format_match_mode": "FormatAgnostic"
28 },28 },
29 {29 {
30- "name": "r_in",30+ "name": "r",
31 "index": 2,31 "index": 2,
32 "dtype": "float32",32 "dtype": "float32",
33 "format": "ND",33 "format": "ND",
@@ -38,7 +38,7 @@
38 "format_match_mode": "FormatAgnostic"38 "format_match_mode": "FormatAgnostic"
39 },39 },
40 {40 {
41- "name": "c_in",41+ "name": "c",
42 "index": 3,42 "index": 3,
43 "dtype": "float32",43 "dtype": "float32",
44 "format": "ND",44 "format": "ND",
@@ -81,20 +81,9 @@
81 ],81 ],
82 "format_match_mode": "FormatAgnostic"82 "format_match_mode": "FormatAgnostic"
83 },83 },
84- {
85- "name": "sum_r",
86- "index": 7,
87- "dtype": "float32",
88- "format": "ND",
89- "paramType": "optional",
90- "shape": [
91- -2
92- ],
93- "format_match_mode": "FormatAgnostic"
94- },
95 {84 {
96 "name": "sum_u_r",85 "name": "sum_u_r",
97- "index": 8,86+ "index": 7,
98 "dtype": "float32",87 "dtype": "float32",
99 "format": "ND",88 "format": "ND",
100 "paramType": "required",89 "paramType": "required",
@@ -105,7 +94,7 @@
105 },94 },
106 {95 {
107 "name": "sum_u_c",96 "name": "sum_u_c",
108- "index": 9,97+ "index": 8,
109 "dtype": "float32",98 "dtype": "float32",
110 "format": "ND",99 "format": "ND",
111 "paramType": "required",100 "paramType": "required",
@@ -116,7 +105,7 @@
116 },105 },
117 {106 {
118 "name": "sum_u_rc",107 "name": "sum_u_rc",
119- "index": 10,108+ "index": 9,
120 "dtype": "float32",109 "dtype": "float32",
121 "format": "ND",110 "format": "ND",
122 "paramType": "required",111 "paramType": "required",
@@ -125,6 +114,17 @@
125 ],114 ],
126 "format_match_mode": "FormatAgnostic"115 "format_match_mode": "FormatAgnostic"
127 },116 },
117+ {
118+ "name": "sum_r",
119+ "index": 10,
fanzhaoyun001
fanzhaoyun001fanzhaoyun00118 days ago

[Blocker] binary json 中 sum_r 索引重排但原型 def.cpp 未同步

该 JSON 把可选输入 sum_r 从 index 7 移到 index 10,并把 sum_u_r/sum_u_c/sum_u_rc 各前移一位(7/8/9);但本 patch 中 op_host/apply_came_part4_def.cpp 仅有输入改名,未见 sum_r 注册位置调整(diff 第 42~79 行区间无改动)。于是原型输入序列为 ...beta3, sum_r, sum_u_r, sum_u_c, sum_u_rc, global_shape,而二进制配置/kernel 索引为 ...beta3, sum_u_r, sum_u_c, sum_u_rc, sum_r, global_shape,两者不一致。运行时会按错误 index 绑定张量,造成结果错误甚至内存越界。建议同步修改 def.cpp 的 Input 注册顺序,并复核 tiling/kernel 的参数索引及 golden 签名;ascend950 的 binary.json 存在同样问题。

likedislike
陈思
陈思
16 days ago Comments:
likedislike
120+ "dtype": "float32",
121+ "format": "ND",
122+ "paramType": "optional",
123+ "shape": [
124+ -2
125+ ],
126+ "format_match_mode": "FormatAgnostic"
127+ },
128 {128 {
129 "name": "global_shape",129 "name": "global_shape",
130 "index": 11,130 "index": 11,
@@ -139,7 +139,7 @@
139 ],139 ],
140 "outputs": [140 "outputs": [
141 {141 {
142- "name": "param_out",142+ "name": "param",
143 "index": 0,143 "index": 0,
144 "dtype": "float32",144 "dtype": "float32",
145 "format": "ND",145 "format": "ND",
@@ -150,7 +150,7 @@
150 "format_match_mode": "FormatAgnostic"150 "format_match_mode": "FormatAgnostic"
151 },151 },
152 {152 {
153- "name": "r_out",153+ "name": "r",
154 "index": 1,154 "index": 1,
155 "dtype": "float32",155 "dtype": "float32",
156 "format": "ND",156 "format": "ND",
@@ -161,7 +161,7 @@
161 "format_match_mode": "FormatAgnostic"161 "format_match_mode": "FormatAgnostic"
162 },162 },
163 {163 {
164- "name": "c_out",164+ "name": "c",
165 "index": 2,165 "index": 2,
166 "dtype": "float32",166 "dtype": "float32",
167 "format": "ND",167 "format": "ND",
@@ -177,7 +177,7 @@
177 "bin_filename": "ApplyCamePart4_float16_350",177 "bin_filename": "ApplyCamePart4_float16_350",
178 "inputs": [178 "inputs": [
179 {179 {
180- "name": "param_in",180+ "name": "param",
181 "index": 0,181 "index": 0,
182 "dtype": "float16",182 "dtype": "float16",
183 "format": "ND",183 "format": "ND",
@@ -199,7 +199,7 @@
199 "format_match_mode": "FormatAgnostic"199 "format_match_mode": "FormatAgnostic"
200 },200 },
201 {201 {
202- "name": "r_in",202+ "name": "r",
203 "index": 2,203 "index": 2,
204 "dtype": "float16",204 "dtype": "float16",
205 "format": "ND",205 "format": "ND",
@@ -210,7 +210,7 @@
210 "format_match_mode": "FormatAgnostic"210 "format_match_mode": "FormatAgnostic"
211 },211 },
212 {212 {
213- "name": "c_in",213+ "name": "c",
214 "index": 3,214 "index": 3,
215 "dtype": "float16",215 "dtype": "float16",
216 "format": "ND",216 "format": "ND",
@@ -253,20 +253,9 @@
253 ],253 ],
254 "format_match_mode": "FormatAgnostic"254 "format_match_mode": "FormatAgnostic"
255 },255 },
256- {
257- "name": "sum_r",
258- "index": 7,
259- "dtype": "float32",
260- "format": "ND",
261- "paramType": "optional",
262- "shape": [
263- -2
264- ],
265- "format_match_mode": "FormatAgnostic"
266- },
267 {256 {
268 "name": "sum_u_r",257 "name": "sum_u_r",
269- "index": 8,258+ "index": 7,
270 "dtype": "float32",259 "dtype": "float32",
271 "format": "ND",260 "format": "ND",
272 "paramType": "required",261 "paramType": "required",
@@ -277,7 +266,7 @@
277 },266 },
278 {267 {
279 "name": "sum_u_c",268 "name": "sum_u_c",
280- "index": 9,269+ "index": 8,
281 "dtype": "float32",270 "dtype": "float32",
282 "format": "ND",271 "format": "ND",
283 "paramType": "required",272 "paramType": "required",
@@ -288,7 +277,7 @@
288 },277 },
289 {278 {
290 "name": "sum_u_rc",279 "name": "sum_u_rc",
291- "index": 10,280+ "index": 9,
292 "dtype": "float32",281 "dtype": "float32",
293 "format": "ND",282 "format": "ND",
294 "paramType": "required",283 "paramType": "required",
@@ -297,6 +286,17 @@
297 ],286 ],
298 "format_match_mode": "FormatAgnostic"287 "format_match_mode": "FormatAgnostic"
299 },288 },
289+ {
290+ "name": "sum_r",
291+ "index": 10,
292+ "dtype": "float32",
293+ "format": "ND",
294+ "paramType": "optional",
295+ "shape": [
296+ -2
297+ ],
298+ "format_match_mode": "FormatAgnostic"
299+ },
300 {300 {
301 "name": "global_shape",301 "name": "global_shape",
302 "index": 11,302 "index": 11,
@@ -311,7 +311,7 @@
311 ],311 ],
312 "outputs": [312 "outputs": [
313 {313 {
314- "name": "param_out",314+ "name": "param",
315 "index": 0,315 "index": 0,
316 "dtype": "float16",316 "dtype": "float16",
317 "format": "ND",317 "format": "ND",
@@ -322,7 +322,7 @@
322 "format_match_mode": "FormatAgnostic"322 "format_match_mode": "FormatAgnostic"
323 },323 },
324 {324 {
325- "name": "r_out",325+ "name": "r",
326 "index": 1,326 "index": 1,
327 "dtype": "float16",327 "dtype": "float16",
328 "format": "ND",328 "format": "ND",
@@ -333,7 +333,7 @@
333 "format_match_mode": "FormatAgnostic"333 "format_match_mode": "FormatAgnostic"
334 },334 },
335 {335 {
336- "name": "c_out",336+ "name": "c",
337 "index": 2,337 "index": 2,
338 "dtype": "float16",338 "dtype": "float16",
339 "format": "ND",339 "format": "ND",
@@ -349,7 +349,7 @@
349 "bin_filename": "ApplyCamePart4_bf16_350",349 "bin_filename": "ApplyCamePart4_bf16_350",
350 "inputs": [350 "inputs": [
351 {351 {
352- "name": "param_in",352+ "name": "param",
353 "index": 0,353 "index": 0,
354 "dtype": "bfloat16",354 "dtype": "bfloat16",
355 "format": "ND",355 "format": "ND",
@@ -371,7 +371,7 @@
371 "format_match_mode": "FormatAgnostic"371 "format_match_mode": "FormatAgnostic"
372 },372 },
373 {373 {
374- "name": "r_in",374+ "name": "r",
375 "index": 2,375 "index": 2,
376 "dtype": "bfloat16",376 "dtype": "bfloat16",
377 "format": "ND",377 "format": "ND",
@@ -382,7 +382,7 @@
382 "format_match_mode": "FormatAgnostic"382 "format_match_mode": "FormatAgnostic"
383 },383 },
384 {384 {
385- "name": "c_in",385+ "name": "c",
386 "index": 3,386 "index": 3,
387 "dtype": "bfloat16",387 "dtype": "bfloat16",
388 "format": "ND",388 "format": "ND",
@@ -425,20 +425,9 @@
425 ],425 ],
426 "format_match_mode": "FormatAgnostic"426 "format_match_mode": "FormatAgnostic"
427 },427 },
428- {
429- "name": "sum_r",
430- "index": 7,
431- "dtype": "float32",
432- "format": "ND",
433- "paramType": "optional",
434- "shape": [
435- -2
436- ],
437- "format_match_mode": "FormatAgnostic"
438- },
439 {428 {
440 "name": "sum_u_r",429 "name": "sum_u_r",
441- "index": 8,430+ "index": 7,
442 "dtype": "float32",431 "dtype": "float32",
443 "format": "ND",432 "format": "ND",
444 "paramType": "required",433 "paramType": "required",
@@ -449,7 +438,7 @@
449 },438 },
450 {439 {
451 "name": "sum_u_c",440 "name": "sum_u_c",
452- "index": 9,441+ "index": 8,
453 "dtype": "float32",442 "dtype": "float32",
454 "format": "ND",443 "format": "ND",
455 "paramType": "required",444 "paramType": "required",
@@ -460,7 +449,7 @@
460 },449 },
461 {450 {
462 "name": "sum_u_rc",451 "name": "sum_u_rc",
463- "index": 10,452+ "index": 9,
464 "dtype": "float32",453 "dtype": "float32",
465 "format": "ND",454 "format": "ND",
466 "paramType": "required",455 "paramType": "required",
@@ -469,6 +458,17 @@
469 ],458 ],
470 "format_match_mode": "FormatAgnostic"459 "format_match_mode": "FormatAgnostic"
471 },460 },
461+ {
462+ "name": "sum_r",
463+ "index": 10,
464+ "dtype": "float32",
465+ "format": "ND",
466+ "paramType": "optional",
467+ "shape": [
468+ -2
469+ ],
470+ "format_match_mode": "FormatAgnostic"
471+ },
472 {472 {
473 "name": "global_shape",473 "name": "global_shape",
474 "index": 11,474 "index": 11,
@@ -483,7 +483,7 @@
483 ],483 ],
484 "outputs": [484 "outputs": [
485 {485 {
486- "name": "param_out",486+ "name": "param",
487 "index": 0,487 "index": 0,
488 "dtype": "bfloat16",488 "dtype": "bfloat16",
489 "format": "ND",489 "format": "ND",
@@ -494,7 +494,7 @@
494 "format_match_mode": "FormatAgnostic"494 "format_match_mode": "FormatAgnostic"
495 },495 },
496 {496 {
497- "name": "r_out",497+ "name": "r",
498 "index": 1,498 "index": 1,
499 "dtype": "bfloat16",499 "dtype": "bfloat16",
500 "format": "ND",500 "format": "ND",
@@ -505,7 +505,7 @@
505 "format_match_mode": "FormatAgnostic"505 "format_match_mode": "FormatAgnostic"
506 },506 },
507 {507 {
508- "name": "c_out",508+ "name": "c",
509 "index": 2,509 "index": 2,
510 "dtype": "bfloat16",510 "dtype": "bfloat16",
511 "format": "ND",511 "format": "ND",
@@ -5,7 +5,7 @@
5 "bin_filename": "ApplyCamePart4_fp32_950",5 "bin_filename": "ApplyCamePart4_fp32_950",
6 "inputs": [6 "inputs": [
7 {7 {
8- "name": "param_in",8+ "name": "param",
9 "index": 0,9 "index": 0,
10 "dtype": "float32",10 "dtype": "float32",
11 "format": "ND",11 "format": "ND",
@@ -27,7 +27,7 @@
27 "format_match_mode": "FormatAgnostic"27 "format_match_mode": "FormatAgnostic"
28 },28 },
29 {29 {
30- "name": "r_in",30+ "name": "r",
31 "index": 2,31 "index": 2,
32 "dtype": "float32",32 "dtype": "float32",
33 "format": "ND",33 "format": "ND",
@@ -38,7 +38,7 @@
38 "format_match_mode": "FormatAgnostic"38 "format_match_mode": "FormatAgnostic"
39 },39 },
40 {40 {
41- "name": "c_in",41+ "name": "c",
42 "index": 3,42 "index": 3,
43 "dtype": "float32",43 "dtype": "float32",
44 "format": "ND",44 "format": "ND",
@@ -81,20 +81,9 @@
81 ],81 ],
82 "format_match_mode": "FormatAgnostic"82 "format_match_mode": "FormatAgnostic"
83 },83 },
84- {
85- "name": "sum_r",
86- "index": 7,
87- "dtype": "float32",
88- "format": "ND",
89- "paramType": "optional",
90- "shape": [
91- -2
92- ],
93- "format_match_mode": "FormatAgnostic"
94- },
95 {84 {
96 "name": "sum_u_r",85 "name": "sum_u_r",
97- "index": 8,86+ "index": 7,
98 "dtype": "float32",87 "dtype": "float32",
99 "format": "ND",88 "format": "ND",
100 "paramType": "required",89 "paramType": "required",
@@ -105,7 +94,7 @@
105 },94 },
106 {95 {
107 "name": "sum_u_c",96 "name": "sum_u_c",
108- "index": 9,97+ "index": 8,
109 "dtype": "float32",98 "dtype": "float32",
110 "format": "ND",99 "format": "ND",
111 "paramType": "required",100 "paramType": "required",
@@ -116,7 +105,7 @@
116 },105 },
117 {106 {
118 "name": "sum_u_rc",107 "name": "sum_u_rc",
119- "index": 10,108+ "index": 9,
120 "dtype": "float32",109 "dtype": "float32",
121 "format": "ND",110 "format": "ND",
122 "paramType": "required",111 "paramType": "required",
@@ -125,6 +114,17 @@
125 ],114 ],
126 "format_match_mode": "FormatAgnostic"115 "format_match_mode": "FormatAgnostic"
127 },116 },
117+ {
118+ "name": "sum_r",
119+ "index": 10,
120+ "dtype": "float32",
121+ "format": "ND",
122+ "paramType": "optional",
123+ "shape": [
124+ -2
125+ ],
126+ "format_match_mode": "FormatAgnostic"
127+ },
128 {128 {
129 "name": "global_shape",129 "name": "global_shape",
130 "index": 11,130 "index": 11,
@@ -139,7 +139,7 @@
139 ],139 ],
140 "outputs": [140 "outputs": [
141 {141 {
142- "name": "param_out",142+ "name": "param",
143 "index": 0,143 "index": 0,
144 "dtype": "float32",144 "dtype": "float32",
145 "format": "ND",145 "format": "ND",
@@ -150,7 +150,7 @@
150 "format_match_mode": "FormatAgnostic"150 "format_match_mode": "FormatAgnostic"
151 },151 },
152 {152 {
153- "name": "r_out",153+ "name": "r",
154 "index": 1,154 "index": 1,
155 "dtype": "float32",155 "dtype": "float32",
156 "format": "ND",156 "format": "ND",
@@ -161,7 +161,7 @@
161 "format_match_mode": "FormatAgnostic"161 "format_match_mode": "FormatAgnostic"
162 },162 },
163 {163 {
164- "name": "c_out",164+ "name": "c",
165 "index": 2,165 "index": 2,
166 "dtype": "float32",166 "dtype": "float32",
167 "format": "ND",167 "format": "ND",
@@ -177,7 +177,7 @@
177 "bin_filename": "ApplyCamePart4_float16_950",177 "bin_filename": "ApplyCamePart4_float16_950",
178 "inputs": [178 "inputs": [
179 {179 {
180- "name": "param_in",180+ "name": "param",
181 "index": 0,181 "index": 0,
182 "dtype": "float16",182 "dtype": "float16",
183 "format": "ND",183 "format": "ND",
@@ -199,7 +199,7 @@
199 "format_match_mode": "FormatAgnostic"199 "format_match_mode": "FormatAgnostic"
200 },200 },
201 {201 {
202- "name": "r_in",202+ "name": "r",
203 "index": 2,203 "index": 2,
204 "dtype": "float16",204 "dtype": "float16",
205 "format": "ND",205 "format": "ND",
@@ -210,7 +210,7 @@
210 "format_match_mode": "FormatAgnostic"210 "format_match_mode": "FormatAgnostic"
211 },211 },
212 {212 {
213- "name": "c_in",213+ "name": "c",
214 "index": 3,214 "index": 3,
215 "dtype": "float16",215 "dtype": "float16",
216 "format": "ND",216 "format": "ND",
@@ -253,20 +253,9 @@
253 ],253 ],
254 "format_match_mode": "FormatAgnostic"254 "format_match_mode": "FormatAgnostic"
255 },255 },
256- {
257- "name": "sum_r",
258- "index": 7,
259- "dtype": "float32",
260- "format": "ND",
261- "paramType": "optional",
262- "shape": [
263- -2
264- ],
265- "format_match_mode": "FormatAgnostic"
266- },
267 {256 {
268 "name": "sum_u_r",257 "name": "sum_u_r",
269- "index": 8,258+ "index": 7,
270 "dtype": "float32",259 "dtype": "float32",
271 "format": "ND",260 "format": "ND",
272 "paramType": "required",261 "paramType": "required",
@@ -277,7 +266,7 @@
277 },266 },
278 {267 {
279 "name": "sum_u_c",268 "name": "sum_u_c",
280- "index": 9,269+ "index": 8,
281 "dtype": "float32",270 "dtype": "float32",
282 "format": "ND",271 "format": "ND",
283 "paramType": "required",272 "paramType": "required",
@@ -288,7 +277,7 @@
288 },277 },
289 {278 {
290 "name": "sum_u_rc",279 "name": "sum_u_rc",
291- "index": 10,280+ "index": 9,
292 "dtype": "float32",281 "dtype": "float32",
293 "format": "ND",282 "format": "ND",
294 "paramType": "required",283 "paramType": "required",
@@ -297,6 +286,17 @@
297 ],286 ],
298 "format_match_mode": "FormatAgnostic"287 "format_match_mode": "FormatAgnostic"
299 },288 },
289+ {
290+ "name": "sum_r",
291+ "index": 10,
292+ "dtype": "float32",
293+ "format": "ND",
294+ "paramType": "optional",
295+ "shape": [
296+ -2
297+ ],
298+ "format_match_mode": "FormatAgnostic"
299+ },
300 {300 {
301 "name": "global_shape",301 "name": "global_shape",
302 "index": 11,302 "index": 11,
@@ -311,7 +311,7 @@
311 ],311 ],
312 "outputs": [312 "outputs": [
313 {313 {
314- "name": "param_out",314+ "name": "param",
315 "index": 0,315 "index": 0,
316 "dtype": "float16",316 "dtype": "float16",
317 "format": "ND",317 "format": "ND",
@@ -322,7 +322,7 @@
322 "format_match_mode": "FormatAgnostic"322 "format_match_mode": "FormatAgnostic"
323 },323 },
324 {324 {
325- "name": "r_out",325+ "name": "r",
326 "index": 1,326 "index": 1,
327 "dtype": "float16",327 "dtype": "float16",
328 "format": "ND",328 "format": "ND",
@@ -333,7 +333,7 @@
333 "format_match_mode": "FormatAgnostic"333 "format_match_mode": "FormatAgnostic"
334 },334 },
335 {335 {
336- "name": "c_out",336+ "name": "c",
337 "index": 2,337 "index": 2,
338 "dtype": "float16",338 "dtype": "float16",
339 "format": "ND",339 "format": "ND",
@@ -349,7 +349,7 @@
349 "bin_filename": "ApplyCamePart4_bf16_950",349 "bin_filename": "ApplyCamePart4_bf16_950",
350 "inputs": [350 "inputs": [
351 {351 {
352- "name": "param_in",352+ "name": "param",
353 "index": 0,353 "index": 0,
354 "dtype": "bfloat16",354 "dtype": "bfloat16",
355 "format": "ND",355 "format": "ND",
@@ -371,7 +371,7 @@
371 "format_match_mode": "FormatAgnostic"371 "format_match_mode": "FormatAgnostic"
372 },372 },
373 {373 {
374- "name": "r_in",374+ "name": "r",
375 "index": 2,375 "index": 2,
376 "dtype": "bfloat16",376 "dtype": "bfloat16",
377 "format": "ND",377 "format": "ND",
@@ -382,7 +382,7 @@
382 "format_match_mode": "FormatAgnostic"382 "format_match_mode": "FormatAgnostic"
383 },383 },
384 {384 {
385- "name": "c_in",385+ "name": "c",
386 "index": 3,386 "index": 3,
387 "dtype": "bfloat16",387 "dtype": "bfloat16",
388 "format": "ND",388 "format": "ND",
@@ -425,20 +425,9 @@
425 ],425 ],
426 "format_match_mode": "FormatAgnostic"426 "format_match_mode": "FormatAgnostic"
427 },427 },
428- {
429- "name": "sum_r",
430- "index": 7,
431- "dtype": "float32",
432- "format": "ND",
433- "paramType": "optional",
434- "shape": [
435- -2
436- ],
437- "format_match_mode": "FormatAgnostic"
438- },
439 {428 {
440 "name": "sum_u_r",429 "name": "sum_u_r",
441- "index": 8,430+ "index": 7,
442 "dtype": "float32",431 "dtype": "float32",
443 "format": "ND",432 "format": "ND",
444 "paramType": "required",433 "paramType": "required",
@@ -449,7 +438,7 @@
449 },438 },
450 {439 {
451 "name": "sum_u_c",440 "name": "sum_u_c",
452- "index": 9,441+ "index": 8,
453 "dtype": "float32",442 "dtype": "float32",
454 "format": "ND",443 "format": "ND",
455 "paramType": "required",444 "paramType": "required",
@@ -460,7 +449,7 @@
460 },449 },
461 {450 {
462 "name": "sum_u_rc",451 "name": "sum_u_rc",
463- "index": 10,452+ "index": 9,
464 "dtype": "float32",453 "dtype": "float32",
465 "format": "ND",454 "format": "ND",
466 "paramType": "required",455 "paramType": "required",
@@ -469,6 +458,17 @@
469 ],458 ],
470 "format_match_mode": "FormatAgnostic"459 "format_match_mode": "FormatAgnostic"
471 },460 },
461+ {
462+ "name": "sum_r",
463+ "index": 10,
464+ "dtype": "float32",
465+ "format": "ND",
466+ "paramType": "optional",
467+ "shape": [
468+ -2
469+ ],
470+ "format_match_mode": "FormatAgnostic"
471+ },
472 {472 {
473 "name": "global_shape",473 "name": "global_shape",
474 "index": 11,474 "index": 11,
@@ -483,7 +483,7 @@
483 ],483 ],
484 "outputs": [484 "outputs": [
485 {485 {
486- "name": "param_out",486+ "name": "param",
487 "index": 0,487 "index": 0,
488 "dtype": "bfloat16",488 "dtype": "bfloat16",
489 "format": "ND",489 "format": "ND",
@@ -494,7 +494,7 @@
494 "format_match_mode": "FormatAgnostic"494 "format_match_mode": "FormatAgnostic"
495 },495 },
496 {496 {
497- "name": "r_out",497+ "name": "r",
498 "index": 1,498 "index": 1,
499 "dtype": "bfloat16",499 "dtype": "bfloat16",
500 "format": "ND",500 "format": "ND",
@@ -505,7 +505,7 @@
505 "format_match_mode": "FormatAgnostic"505 "format_match_mode": "FormatAgnostic"
506 },506 },
507 {507 {
508- "name": "c_out",508+ "name": "c",
509 "index": 2,509 "index": 2,
510 "dtype": "bfloat16",510 "dtype": "bfloat16",
511 "format": "ND",511 "format": "ND",
@@ -13,8 +13,8 @@
13 * \brief ApplyCamePart4 kernel entry (arch35), aligned to canndev ApplyCamePart413 * \brief ApplyCamePart4 kernel entry (arch35), aligned to canndev ApplyCamePart4
14 *14 *
15 * GE IR signature (canndev REG_OP(ApplyCamePart4)):15 * GE IR signature (canndev REG_OP(ApplyCamePart4)):
16- * Inputs (12): param, m, r, c, weight_decay, lr, beta3, sum_r(optional),16+ * Inputs (12): param, m, r, c, weight_decay, lr, beta3,
17- * sum_u_r, sum_u_c, sum_u_rc, global_shape(optional)17+ * sum_u_r(7), sum_u_c(8), sum_u_rc(9), sum_r(10, optional), global_shape(11, optional)
18 * Outputs (3): param, r, c18 * Outputs (3): param, r, c
19 *19 *
20 * Template parameters (matching apply_came_part4_tiling_key.h):20 * Template parameters (matching apply_came_part4_tiling_key.h):
@@ -24,6 +24,10 @@ m = len(c_in); N/M from global_shape when given, else n/m):
24 24 
25fp16/bf16 path: inputs cast to fp32, computed in fp32, rounded (RNE, torch cast)25fp16/bf16 path: inputs cast to fp32, computed in fp32, rounded (RNE, torch cast)
26back to the low precision dtype; the param update consumes the ROUNDED r_out/c_out.26back to the low precision dtype; the param update consumes the ROUNDED r_out/c_out.
27+ 
28+The kernel has no epsilon/clamp. References reject non-finite/non-positive denom
29+or normalized r*c (including zeros introduced by output rounding), rather than
30+changing the formula or passing NaN/Inf to the precision comparator.
27"""31"""
28 32 
29import numpy as np33import numpy as np
@@ -57,14 +61,6 @@ def _to_compute(x):
57 return torch.as_tensor(arr)61 return torch.as_tensor(arr)
58 62 
59 63 
60-def _to_numpy_for_golden(x):
61- if torch.is_tensor(x):
62- if x.dtype == torch.bfloat16:
63- return x.detach().cpu().to(torch.float32).numpy().astype(ml_dtypes.bfloat16)
64- return x.detach().cpu().numpy()
65- return x
66- 
67- 
68def _dtype_of(x):64def _dtype_of(x):
69 if torch.is_tensor(x):65 if torch.is_tensor(x):
70 return x.dtype66 return x.dtype
@@ -78,6 +74,25 @@ def _dtype_of(x):
78 return torch.float3274 return torch.float32
79 75 
80 76 
77+def _checked_param_update(param, m, r_out, c_out, denom, lr, weight_decay, out_dtype):
78+ """Follow the kernel's reciprocal/multiply path on its finite, positive domain."""
79+ if not torch.isfinite(denom).all() or not (denom > 0).all():
80+ raise ValueError("ApplyCamePart4 reference requires finite denom > 0")
81+ rc = torch.outer(r_out.to(param.dtype), c_out.to(param.dtype))
82+ # ProcessParam computes the reciprocal once, then ComputeParam multiplies rc.
83+ normalized_rc = rc * denom.reciprocal()
84+ if not torch.isfinite(normalized_rc).all() or not (normalized_rc > 0).all():
85+ raise ValueError(
86+ "ApplyCamePart4 reference requires finite rc / denom > 0 after r/c rounding"
87+ )
88+ param_out = (
89+ (1.0 - lr * weight_decay) * param - (lr * m) / torch.sqrt(normalized_rc)
90+ ).to(out_dtype)
91+ if not torch.isfinite(param_out).all():
92+ raise ValueError("ApplyCamePart4 reference produced non-finite param output")
93+ return param_out
94+ 
95+ 
81def apply_came_part4_golden(96def apply_came_part4_golden(
82 param_in,97 param_in,
83 m,98 m,
@@ -89,8 +104,8 @@ def apply_came_part4_golden(
89 sum_u_r,104 sum_u_r,
90 sum_u_c,105 sum_u_c,
91 sum_u_rc,106 sum_u_rc,
92- sum_r,107+ sum_r=None,
93- global_shape,108+ global_shape=None,
94 *attr_values,109 *attr_values,
95 **kwargs,110 **kwargs,
96):111):
@@ -126,8 +141,9 @@ def apply_came_part4_golden(
126 c_out = (beta3_v * c_f + (one - beta3_v) / n_g * sum_u_c_f).to(out_dtype)141 c_out = (beta3_v * c_f + (one - beta3_v) / n_g * sum_u_c_f).to(out_dtype)
127 # param 更新:以 round 后的 r_out/c_out(cast 回 compute_dtype)为输入142 # param 更新:以 round 后的 r_out/c_out(cast 回 compute_dtype)为输入
128 denom = beta3_v * sum_r_v / n_g + (one - beta3_v) * sum_u_rc_v / (m_g * n_g)143 denom = beta3_v * sum_r_v / n_g + (one - beta3_v) * sum_u_rc_v / (m_g * n_g)
129- s = torch.outer(r_out.to(compute_dtype), c_out.to(compute_dtype)) / denom144+ param_out = _checked_param_update(
130- param_out = ((one - lr_v * wd) * param_f - lr_v * m_f / torch.sqrt(s)).to(out_dtype)145+ param_f, m_f, r_out, c_out, denom, lr_v, wd, out_dtype
146+ )
131 return [param_out, r_out, c_out]147 return [param_out, r_out, c_out]
132 148 
133 149 
@@ -142,11 +158,11 @@ def customize_inputs(
142 sum_u_r,158 sum_u_r,
143 sum_u_c,159 sum_u_c,
144 sum_u_rc,160 sum_u_rc,
145- sum_r,161+ sum_r=None,
146- global_shape,162+ global_shape=None,
147 **kwargs,163 **kwargs,
148):164):
149- """约束取值域,保证金色可算(sqrt 内 r_out*c_out/denom 非负、denom != 0)。"""165+ """约束常规随机用例取值域;边界用例由 golden 显式检查,拒绝非有限参考结果。"""
150 for tensor in (r_in, c_in, sum_u_r, sum_u_c):166 for tensor in (r_in, c_in, sum_u_r, sum_u_c):
151 tensor[...] = np.abs(np.asarray(tensor)) + 0.1167 tensor[...] = np.abs(np.asarray(tensor)) + 0.1
152 if sum_r is not None:168 if sum_r is not None:
@@ -179,17 +195,56 @@ class _ApplyCamePart4Compose:
179 """Third-party reference executed on the remote GPU server."""195 """Third-party reference executed on the remote GPU server."""
180 196 
181 def __init__(self, **kwargs):197 def __init__(self, **kwargs):
182- self.kwargs = kwargs198+ # TTK may pass the input pool to both construction and invocation.
199+ # Bind tensors only in __call__, using the registered GE input names.
200+ pass
183 201 
184- def __call__(self, *inputs, **kwargs):202+ def __call__(
185- merged = dict(self.kwargs)203+ self,
186- merged.update(kwargs)204+ param,
187- outputs = apply_came_part4_golden(205+ m,
188- *[_to_numpy_for_golden(value) for value in inputs],206+ r,
189- **merged,207+ c,
208+ weight_decay,
209+ lr,
210+ beta3,
211+ sum_u_r,
212+ sum_u_c,
213+ sum_u_rc,
214+ sum_r=None,
215+ global_shape=None,
216+ **kwargs,
217+ ):
218+ out_dtype = param.dtype
219+ param_f = param.to(torch.float32)
220+ m_f = m.to(torch.float32)
221+ r_f = r.to(torch.float32).reshape(-1)
222+ c_f = c.to(torch.float32).reshape(-1)
223+ wd = weight_decay.to(torch.float32).reshape(-1)[0]
224+ lr_v = lr.to(torch.float32).reshape(-1)[0]
225+ beta3_v = beta3.to(torch.float32).reshape(-1)[0]
226+ sum_u_rc_v = sum_u_rc.to(torch.float32).reshape(-1)[0]
227+ sum_r_v = r_f.sum() if sum_r is None else sum_r.to(torch.float32).reshape(-1)[0]
228+ 
229+ if global_shape is None:
230+ n_g, m_g = float(r_f.numel()), float(c_f.numel())
231+ else:
232+ n_g, m_g = global_shape.to(torch.float32).reshape(-1).unbind()
233+ 
234+ r_out = (
235+ beta3_v * r_f
236+ + (1.0 - beta3_v) / m_g * sum_u_r.to(torch.float32).reshape(-1)
237+ ).to(out_dtype)
238+ c_out = (
239+ beta3_v * c_f
240+ + (1.0 - beta3_v) / n_g * sum_u_c.to(torch.float32).reshape(-1)
241+ ).to(out_dtype)
242+ denom = beta3_v * sum_r_v / n_g + (1.0 - beta3_v) * sum_u_rc_v / (m_g * n_g)
243+ # The parameter update consumes the rounded low-precision r/c outputs.
244+ param_out = _checked_param_update(
245+ param_f, m_f, r_out, c_out, denom, lr_v, wd, out_dtype
190 )246 )
191- device = inputs[0].device if inputs and torch.is_tensor(inputs[0]) else "cpu"247+ return [param_out, r_out, c_out]
192- return [torch.as_tensor(np.asarray(out), device=device) for out in outputs]
193 248 
194 249 
195class ApplyCamePart4KernelSpec:250class ApplyCamePart4KernelSpec: