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

Abierto
#9,109 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, pytorch

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
43.3k
Forks
5.1k
Merge medio
5 d 10 h
PR fusionados (30 d)
85

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de deepspeedai/DeepSpeed

Todos los issues de deepspeedai/DeepSpeed

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.