Skip to content

[FEAT][dispatcher]: implement unified kernel registry and enhanced logger - #2

Merged
Flink-ddd merged 1 commit into
mainfrom
feat/executor-dispatch
Feb 5, 2026
Merged

Flink-ddd merged 1 commit into
mainfrom
feat/executor-dispatch

Conversation

@Flink-ddd

Copy link
Copy Markdown
Collaborator

Description

This PR establishes the core infrastructure for RL-Engine, focusing on hardware-agnostic operator dispatching and industrial-grade logging.

Unified Logger: Patched logging.Logger with info_once and warn_once using MethodType and lru_cache.

Kernel Registry: Implemented a metadata-driven KernelRegistry for dynamic routing between ROCm and CUDA.

Robust Hardware Context: Fixed DeviceContext attribute initialization to support seamless CPU/GPU fallback.

Key Changes

rl_engine/utils/logger.py: Centralized logging utility with efficiency patches.
rl_engine/kernels/registry.py: Hardware-aware dispatcher with EnumMeta safety.
rl_engine/platforms/device.py: Integrated centralized logger and improved device detection.
rl_engine/executors/rollout.py: Decoupled execution logic from specific kernel backends.

Test Results

Verified via tests/test_dispatch.py:
Logger info_once suppression works correctly.
Hardware detection correctly identifies CPU/CUDA/ROCm.
RolloutExecutor successfully dispatches kernels based on platform.

@Flink-ddd
Flink-ddd merged commit 5861344 into main Feb 5, 2026
@Flink-ddd Flink-ddd added the enhancement New feature or request label Feb 5, 2026
@Flink-ddd Flink-ddd assigned Flink-ddd and unassigned Flink-ddd Feb 5, 2026
Zhifu-Liu added a commit to Zhifu-Liu/RL-Kernel that referenced this pull request Jun 30, 2026
zhangj1an added a commit that referenced this pull request Sep 3, 2026
…lars

Follow-up after reading the Megatron mHC source
(megatron/core/transformer/hyper_connection.py and
megatron/core/fusions/fused_mhc_kernels.py, dev).

Megatron's native and fused paths disagree with each other: the fused
kernel uses TF32 MMA, split_k=16 at K>=16384, and runtime autotuning,
and computes sqrt(s/K) where native computes sqrt(s)/sqrt(K). Three of
issue #2's explicit bans (Split-K off, TF32 off, fixed reduction tree)
are violated by that path at exactly the production shape. So Megatron
supplies the formulas and constants for this contract, never the
reduction order.

Changes:

- fusion: 'unfused' is now CANONICAL and documented as such. Train/infer
  byte-equality needs every boundary hashable on its own, which only the
  unfused decomposition gives. v1 does not reuse TE's
  TEFusedResidualRMSNorm -- it refuses to expose the intermediate (raises
  on any forward hook), collapsing two boundaries into one. Fusion stays
  legal; changing the reduction layout or a downcast point does not.
- alpha: Megatron holds three learnable scalars (alpha_pre/post/res)
  broadcast over the PRE/POST/COMB segments, not 24 independent gains.
  Forward was already equivalent; backward was not, so dAlpha is now
  three scalars with the segment fold pinned like every other reduction.
- design doc: new section on what Megatron actually does and why it is
  not the byte reference; D1/D6/D8 rewritten with the source evidence;
  open questions updated (Miles must also run unfused -- needs their
  sign-off).
- the fused/unfused test now says what it actually proves (oracle
  self-consistency, not that a real fused kernel matches).

54 tests pass; check_p1.py PASSes on cpu and cuda, stub still fails
closed; ruff/flake8/black/isort/mypy clean. Golden manifest regenerated.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kcu8vXve5YMZ5wqCCKRfvJ
zhangj1an added a commit that referenced this pull request Sep 3, 2026
Issue #2 splits P1 by function, not by operator: P1-D1 owns the mHC
forwards, P1-D2 the RMSNorm forwards, P1-D3 every custom backward across
both, P1-D4 the provider adapter, P1-D5 trace/tests/benchmarks and P1-D6
the fixed-K GEMM reference -- eight tasks with P1-S0 and P1-R0.

The kit had invented a one-task-per-operator split instead. That was
wrong in the design doc and, worse, in StubProvider's messages, which
told a developer to "claim it on P1-D1 (hc_split_sinkhorn)" and would
have pointed them at the wrong task.

- StubProvider now names the real owning task per (operator, direction);
  every *_bwd points at P1-D3.
- design doc: the eight tasks with owners, the dependency line, and a
  note that operators and tasks are different axes.
- provider docstring and tests updated to match.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kcu8vXve5YMZ5wqCCKRfvJ
zhangj1an added a commit that referenced this pull request Sep 3, 2026
#2 has eight GitHub sub-issues, and they are split one per operator --
not by function as the older 任务分工 section in the issue body reads.
The previous commit followed that superseded section and mislabelled
everything; this restores the operator split and uses the authoritative
issue numbers, matching how P5 labels its sub-tasks.

- P1-1 (#14) hc_split_sinkhorn, P1-2 (#15) fp32_gemm_rms, P1-3 (#16)
  mhc_post, P1-4 (#17) mhc_pre/h_aggregate, P1-5 (#18) rmsnorm_residual
  -- each fwd + bwd together; P1-6..P1-8 (#19-#21) are the WS2 TP/SP/CP/
  DP/PP tasks.
- #15 explicitly absorbs the fixed-K / batch-invariant GEMM reference and
  its equivalence harness, so fixed_k_gemm points there rather than at a
  task of its own.
- StubProvider names the owning sub-issue per operator.
- D8 reframed against #18's actual wording: it says prefer TE's
  TEFusedResidualRMSNorm and self-write only if TE fails the
  deterministic contract. TE fails it -- it refuses to expose the
  pre-normalization intermediate -- so unfused v1 is the escape hatch
  #18 provides, not a departure from it.
- design doc: the eight sub-issues with stage, issue number and the WS2
  attachment points (placement + check_capability).

54 tests pass; check_p1.py reference PASS, stub fails closed; lint clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kcu8vXve5YMZ5wqCCKRfvJ
zhangj1an added a commit that referenced this pull request Sep 3, 2026
…lars

Follow-up after reading the Megatron mHC source
(megatron/core/transformer/hyper_connection.py and
megatron/core/fusions/fused_mhc_kernels.py, dev).

Megatron's native and fused paths disagree with each other: the fused
kernel uses TF32 MMA, split_k=16 at K>=16384, and runtime autotuning,
and computes sqrt(s/K) where native computes sqrt(s)/sqrt(K). Three of
issue #2's explicit bans (Split-K off, TF32 off, fixed reduction tree)
are violated by that path at exactly the production shape. So Megatron
supplies the formulas and constants for this contract, never the
reduction order.

Changes:

- fusion: 'unfused' is now CANONICAL and documented as such. Train/infer
  byte-equality needs every boundary hashable on its own, which only the
  unfused decomposition gives. v1 does not reuse TE's
  TEFusedResidualRMSNorm -- it refuses to expose the intermediate (raises
  on any forward hook), collapsing two boundaries into one. Fusion stays
  legal; changing the reduction layout or a downcast point does not.
- alpha: Megatron holds three learnable scalars (alpha_pre/post/res)
  broadcast over the PRE/POST/COMB segments, not 24 independent gains.
  Forward was already equivalent; backward was not, so dAlpha is now
  three scalars with the segment fold pinned like every other reduction.
- design doc: new section on what Megatron actually does and why it is
  not the byte reference; D1/D6/D8 rewritten with the source evidence;
  open questions updated (Miles must also run unfused -- needs their
  sign-off).
- the fused/unfused test now says what it actually proves (oracle
  self-consistency, not that a real fused kernel matches).

54 tests pass; check_p1.py PASSes on cpu and cuda, stub still fails
closed; ruff/flake8/black/isort/mypy clean. Golden manifest regenerated.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kcu8vXve5YMZ5wqCCKRfvJ
zhangj1an added a commit that referenced this pull request Sep 3, 2026
Issue #2 splits P1 by function, not by operator: P1-D1 owns the mHC
forwards, P1-D2 the RMSNorm forwards, P1-D3 every custom backward across
both, P1-D4 the provider adapter, P1-D5 trace/tests/benchmarks and P1-D6
the fixed-K GEMM reference -- eight tasks with P1-S0 and P1-R0.

The kit had invented a one-task-per-operator split instead. That was
wrong in the design doc and, worse, in StubProvider's messages, which
told a developer to "claim it on P1-D1 (hc_split_sinkhorn)" and would
have pointed them at the wrong task.

- StubProvider now names the real owning task per (operator, direction);
  every *_bwd points at P1-D3.
- design doc: the eight tasks with owners, the dependency line, and a
  note that operators and tasks are different axes.
- provider docstring and tests updated to match.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kcu8vXve5YMZ5wqCCKRfvJ
zhangj1an added a commit that referenced this pull request Sep 3, 2026
#2 has eight GitHub sub-issues, and they are split one per operator --
not by function as the older 任务分工 section in the issue body reads.
The previous commit followed that superseded section and mislabelled
everything; this restores the operator split and uses the authoritative
issue numbers, matching how P5 labels its sub-tasks.

- P1-1 (#14) hc_split_sinkhorn, P1-2 (#15) fp32_gemm_rms, P1-3 (#16)
  mhc_post, P1-4 (#17) mhc_pre/h_aggregate, P1-5 (#18) rmsnorm_residual
  -- each fwd + bwd together; P1-6..P1-8 (#19-#21) are the WS2 TP/SP/CP/
  DP/PP tasks.
- #15 explicitly absorbs the fixed-K / batch-invariant GEMM reference and
  its equivalence harness, so fixed_k_gemm points there rather than at a
  task of its own.
- StubProvider names the owning sub-issue per operator.
- D8 reframed against #18's actual wording: it says prefer TE's
  TEFusedResidualRMSNorm and self-write only if TE fails the
  deterministic contract. TE fails it -- it refuses to expose the
  pre-normalization intermediate -- so unfused v1 is the escape hatch
  #18 provides, not a departure from it.
- design doc: the eight sub-issues with stage, issue number and the WS2
  attachment points (placement + check_capability).

54 tests pass; check_p1.py reference PASS, stub fails closed; lint clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kcu8vXve5YMZ5wqCCKRfvJ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant