MCPcopy Create free account
hub / github.com/FlashSampling/FlashSampling / _local_reduce

Function _local_reduce

src/fused_mm_sampling/core.py:344–354  ·  view source on GitHub ↗

Reduce across V-tiles (dim=1) on this rank and adjust to global vocab indices.

(
    maxs: torch.Tensor,  # [num_samples, n_tiles, H]
    maxs_idx: torch.Tensor,  # [num_samples, n_tiles, H]
    vocab_start_index: int,
)

Source from the content-addressed store, hash-verified

342
343@torch.compile(fullgraph=True)
344def _local_reduce(
345 maxs: torch.Tensor, # [num_samples, n_tiles, H]
346 maxs_idx: torch.Tensor, # [num_samples, n_tiles, H]
347 vocab_start_index: int,
348) -> tuple[torch.Tensor, torch.Tensor]:
349 """Reduce across V-tiles (dim=1) on this rank and adjust to global vocab indices."""
350 idxs = maxs.max(dim=1).indices # [num_samples, H]
351 samples = maxs_idx.gather(1, idxs.unsqueeze(1)).squeeze(1) # [num_samples, H]
352 max_values = maxs.gather(1, idxs.unsqueeze(1)).squeeze(1) # [num_samples, H]
353 samples += vocab_start_index
354 return samples.T.contiguous(), max_values.T.contiguous() # [H, num_samples]
355
356
357def clip(low, high, x):

Callers 2

fused_mm_sample_tritonFunction · 0.85
tp_post_kernel_reduceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected