| 728 | |
| 729 | |
| 730 | def 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 | |
| 784 | def _default_top_k_top_p(kwargs: dict) -> dict: |