Repository navigation
feat(adaln): add indexed CUDA/Triton modulation and explicit strict qualification - #621
Conversation
Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
…n Fixes - Updated CUDA kernel functions to accept a configurable number of threads (128, 256, or 512) for improved flexibility. - Added synchronization after reading the reduction result in the fixed_sum function to prevent shared memory hazards. - Modified the Python bindings and C++ interface to accommodate the new threads parameter in forward and backward functions. - Enhanced documentation to include the new thread configuration options. - Implemented additional tests to validate the behavior of the AdaLN modulation with different thread configurations and ensure numerical stability. - Introduced a race condition check script to validate shared memory access in CUDA kernels. Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
…type support Signed-off-by: hongleng-github <[email protected]>
…t sensitivity tests Signed-off-by: hongleng-github <[email protected]>
- Deleted installation script for CUDA 12.6 on WSL. - Removed verification script for CUDA 12.6 installation. - Eliminated build extension script for CUDA-related extensions. - Removed testing scripts for AdaLN CUDA extension. - Deleted benchmarking script for AdaLN CUDA operations. - Removed race checking script for AdaLN CUDA extension. Signed-off-by: hongleng-github <[email protected]>
…servation - Introduced strict dispatch and execution observations for AdaLN modulation, enforcing arithmetic profiles and backend qualifications. - Added `AdaLNDispatch` class to manage execution traces and backend information. - Updated `KernelRegistry` to support strict mode and handle arithmetic profiles. - Enhanced backend provenance tracking in GTest to validate execution against declared profiles. - Created tests for strict dispatch behavior, including validation of backend observations and error handling for unsupported profiles. - Added benchmark tests for CPU checks and CLI contract validation. - Refactored existing tests to ensure compatibility with new dispatch and backend observation mechanisms. Signed-off-by: hongleng-github <[email protected]>
Rebase the existing AdaLN work onto fixed test-qwenimage revision 16b8117. Move reference, backends, dispatch, tests and benchmark into their canonical owners; preserve legacy module and stable operator identity, arithmetic, independent gold and shared precision thresholds. Validation: 229 CPU-focused tests passed, 302 hardware/opt-in tests skipped; focused mypy, Ruff and BF16 H3072 forward/backward CLI passed. GPU builds, H100 tests, sanitizer, benchmarks and the repository-wide suite remain manual; updated commands are documented. Signed-off-by: hongleng-github <[email protected]>
Delete the five AdaLN import/benchmark shims and their compatibility checks. Remove AdaLN-only local migration and identity aliases while keeping upstream compatibility and canonical implementations unchanged. Validation: focused CPU regression 223 passed, 302 skipped; BF16 H3072 CPU forward/backward CLI, Ruff and diff checks passed. Migrated ten external local scripts, including a CPU-only probe (4 passed). GPU/H100 and full-repository validation were not run. Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
…ipeline Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
…backward_reduce_kernel Signed-off-by: hongleng-github <[email protected]>
…lculation Signed-off-by: hongleng-github <[email protected]>
…act validation Signed-off-by: hongleng-github <[email protected]>
…n logic Signed-off-by: hongleng-github <[email protected]>
… for strict rejection Signed-off-by: hongleng-github <[email protected]>
Remove automatic AdaLN provenance observation and retain generic trace snapshots, FP32 reference inputs and output dtype checks. Preserve comparison on the original device when candidate and gold share it. Validation: op_checks 19 passed; AdaLN subset 333 passed; targeted mypy and Ruff passed. Full pytest stopped during collection on an unchanged ROCm import of _AITER_FWD_REQUIRED_KEYWORDS. Signed-off-by: hongleng-github <[email protected]>
Restore non-AdaLN gold and candidate paths and unrelated import formatting to the fixed integration baseline. Preserve AdaLN registration, precision settings, independent reference and optional backend observation. Validation: 65 focused tests passed; mypy, Ruff and diff checks passed. Both review axes reported no findings. Full pytest stopped during collection on the existing ROCm _AITER_FWD_REQUIRED_KEYWORDS import error. Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
Apply the test-only layout update from parent PR RL-Align#559 commit 38352b0. Move resolver and fallback policy cases into tests/runtime while retaining operator accuracy and invariance cases in tests/ops. Preserve existing test names, assertions and decorators. Signed-off-by: hongleng-github <[email protected]>
Route supported B2/S8/H2 FP32 inputs with int32 indices through dedicated CUDA kernels. Preserve explicit framework fallback outside the slice and keep indexed strict execution rejected. Add an independent CPU byte reference, literal VJP and token-order checks, and direct backend plus public dispatch coverage. Share FP32 eps eligibility and indexed trace construction, and isolate NVIDIA-only tests from ROCm. Validation: bounded CPU-only regression passed with 135 passed and 305 skipped; targeted Ruff and diff checks passed. Historical SM86 evidence predates the Python refactors; current-source GPU acceptance, full-extension linkage, H100 and strict qualification remain pending. Signed-off-by: hongleng-github <[email protected]>
|
Follow-up on the shared Triton Checked against Triton 3.7.1. An offline SM90a compilation comparison produced identical cubins with the flag enabled and disabled for the checked FP32/BF16 configurations. Both use FP32 I don't see a numerical defect here. The missing flag could be added for consistency, but it is not a required correctness fix. |
|
Follow-up on the index-validation stream claim in the OCR summary: I checked the generated ATen wrappers in Torch 2.12.1. The validation operations select the tensor's CUDA device and use its current stream, rather than unconditionally running on the default stream. The I'll keep the current ordering and checks. |
Signed-off-by: hongleng-github <[email protected]>
359d274 to
496324d
Compare
|
Follow-up on two findings in the latest OCR summary, checked against
|
Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
Signed-off-by: hongleng-github <[email protected]>
|
Regarding the CUDA accumulation-order finding in the OCR summary: The retained H100 build used source Interleaving independent shift/scale chains does not change either chain's summation order. The recorded shared FP32 byte comparisons and indexed cancellation/product-rounding tests passed. The CUDA source is unchanged at |
|
please resolve the conflicts first, thx @hongleng |
| "csrc/cuda/activation/activation.cu", | ||
| "csrc/cuda/attention/deterministic_attention.cu", | ||
| ] | ||
| adaln_cuda_enabled = not is_rocm and not envs.env_flag(envs.KERNEL_ALIGN_USE_FAST_MATH) |
There was a problem hiding this comment.
The native AdaLN gate only checks KERNEL_ALIGN_USE_FAST_MATH and ignores externally supplied relaxed-math NVCC flags (NVCC_PREPEND_FLAGS/NVCC_APPEND_FLAGS/TORCH_NVCC_FLAGS). With e.g. NVCC_APPEND_FLAGS=--use_fast_math, csrc/cuda/norm/adaln_modulation.cu is still compiled and its #if defined(__CUDA_FAST_MATH__) #error (line 13) aborts the build; with --ftz=true/--prec-div=false the build succeeds but AdaLN's FP32 pairwise-tree results no longer match the exact reference (the doc claims no fast math). This is inconsistent with the joint_attn_softmax_enabled gating immediately below. Reuse the already-computed use_fast_math/relaxed_math_env values.
Suggestion:
| adaln_cuda_enabled = not is_rocm and not envs.env_flag(envs.KERNEL_ALIGN_USE_FAST_MATH) | |
| adaln_cuda_enabled = not is_rocm and not use_fast_math and not relaxed_math_env |
…L-Align#538 Resolve additive conflicts in build_tools/extensions.py, csrc/bindings/ops.cpp and rl_engine/runtime/registry.py by keeping both the final_adaln_out (token_sum) entries and the upstream latent pack/unpack entries. Signed-off-by: Wenbo Ji <[email protected]>
The pytest node IDs in tests/runtime/test_adaln_test_environments.py (from RL-Align#621 on test-qwenimage) exceeded the 100-character limit, so the linting job failed and unit-tests was skipped. Build them from per-module prefixes; the selected tests are unchanged. Signed-off-by: Wenbo Ji <[email protected]>
Summary
Add dedicated CUDA and NVIDIA Triton FP32/BF16 forward/backward for indexed AdaLN, extending the shared implementation in #559. Each token selects one of two per-sample modulation banks, applies parameter-free LayerNorm followed by scale/shift, and returns the selected gate separately.
Backend dispatch selects CUDA, Triton, or the existing framework select01 fallback according to availability and supported input domains. Valid inputs outside the dedicated backend domain retain ordinary fallback.
Implementation
[2B,3H]and Boolean/integer 0/1 routes[B,S]or batch-broadcast[1,S]. Return modulated output and gate[B,S,H], with gradients to the input and both modulation banks.See the operator contract at this PR revision for the full numerical and dispatch behavior.
Validation & Performance
H100 NVL/SM90 validation recorded 720 correctness node calls and 1,408 sanitizer node calls, including CPU policy/boundary checks. All recorded phases passed, with no skips/xfails. Both backends were checked with memcheck, racecheck, initcheck and synccheck, with no reported errors, hazards or warnings in the tested configurations. These tools ran locked small-matrix subsets at default launch settings; H3072 workloads and alternate launch settings have separate correctness coverage.
Correctness checks cover independent output/gradient accuracy, fixed bytes, routing, views, upstream semantics, large offsets, H3072 workloads, shared regressions and explicit strict activation.
The indexed benchmark covers 18 cases across FP32/BF16, small inputs and H3072 image workloads. Warm wall-time speedups against framework select01 are ranges of per-case median ratios:
These are whole-call measurements from one successful process using
eps=7, including applicable validation, copies, allocations and autograd. Latency and memory gains vary by case; the linked performance report contains sample variation, memory tradeoffs and first-use/JIT costs. These are operator-level measurements rather than model-level training benchmarks.The published GPU results apply to source
5490223a850fe9cb1efd5c3cceeb0fb964ee5c1c. Current HEAD496324dadditionally includes formatting, device-context guards for shared/indexed Triton forward launches, CLI backend reporting, and test coverage for optional and required extensions; kernel arithmetic is unchanged. Focused CPU checks for the device-guard follow-up recorded 70 passed / 42 skipped with GPUs hidden. The subsequent changes have not been revalidated on H100, and the new two-GPU regression remains unexecuted.Dependencies & Limitations
#559 remains open. This PR targets
test-qwenimage, so its diff includes the shared parent implementation.The GPU evidence uses a fresh AdaLN-only extension built from production sources/bindings in the recorded H100 environment; full-extension build/link integration remains unvalidated.
Indexed strict qualification remains default-closed. Execution requires an explicit backend/target/runtime scope following external evidence review; the published qualification record does not activate it.
Evidence
Merge Danger
Door: two-way
Reverting removes the operator/backend additions; no persisted data migration is involved.
Blast Radius: operators
Adds native symbols and AdaLN runtime/validation paths, including the shared parent changes. Valid unsupported indexed inputs retain explicit ordinary fallback; strict rejects unqualified execution. Successful-forward trace metadata is not backward, profiler or binary-attestation evidence. Evidence is linked above. Qualification evidence acceptance is limited to the disclosed target/build/matrix; no runtime scope is installed or enabled by this PR.
Summary by CodeRabbit