diff --git a/ignition/components/flashinfer_sampling.py b/ignition/components/flashinfer_sampling.py index 3e655d8b0..9f298d4df 100644 --- a/ignition/components/flashinfer_sampling.py +++ b/ignition/components/flashinfer_sampling.py @@ -37,6 +37,15 @@ def sample_probabilities(probabilities, seed, offset, return_valid=False): deterministic=True, check_nan=False, return_valid=return_valid) +@torch.compiler.allow_in_graph +def sample_probabilities_out(probabilities, samples, valid, seed, offset, *, row_independent_rng=False): + """Sample every row in one launch directly into caller-owned output buffers.""" + sampling.get_sampling_module() + torch.ops.flashinfer.sampling_from_probs_out( + probabilities, samples, valid, None, True, seed, 0, offset, 0, row_independent_rng + ) + + @torch.compiler.allow_in_graph def verify_chain(draft_probs, draft_ids, target_probs, accepted, emitted, seed, offset): # Each row draws from its own seed and offset only, so its tokens do not depend on its batch slot. diff --git a/ignition/components/sampling.py b/ignition/components/sampling.py index ece253a9e..3aa780897 100644 --- a/ignition/components/sampling.py +++ b/ignition/components/sampling.py @@ -21,7 +21,11 @@ from .completion import CompletionOutputs, completion_record_capacity from .logprobs import PreparedLogprobs from .capacity import MAX_CONCURRENCY -from .flashinfer_sampling import filter_probabilities_out, probability_filter_workspace, sample_probabilities +from .flashinfer_sampling import ( + filter_probabilities_out, + probability_filter_workspace, + sample_probabilities_out, +) from ignition.preparation.persistent import persistent_copy, persistent_empty from ignition.preparation.scratch import bind_scratch @@ -589,12 +593,8 @@ def launch(operation): num_warps=4, enable_fp_fusion=False) torch.sum(probabilities, dim=-1, keepdim=True, out=scratch["probability_mass"]) launch(self._normalize) - for row in range(self._rows): - sampled, valid = sample_probabilities(probabilities[row:row + 1], - seed=scratch["packed_seed"][row:row + 1], offset=scratch["packed_offset"][row:row + 1], - return_valid=True) - scratch["sampled_tokens"][row:row + 1].copy_(sampled) - scratch["sample_valid"][row:row + 1].copy_(valid) + sample_probabilities_out(probabilities, scratch["sampled_tokens"], scratch["sample_valid"], + seed=scratch["packed_seed"], offset=scratch["packed_offset"], row_independent_rng=True) def __call__(self) -> None: if not self._prepared: diff --git a/pyproject.toml b/pyproject.toml index d8717dbbd..e03a2529c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,7 @@ explicit = true torch = { index = "pytorch-cu132" } torchvision = { index = "pytorch-cu132" } flare-heliopause = { path = "heliopause" } -flashinfer-python = { git = "https://github.com/local-inference-lab/flashinfer.git", branch = "main" } +flashinfer-python = { git = "https://github.com/local-inference-lab/flashinfer.git", rev = "5a8ceed80ccc58e11a4d49ccc910f52967699c09" } [tool.setuptools.packages.find] include = ["ignition*"]