segKI: registered per-module refresh callbacks for derived-weight caches (follow-up to #8602)

Aperta
#9,109 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Start by reading segki_refresh and the per-path injectors for GDN, attention, GLU, and lm_head, then inspect the backend op’s existing clear_glu_cat_cache handling. Register each injector’s callback on its module and make refresh dispatch registered callbacks plus the backend refresh_weights() hook. Done means the listed paths are registered, the sentinel callback test reaches dispatch, and the existing arena tests pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

Motivation

Follow-up to #8602. During review (@tohtana, #issuecomment) we found a bug class: segki_refresh() keeps a centralized, hardcoded list of derived-cache attribute names, while injections are installed distributedly by per-path installers. When a new injection path lands, its refresh entry can be forgotten:

  • The GLU-only path (_ki_dual_op on MLP modules) was missed by the _ki_gdn_op-only backend lookup — clear_glu_cat_cache() was never called for dense models, leaving the process-wide gate|up concat stale after an in-place weight sync (#8602 fixed the symptom in ed86967aa; the class remains).

Proposal

Each injector registers its own refresh callback at injection time, on the module it injects into. segki_refresh() becomes a pure dispatcher:

# at injection time — the installer holds exactly this module
def _register_refresh(module, fn):
    regs = getattr(module, "_ki_refresh_fns", None)
    if regs is None:
        regs = module._ki_refresh_fns = []
    regs.append(fn)

# segki_refresh: walk the tree, call whatever is registered
def segki_refresh(model):
    for m in model.modules():
        for fn in getattr(m, "_ki_refresh_fns", ()):
            fn(m)
    # backend-side caches follow the same contract: op.refresh_weights()
    # (clear_glu_cat_cache becomes its alias / implementation)

New injection paths then cannot forget their refresh logic — registration is co-located with cache creation.

Why module-level (not a model-level registry)
  • Registration is natural: installers receive the leaf module (seg.parent); attaching the callback there is one line. A model-level registry would require threading the root reference through every installer.
  • Lifecycle is automatic: when a module is deleted/replaced (RL rollout rebuilds), its callbacks go with it — no stale entries.
  • Zero added cost: segki_refresh already traverses model.modules(); the traversal stays, only the action changes from attribute deletion to callback dispatch.
  • Consistent with existing idioms: the _ki_* attributes already live on modules; clear_glu_cat_cache already hangs off the backend op (hasattr discovery) — this generalizes that pattern to the Python side.
Composing with the end-state handshake

Per the #8602 discussion with @runguo-li, the eventual design is for weight syncs to write derived tensors directly as affine targets (#8575/#8706 fused target maps) — nothing derived, nothing to refresh. The registered-callback framework composes with that: an affine-written target simply registers a no-op. The registry is the robust interim contract, not the end state.

Scope

  • _register_refresh helper + registration at every existing injector (GDN, attention, GLU, lm_head)
  • segki_refresh rewritten as dispatcher (behavior identical; existing arena tests must pass unchanged)
  • Backend op grows a uniform refresh_weights() (alias clear_glu_cat_cache)
  • Test: an injector registering a sentinel callback proves dispatch reaches it (guards the forgotten-registration class structurally)
  • Update the PROVISIONAL docstring on segki_refresh / HybridEngineRollout.refresh_weights

Found while reviewing #8602.

Lingua principale
Python
Stelle
43.3k
Fork
5.1k
Merge medio
5g 10h
PR unite (30g)
85

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di deepspeedai/DeepSpeed

Tutte le issue di deepspeedai/DeepSpeed

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.