MCPcopy Index your code
hub / github.com/FlashSampling/FlashSampling / get_sampler

Function get_sampler

src/fused_mm_sampling/core.py:730–781  ·  view source on GitHub ↗
(provider: str, weights: torch.Tensor)

Source from the content-addressed store, hash-verified

728
729
730def get_sampler(provider: str, weights: torch.Tensor) -> Sampler:
731 match provider:
732 case S.fused_triton:
733 return SimpleSampler(lambda **kwargs: fused_mm_sample_triton(**{"seed": 0, **kwargs}))
734 case S.fused_triton_ret_logits:
735 return SimpleSampler(
736 lambda **kwargs: fused_mm_sample_triton(
737 **{"seed": 0, "return_logits": True, **kwargs}
738 )[0]
739 )
740 case S.fused_triton_greedy:
741 return SimpleSampler(
742 lambda **kwargs: fused_mm_sample_triton(
743 **{"seed": 0, "greedy_sampling": True, **kwargs}
744 )
745 )
746 case S.naive_pt:
747 return SimpleSampler(sample)
748 case S.naive_compiled:
749 return SimpleSampler(sample_compiled)
750 case S.pt_qitra:
751 return SimpleSampler(lambda **kwargs: sample(**kwargs, use_qitra=True))
752 case S.sequential_compiled:
753 return SimpleSampler(sequential_sample_pt)
754 case S.naive_tl_matmul:
755 return SimpleSampler(lambda **kwargs: sample_compiled(**kwargs, tl_matmul=True))
756 case S.jl_compiled:
757 return JLSampler.from_weights(weights)
758 case S.fused_topk:
759 from .tl_fused_mm_topk import fused_mm_topk_and_sample
760
761 return SimpleSampler(fused_mm_topk_and_sample)
762 case S.flashinfer_top_k_top_p_sampling_from_logits:
763 return SimpleSampler(
764 lambda **kwargs: flashinfer_top_k_top_p_sampling_from_logits(
765 **_default_top_k_top_p(kwargs),
766 )
767 )
768 case S.fused_cuda:
769 from .cuda_impl import fused_mm_sample_cuda
770
771 return SimpleSampler(fused_mm_sample_cuda)
772 case S.helion:
773 from .helion_impl import fused_mm_sample_helion
774
775 return SimpleSampler(fused_mm_sample_helion)
776 case S.flashinfer_sampling_from_logits:
777 return SimpleSampler(flashinfer_sampling_from_logits)
778 case S.greedy_baseline:
779 return SimpleSampler(greedy_sample_compiled)
780 case _:
781 raise NotImplementedError(f"Unknown provider: {provider}")
782
783
784def _default_top_k_top_p(kwargs: dict) -> dict:

Callers 7

test_top_k_top_pFunction · 0.90
verify_greedy_tp2Function · 0.85
_run_benchmarkFunction · 0.85
_prepare_caseFunction · 0.85
nvbench_kernelFunction · 0.85

Calls 7

SimpleSamplerClass · 0.85
fused_mm_sample_tritonFunction · 0.85
sampleFunction · 0.85
sample_compiledFunction · 0.85
_default_top_k_top_pFunction · 0.85
from_weightsMethod · 0.80

Tested by 6

test_top_k_top_pFunction · 0.72
verify_greedy_tp2Function · 0.68
_prepare_caseFunction · 0.68
nvbench_kernelFunction · 0.68