In DSpark the CPU scheduler fixes only the total verification budget; the per-sequence draft lengths are computed on the GPU from the confidence head's outputs after the step's forward pass. Write the kernel that turns a row of per-draft confidences into cumulative acceptance probabilities and the length of the prefix whose probabilities clear a threshold.
Required kernel and wrappers:
@triton.jit
def confidence_prefix_kernel(conf_ptr, cum_ptr, len_ptr, D, threshold,
stride_cr, stride_cd, stride_ur, stride_ud):
def confidence_prefix(conf: torch.Tensor, threshold: float):
def plan_with_budget(conf: torch.Tensor, budget: int):
conf is (R, D) float32 on the GPU with D >= 1. One program per row. The program walks positions 0, 1, ..., D - 1 in order with a running product, stores each running product into cum[r, j], and counts how many of them are >= threshold. Because the products never increase along the row, that count is the length of the qualifying prefix. Store it into lengths[r] as int32.confidence_prefix launches the kernel on a grid of R programs and returns (cum, lengths) with cum float32 (R, D) and lengths int32 (R,).plan_with_budget returns (lengths, threshold): run the kernel once with a threshold of 0 to obtain cum, take the budget-th largest value of cum (over all R * D entries, with budget capped at R * D) as the threshold, run the kernel again with it, and return the resulting lengths and the threshold as a Python float. With distinct values the lengths sum to the budget.0 before the loop so the loop-carried value has a fixed type; store it and count it before entering for j in range(1, D).(acc >= threshold).to(tl.int32) and accumulate the count as an int32 scalar.torch.topk(cum.flatten(), k).values[-1].