Skip to content

[RFC] Batch-Invariant RL Kernel Suite for Train-Inference Consistency #101

Description

@inaniloquentee

This RFC defines the batch-invariance contract for RL-Kernel's train-inference consistency suite.

The target identity is:

same model + same token sequence + same policy state
=> aligned logprobs / hidden states regardless of surrounding batch shape

This is the P0.3 roadmap item from #83. It is broader than the CUDA deterministic logprob kernel in #96: #96 is one concrete operator path, while this RFC should define the cross-kernel and cross-engine contract that rollout and training backends must satisfy.

Problem

RL rollout and training rarely execute the same sequence in the same shape:

  • rollout engines use dynamic batching, chunked prefill, paged KV, and prefix cache;
  • reference/reward scoring may use different packing and padding layouts;
  • training engines use micro-batches, gradient accumulation, FSDP/TP partitioning, and different row order;
  • kernel dispatch may choose different CUDA/ROCm/Triton implementations by shape or hardware.

Small logprob drift can be amplified by GRPO/PPO ratio and KL terms. The suite should make drift visible and locate whether it comes from logprob reduction, attention/prefix reuse, packing layout, TP reduction, dtype rounding, or engine integration.

Scope

Define the expected invariance contract for the same logical sequence across:

  • batch size changes: B=1 / small batch / large batch;
  • batch position changes and unrelated neighboring samples;
  • chunked prefill on/off;
  • prefix cache on/off;
  • padding layout and varlen packing changes;
  • dense vs indexed selected-logprob paths;
  • CUDA / ROCm / Triton backend parity, with backend-specific tolerance policy where bitwise identity is not realistic;
  • rollout engines such as vLLM/sglang vs training engines such as Megatron/DeepSpeed/FSDP.

Questions To Resolve

  • Which outputs require bitwise identity, and which require explicit tolerance?
  • What is the canonical fixture format for prompt, completion, token ids, position ids, masks, cache metadata, and policy state?
  • Which kernels are included in the first suite: selected logprob, attention with exported LSE, prefix-shared attention, sampling, loss reductions?
  • How should failures report the first divergent layer/operator?
  • How should TP>1 reductions compare against FSDP(TP=1)?
  • What command should contributors run locally before opening PRs?
  • Which checks belong in CI, and which require GPU/nightly/benchmark lanes?

Proposed Deliverables

  • RFC document describing the invariance contract and tolerance policy.
  • A reusable fixture generator for logically identical sequences under different batch/cache/layout configurations.
  • A batch-invariance test matrix for selected logprob and attention-adjacent paths.
  • A cross-engine benchmark plan comparing rollout logprobs with training logprobs.
  • A drift report format that includes max error, sequence id, token position, layer/operator, backend, dtype, and launch configuration.
  • Links to implementation issues for concrete kernels and tooling.

Acceptance Criteria

  • The RFC clearly separates bitwise-invariant requirements from tolerance-based parity requirements.
  • The RFC names the minimal P0 suite and the deferred P1/P2 extensions.
  • The RFC references Implement Batch-Invariant Deterministic LogProb CUDA Kernel to Eliminate Batch-Size Drift #96 as the CUDA deterministic selected-logprob implementation path.
  • The RFC defines at least one local command shape for contributors and one CI/nightly command shape for maintainers.
  • Follow-up issues can be opened directly from the RFC without re-litigating the contract.

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: kernelsTasks involving the development of CUDA and Triton underlying operatorscomponent: testingAdd test cases and benchmark-related tasksfeatureplatform: cudaSpecific optimizations or bugs in NVIDIA graphics cards (such as FlashInfer, TMA optimizations)platform: rocmSpecific tasks specific to AMD graphics cards (such as CK, bpreshuffle/FA)platform: tritonCross-platform Triton kernel related taskspriority: highSevere congestion issues require the highest priority for resolution.type: designIssues requiring in-depth discussion of architecture design

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions