feat(worker): onnx 階段自動移除尾端 Softmax + pre-check regex 收窄 #6

Merged
jim800121 merged 1 commits from feat/softmax-tail-removal into main 2026-07-05 21:55:39 +00:00
Collaborator

問題

同一顆含 Softmax 的 tflite,正式站能編出 KL520 真 .nef,本專案 worker 在 nef 階段撞 UnimplementedFeature [Softmax] exit 6。

根因

runtime ktc 的 eliminate_tail 是 no-op(只印警告不做事),尾端 Softmax 未被移除。正式站產物實測為 logits 輸出(Softmax 已在模型階段移除)、compiler 版本相同。

修法(staging 實測驗證)

  • onnx/core.pyremove_tail_softmax() — 所有 platform 移除 terminal Softmax(cut_nodes、多 output fail-loud 驗證、onnx.checker、metadata)
  • precheck.py:R3 誤擋收窄(真 fail-open)
  • tests +16(29 passed)、TDD §12 / ADR-012 / PRD 同步

行為變更

所有 platform NEF 輸出改 logits(與正式站一致)、需通知 visionA。

驗證

  • Review 兩輪:0C/3M → 0C/0M 通過
  • W3 docker integration 6/6 PASS:520+Softmax e2e 產真 .nef 799,844 bytes(與正式站權重段逐 byte 相同)、720 回歸、precheck 真報告不誤擋、no-op 回歸
## 問題 同一顆含 Softmax 的 tflite,正式站能編出 KL520 真 .nef,本專案 worker 在 nef 階段撞 `UnimplementedFeature [Softmax]` exit 6。 ## 根因 runtime ktc 的 `eliminate_tail` 是 no-op(只印警告不做事),尾端 Softmax 未被移除。正式站產物實測為 logits 輸出(Softmax 已在模型階段移除)、compiler 版本相同。 ## 修法(staging 實測驗證) - **onnx/core.py**:`remove_tail_softmax()` — 所有 platform 移除 terminal Softmax(`cut_nodes`、多 output fail-loud 驗證、onnx.checker、metadata) - **precheck.py**:R3 誤擋收窄(真 fail-open) - tests +16(29 passed)、TDD §12 / ADR-012 / PRD 同步 ## 行為變更 所有 platform NEF 輸出改 **logits**(與正式站一致)、需通知 visionA。 ## 驗證 - Review 兩輪:0C/3M → **0C/0M 通過** - W3 docker integration **6/6 PASS**:520+Softmax e2e 產真 .nef 799,844 bytes(與正式站權重段逐 byte 相同)、720 回歸、precheck 真報告不誤擋、no-op 回歸
jim800121 added 1 commit 2026-07-05 21:55:15 +00:00
問題:同一顆含 Softmax 的 tflite,正式站能編出 KL520 真 .nef,
本專案 worker 在 nef 階段撞 UnimplementedFeature [Softmax] exit 6。
根因:runtime ktc 的 eliminate_tail 是 no-op(閹割版、只印警告),
尾端 Softmax 未被移除;正式站產物實測為 logits 輸出(Softmax 已砍)。

修法(staging 實測驗證、與正式站產物權重段逐 byte 相同):
- onnx/core.py:新增 remove_tail_softmax(),onnx2onnx_flow 後對所有
  platform 移除 terminal Softmax(cut_nodes、不用 cut_types 避免誤砍
  中間層下游)、多 output rewire 逐項驗證 fail-loud、onnx.checker、
  removed_tail_softmax metadata
- precheck.py:R3 誤擋收窄——刪 hw_not_support_col 欄位名誤命中、
  op capture 改必須、抽不到具體 op 名改放行+warning(真 fail-open)、
  刪自由文字猜 op fallback、加噪音 token 過濾
- tests:+16(29 passed;terminal/no-op/多 output/fail-open 全覆蓋)
- docs:TDD §12、design-doc ADR-012、PRD 輸出語意變更(機率→logits)

行為變更:所有 platform NEF 輸出改 logits(與正式站一致)、
分類後處理需呼叫端自行補 softmax。

Review:兩輪(0C/3M→0C/0M);W3 docker integration 6/6 PASS
(520+Softmax e2e 產真 .nef 799,844 bytes、720 回歸、precheck 放行)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jim800121 merged commit 407fe10a8c into main 2026-07-05 21:55:39 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: warrenchen/kneron_model_converter#6
No description provided.