Skip to content

test(accel): add KIVI reference implementation and CPU boundary regressions - #658

Open
DoubleCore wants to merge 2 commits into
inclusionAI:mainfrom
DoubleCore:issue-590-kivi-verify
Open

DoubleCore wants to merge 2 commits into
inclusionAI:mainfrom
DoubleCore:issue-590-kivi-verify

Conversation

@DoubleCore

Copy link
Copy Markdown

Adds an independent CPU reference implementation for KIVI-style 2-bit KV cache quantization and boundary regression tests.

This is an incremental verification artifact and does not modify the mainline implementation (PR #641).

What is covered

  • Per-channel key quantization / per-token value quantization round-trip
  • Residual window empty / partially full / full transitions
  • Cache reset clears all state
  • Unsupported attention types raise instead of silently degrading
  • Numerical deviation upper bound vs BF16 baseline

Verification

C:/Users/AORUS/anaconda3/python -m pytest tests/test_kivi_reference_cpu.py -q → 25 passed

Not covered

CUDA memory savings and real-hardware throughput (CPU-only environment). Flagged explicitly in the report at docs/dev/kivi-reference-verification.rst.

Refs #590

…ssions

Refs inclusionAI#590. Incremental verification artifact: CPU-only reference implementation plus regression tests. Does not modify the mainline implementation.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T13:26:37.327826Z b1a21d8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b1a21d88b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


.. code-block:: console

C:/Users/AORUS/anaconda3/python -m pytest tests/test_kivi_reference_cpu.py -q

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Replace the workstation-specific interpreter path

On Linux or any workstation without this particular Windows Anaconda installation, the documented reproduction command cannot launch the tests. Replace the absolute interpreter path with an environment-selected interpreter, such as python, so contributors can reproduce the verification. The root AGENTS.md explicitly prohibits hardcoded absolute paths.

AGENTS.md reference: AGENTS.md:L35-L35

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 83df034: the reproduction command now uses python. CPU-only verification: python -m pytest tests/test_kivi_reference_cpu.py -q passed all 26 tests on torch 2.7.1+cpu with CUDA unavailable.

Comment on lines +241 to +244
self._value_blocks.append(
quantize_value_per_token(
values[:, :, start:stop], bits=self.bits, group_size=self.group_size
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject incompatible head dimensions before mutating the cache

With group_size=4, residual_length=2, and head_dim=3, appending two tokens succeeds, but appending four more adds a key block before this value quantizer raises because the head dimension is not divisible by the group size. The failed update leaves num_tokens == 2, quantized_tokens == 4, and no corresponding value block, so materialize() subsequently returns different key/value lengths. Validate head-dimension divisibility in _validate_update before changing metadata or block lists.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 83df034. _validate_update now rejects a head_dim that is not divisible by group_size before metadata or block lists are mutated. The new regression test verifies that rejection leaves token counts, block lists, residual state, and empty-cache materialization behavior unchanged. CPU-only suite: 26 passed; no GPU validation was performed.

@DoubleCore

Copy link
Copy Markdown
Author

Implemented both review fixes in 83df034.

  • The verification command now uses the active environment's python.
  • _validate_update rejects incompatible head_dim values before any cache metadata or block-list mutation.
  • Added a regression test covering unchanged cache state after rejection: zero tokens, no blocks or residual state, and empty-cache materialization behavior.

CPU-only verification with torch 2.7.1+cpu (CUDA unavailable):

  • python -m pytest tests/test_kivi_reference_cpu.py -q — 26 passed.

No GPU/CUDA validation was performed.

This branch has not been deployed

No deployments
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.

1 participant