Skip to content

spacemit: fix partial output tiles for dense Q8_0 and Q6_K matmul - #98

Merged
alex-spacemit merged 1 commit into
spacemit-com:mtmd-backendfrom
co-seven:pr/nomtp-i8-20261203
Dec 4, 2026
Merged

alex-spacemit merged 1 commit into
spacemit-com:mtmd-backendfrom
co-seven:pr/nomtp-i8-20261203

Conversation

@co-seven

@co-seven co-seven commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Problem and behavior

Correctness fix, not a quantization-accuracy or performance optimization. Dense Q8_0/Q6_K MUL_MAT can stage incomplete packed weights into TCM when the final output tile has fewer than 32 columns. The packed tile still contains all 32 rows. The IME2 M4 kernel can also store past the logical output width.

Copy complete physical N32 weight blocks while retaining the logical output count, then bound M4 vector stores by the remaining columns.

Change and design

  • ime.cpp: round TCM weight-copy extents to full packed blocks, including initial and subsequent staged tiles; keep actual output counts for computation.
  • ime2_kernels.cpp: set output-store VL to the remaining width in the four-row I8 kernel.

Related open work: #78 contains an overlapping M4 tail-store fix among its broader CPY/Q8/MTP changes. This PR additionally fixes dense Q8_0/Q6_K physical TCM staging and is independently based on current mtmd-backend. The shared store hunk should be reconciled if both are merged; this is not a claim that the hunk is unique to this PR.

Scope is limited to ggml/src/ggml-spacemit/. Impact classification: execution-path change. No changes to the retired CPU backend, model code, public API or test sources. Local validation fixtures are excluded. This independently based module commit preserves the target branch's common MTP graph/rollback paths; experimental noMTP-wide reversions are not submitted. No new external dependency is added.

Validation

Base: mtmd-backend at 3f5ce5fd84f4dc6e7e621642cfef0143d49e7c24. Candidate: 8fae2acc369ea14ba4315229d703a5d0a7d662f4; source tree b6d4493f2bbdc5b164b76b40cbb36f2d63e54247.

The exact submitted production source passed a RISC-V Release cross-build of ggml-spacemit using the SpacemiT v1.1.2 toolchain (GCC 14.3), cmake/riscv64-spacemit-linux-gnu-gcc.cmake, GGML_SPACEMIT=ON, GGML_RV_ZBA=ON, GGML_OPENMP=OFF, Spert 0.6.3 and SpacemiT ORT 2.0.6. Build target: cmake --build <build> --target ggml-spacemit --parallel 24. Backend DSO SHA-256: 2a892969db4eb878d3e3b49c615207a07a8349db5b7b6751a4df5eb4a0255c90. Source hashes were checked before/after the build and against the committed files.

Reproduce with SPACEMIT0/TCM, Q6_K weights [K=256,N=65], F32 activations [256,M=1], and an independent CPU-only reference. The earlier backend returned NaN at column 64. Repeat at M=4 to exercise the last-tile store boundary. Numerical acceptance: NMSE <= 5e-4 over the complete output.

Archived K3-179 results:

Revision stage Result Detail
Before fix 16/20 Includes Q6_K M1/K256/N65 NaN
Copy-only intermediate 22/24 Remaining Q8_0 and Q6_K M4/N65 failures
Both fixes, default schedule 24/24 All cases meet the independent-reference threshold
Both fixes, three experimental schedules 72/72 Historical extra coverage; optional schedules are not part of this PR

Cases include N=33/65/513/1025 and aligned controls, including M2/M4. Run labels: i8-tail-baseline-v38-board179-r1 and i8-gemv-tiles-v41-board179-r1. The archived corrected package contains the same two fixes; these results are carried forward, not fresh execution of the PR head.

Check Status Evidence / scope
Exact-source RISC-V backend build PASS Configuration and DSO identity above
Diff / scope / formatting checks PASS Backend-only; no test changes or new environment controls; git diff --check, UTF-8/LF and added-line whitespace
Original regression FAIL (historical baseline) 16/20, including a Q6_K NaN
Corrected operator cases PASS (historical) Default 24/24; all schedules 72/72; CPU reference, NMSE <= 5e-4
Final-head model correctness / performance NOT RUN No model-level claim; partial-tile traffic changes
Final-head board / additional platform coverage NOT RUN Historical target results are carried forward; no new final-head K3 or K1 run

Performance

No speedup is claimed. This fixes incomplete reads and out-of-bounds writes; copying physical padding may increase bytes transferred for a partial tile. A final-head model performance comparison is NOT RUN. The archived evidence is operator correctness evidence, not end-to-end model validation.

Risks and limits

The old 20-case and new 24-case totals are different suites, so they are not a same-denominator pass-rate comparison. Exact final-head target execution and affected model coverage remain pending. Coordinate the overlapping M4 store fix with #78.

The historical module comparisons used the common noMTP experimental baseline on top of 3f5ce5fd; this PR instead preserves upstream common MTP behavior. Historical results are not claimed as new measurements of the final independent head. Raw build/test/benchmark archives are retained privately and are not publicly attached; the cases, results, artifact identities and limits above are the reviewable record here. Exact-input model replay is not provided by these summaries. Required final-head target evidence remains pending; this submission requests review, not a waiver or a claim of merge readiness. No maintainer exception has been granted. CI status is separate from the local results above.

AI assistance and contributor responsibility

Codex assisted with source preparation, static review, local build/check execution, historical evidence analysis and this PR description. The contributor discussed the module design and explicitly requested publication. No unrecorded personal review, maintainer approval or target execution is asserted. The contributor remains responsible for reviewing the submitted code and claims and addressing review feedback.

@alex-spacemit
alex-spacemit merged commit a926ebd into spacemit-com:mtmd-backend Dec 4, 2026
13 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants