Skip to content

docs: add segKI design guide (and align implementation) - #9130

Open
delock wants to merge 4 commits into
masterfrom
gma/segki-design-doc
Open

delock wants to merge 4 commits into
masterfrom
gma/segki-design-doc

Conversation

@delock

@delock delock commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds the segKI design document at deepspeed/module_inject/segki_design.md, next to its implementation (segment_ki.py, kernel_reference.py). Starts as a doc-only change (one new file); commit 3 additionally makes refresh_weights a real opbuilder contract in code — see Update below.

The segKI implementation has already merged; per the document's own rule — the implementation must stay in sync with it — this lands the accompanying design guide so agents and humans modifying segKI can read the contracts (opbuilder boundary, kernel_reference executable spec, refresh_weights, lineage and extension policies) before making changes.

The document was previously drafted on the gma/segki-design branch; this is its submission after PR #8602 merged, as noted in the doc header. Supersedes #9129.

Update: refresh_weights is now the enforced contract (commits 3-4)

Codex review on this PR flagged two doc-vs-code drifts, both fixed:

  1. refresh_weights was only a paper contract. The doc promised a
    uniform refresh_weights() opbuilder method ("clear_glu_cat_cache is
    its alias"), but segki_refresh() hardcoded the backend-internal
    clear_glu_cat_cache hook — a new backend following the doc would
    silently serve stale derived caches after an in-place weight sync.
    Now enforced end to end:
    • fused_glu.cu exposes refresh_weights() (drops the backend-owned
      GLU concat cache; clear_glu_cat_cache stays internal);
    • segki_refresh() collects every injected opbuilder handle
      (_ki_gdn_op, _ki_dual_op) and calls refresh_weights() on each
      distinct handle — no backend-internal hook names in the dispatcher;
      a stateless backend omits the method and is skipped;
    • §2.1/§2.4 of the design doc updated to match;
    • new TestSegkiRefreshDispatcher unit tests (CPU-safe) cover
      per-handle dispatch, stateless skip, and Python-side cache drops.
  2. §2.2 mis-stated kernel_reference coverage. The file holds 5
    compute-method references plus 2 glue ops; gdn_recurrent_step (FLA's
    public API) and decode_step_graph (contract tests) intentionally have
    no function there. §2.2 now says so and names the executable oracle for
    each.

Lands the segKI design document next to its implementation
(segment_ki.py, kernel_reference.py). The segKI implementation has
already merged; this ships the accompanying design contract so agents
and humans modifying segKI read the boundary, refresh_weights, lineage
and extension policies before making changes.

Signed-off-by: Guokai Ma <guokai.ma@intel.com>
@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T00:06:21.914535Z 10267b6 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.

@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 20, 2026
segKI and PR #8602 have merged; the draft/submission note no longer
applies.

Signed-off-by: Guokai Ma <guokai.ma@intel.com>

@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: 10267b6553

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread deepspeed/module_inject/segki_design.md Resolved
Comment thread deepspeed/module_inject/segki_design.md Resolved
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. and removed skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. labels Nov 20, 2026
@delock

delock commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator Author

@jinyouzhi @nathon-lee @anyadontfly @LiRunGuo hoping to get your comments on this design doc. I hope we can build a design doc on segKI together that alignes with your planned optimizations on HybridEngineRollout. Thanks!

Codex review on #9130 flagged that the design doc promised a
refresh_weights() opbuilder contract while segki_refresh() still
hardcoded the backend-internal clear_glu_cat_cache hook, so a new
backend following the doc would silently serve stale derived caches.

- fused_glu.cu: expose refresh_weights() (drops the backend-owned GLU
  concat cache); clear_glu_cat_cache stays internal.
- segment_ki.py: segki_refresh() collects every injected opbuilder
  handle (_ki_gdn_op, _ki_dual_op) and calls refresh_weights() on each
  distinct handle; no backend-internal hook names remain in the
  dispatcher; a stateless backend omits the method and is skipped.
- segki_design.md: refresh_weights is the contract (§2.1); §2.4 drops
  the not-yet-true 'alias' wording and describes the dispatcher walk.
- tests: dispatcher contract unit tests (per-handle call, stateless
  skip, python-side cache drop).

Signed-off-by: Guokai Ma <guokai.ma@intel.com>
Codex review on #9130: §2.2 claimed 'exactly 7 functions, one per
compute interface method', but the file holds 5 compute-method
references plus 2 glue ops, and gdn_recurrent_step / decode_step_graph
have no function there at all — contradicting the porting instruction
to treat those 7 functions as the whole math contract. State the real
coverage and name the executable oracle for each of the two missing
methods (FLA's public API; the decode_step_graph contract tests).

Signed-off-by: Guokai Ma <guokai.ma@intel.com>
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. and removed skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. labels Nov 20, 2026
@delock delock changed the title docs: add segKI design guide docs: add segKI design guide (and align implementation) Nov 20, 2026
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. and removed skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. labels Nov 20, 2026
@delock

delock commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed two commits addressing both Codex findings:

1. refresh_weights is now the real contract (966aba2) — code + doc + tests:

  • fused_glu.cu: exposes refresh_weights() (drops the backend-owned GLU concat cache; clear_glu_cat_cache remains an internal detail).
  • segment_ki.py: segki_refresh() is now a pure dispatcher — it collects every injected opbuilder handle (_ki_gdn_op, _ki_dual_op) and calls refresh_weights() on each distinct handle via hasattr discovery. No backend-internal hook names in the dispatcher; a stateless backend omits the method and is skipped.
  • segki_design.md §2.1/§2.4: refresh_weights documented as the enforced mgmt contract; the not-yet-true "alias" wording removed.
  • New TestSegkiRefreshDispatcher (CPU-safe): per-handle dispatch, stateless skip, Python-side cache drop.

2. §2.2 kernel_reference coverage stated accurately (2663f02) — doc-only: the file holds 5 compute-method references + 2 glue ops; gdn_recurrent_step (oracle: FLA's public API) and decode_step_graph (oracle: the decode_step_graph contract tests) intentionally have no function there — §2.2 now says so and names each oracle.

CI re-running; pre-commit and the CPU test classes pass locally.

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