Skip to content

DivergentHF: fix off-by-one in sequence selector (0-based kernel) - #2

Merged
johnnynunez merged 1 commit into
mainfrom
fix/divergent-hf-selector-offbyone
Jun 24, 2026
Merged

DivergentHF: fix off-by-one in sequence selector (0-based kernel)#2
johnnynunez merged 1 commit into
mainfrom
fix/divergent-hf-selector-offbyone

Conversation

@johnnynunez

Copy link
Copy Markdown
Owner

Qué arregla

Las 3 fallas de test_batch_divergent_hf (DivergentHF: …) que existían en main. En los tres casos el plano 0 ejecutaba la secuencia equivocada.

Causa raíz — off-by-one en el selector

DivergentBatchTransformDPP es 0-based: exec() llama a divergent_operate<0>(z, seqs...) y ejecuta la secuencia cuya posición 0-based coincide con at(z) (data_parallel_patterns.h). El selector del test de regresión upstream lo confirma: MySelector::at devuelve index==0?0u:1u, es decir, at=0 elige la PRIMERA secuencia.

DivergentKernel._selector_cpp (jit.py) emitía el plane_map 1-based tal cual, así que at(0)=1 seleccionaba la SEGUNDA secuencia para el plano 0 → de ahí el desfase en los 3 tests.

Fix

  • compose_divergent mantiene el plane_map 1-based en la API (legible); el selector ahora emite (s-1).
  • Corregido el comentario que citaba circular_tensor.h::SequenceSelectorType como "1-based convention" — es otro contrato de selector, no aplica a este kernel.
  • Añadido sv=2 a la firma de caché del divergente para no reusar .so obsoletas del selector buggeado.

Verificación (RTX PRO 6000 sm_120, nvcc 13.3)

  • test_batch_divergent_hf: 12/12 (antes 9/12).
  • Sin regresiones: circular_tensor (usa el otro selector, SequenceSelectorType), horizontal_fusion y e2e siguen verdes.

Nota: este fix se desarrolló sobre la rama del #1 pero se empujó después de que se mergeara, por eso va en un PR propio sobre main ya actualizado.

The 3 failing DivergentHF tests were an off-by-one: plane 0 always ran the
wrong sequence. DivergentBatchTransformDPP is 0-BASED — exec() calls
divergent_operate<0>(z, seqs...) and runs the sequence whose 0-based position
equals at(z) (data_parallel_patterns.h; the upstream regression test selector
returns index==0?0u:1u, i.e. 0 picks the FIRST sequence). _selector_cpp was
emitting the 1-based plane_map verbatim, so at(0)=1 selected the SECOND
sequence for plane 0.

compose_divergent keeps the readable 1-based plane_map at the API; the
selector now emits (s-1). The stale comment citing circular_tensor.h's
SequenceSelectorType as '1-based convention' was wrong for this kernel (that
is a different selector contract) — corrected.

Added sv=2 to the divergent cache signature so stale .so files from the
previous (buggy) selector are not reused.

test_batch_divergent_hf now 12/12 (was 9/12). circular/HF/e2e still green.
@johnnynunez
johnnynunez merged commit 3e58de4 into main Jun 24, 2026
5 checks passed
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