kernel: avoid partial Triton lazy initialization#4553
Conversation
Build Triton kernel handles under an explicit lock and publish them only after initialization completes. This avoids exposing partially initialized module state to concurrent first callers. Assisted-by: Claude Opus 4.7
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4553
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New FailuresAs of commit 1d28ff8 with merge base d1e0e2d ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review |
|
Claude finished @vkuzo's task in 1m 30s —— View job Code Review: avoid partial Triton lazy initialization
Nice fix. The core change is correct: replacing the A few observations: 1. Behavior change in Previously impls = _get_triton_impls()
if not impls.available:
raise AssertionError("unsupported without triton")This is a strict improvement (fail fast, clear message) and matches the pattern in 2. Both files raise 3. The
4. Optional: dedup the identical The Overall this looks correct and is a solid concurrency fix. Nothing blocking from my side — points 1 and 2 are the only ones I'd ask you to confirm are intentional. |
blockwise_quantization.pyandbsr_triton_ops.pyboth used a module-level_triton_initialized = Falseflag set toTruebefore the kernel handles were assigned. Under free-threaded Python, one thread can set the flag and yield during the slowimport triton, while another thread observes the flag set but the kernel globals stillNone.Replace the bool-flag pattern with a lock-guarded builder that publishes an immutable dataclass of the built handles only once construction completes, so callers either see nothing or the fully-built set.