Skip to content

[CPU:Bugfix] Match RVV Float2Int8 rounding to scalar - #5023

Draft
luke-opus wants to merge 1 commit into
alibaba:masterfrom
luke-opus:feature/rvv-quant-rounding
Draft

luke-opus wants to merge 1 commit into
alibaba:masterfrom
luke-opus:feature/rvv-quant-rounding

Conversation

@luke-opus

@luke-opus luke-opus commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

RVV Float2Int8 currently converts with the caller's floating-point rounding mode. With the usual round-to-nearest-even mode, 0.5, -0.5, 2.5, -2.5 become 0, 0, 2, -2; the scalar roundf implementation produces 1, -1, 3, -3.

Use the explicit RMM intrinsic in both the scalar-parameter and per-channel-parameter RVV paths. This matches roundf's ties-away-from-zero rule and preserves the caller's rounding mode. Packing, dispatch, affine arithmetic and saturation bounds are unchanged.

Validation

  • Full static MNN and run_test.out cross-build/link with Clang 22.1.8, C++11, rv64gcv/lp64d, RVV on and transformer-fuse off. Changed lines checked with clang-format 17 and git diff --check.
  • Executed production RVV kernels in QEMU 11.1.2 at VLEN 128/256/512/1024. For the default VL policy, all 3,640 cases pass per VLEN; the unmodified baseline fails 1,936 rounding cases per VLEN. The matrix covers all five frm modes, all four scale/zero-point parameter modes, 0–129 C4 quads, saturation, output guards and restoration of the caller's frm.
  • Booted RISC-V Linux under QEMU and verified that MNN's actual function table selects both RVV quantization functions. Direct cases, five synthetic quant/dequant graphs and the existing op/ConvInt8/depthwise test pass at VLEN 128/512 with 1 and 4 threads. A v=false run confirms scalar fallback and passes the same checks.

A minimal reproducer uses src={0.5f,-0.5f,2.5f,-2.5f}, sizeQuad=1, unit scale, zero point 0, bounds [-127,127], scalar parameter mode and frm=RNE: baseline output is {0,0,2,-2}, patched output is {1,-1,3,-3}.

This change does not fix the separate per-channel template alignment bug exposed by legal non-maximal VL selection. That is handled independently in the companion PR #5024; combining both changes passes all 29,120 cases across four VLENs and both VL policies. No hardware performance claim is made. This remains a draft pending physical-board and pretrained-model validation.

Module

CPU / RISC-V RVV

Type

  • Feature
  • Bugfix
  • Perf
  • Refact
  • Style
  • Doc
  • Test
  • Chore

Checklist

  • Commit message follows [Module:Type] Description format
  • Code compiles without errors
  • Tested on relevant platform(s) — QEMU execution completed; physical RISC-V board and pretrained-model validation pending
  • No unrelated format or style changes included

Shared iOS CI failure

The iOS job fails on a pre-existing Xcode project reference to the absent express/module/MoEModule.cpp. The RVV changes do not modify that project or file. The independent build fix is #5026, which passes the same iOS framework build script locally on Xcode 26.6 / iPhoneOS SDK 26.5. The failed runs on this PR have not been marked as passing; they need a new build with the project fix included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:quantization 量化相关 type:bug 功能缺陷

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants