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

Method sample

src/fused_mm_sampling/core.py:693–709  ·  view source on GitHub ↗

Sampling using low-dimensional random projections (Johnson-Lindenstrauss lemma).

(
        self,
        hidden_states: torch.Tensor,  # [n_hidden_states, D]
        temperature: torch.Tensor,  # scalar (0-d)
        num_samples: int,
        seed: int | None = None,  # ignored
        weights: torch.Tensor = None,  # ignored
    )

Source from the content-addressed store, hash-verified

691
692 @torch.compile(fullgraph=True)
693 def sample(
694 self,
695 hidden_states: torch.Tensor, # [n_hidden_states, D]
696 temperature: torch.Tensor, # scalar (0-d)
697 num_samples: int,
698 seed: int | None = None, # ignored
699 weights: torch.Tensor = None, # ignored
700 ):
701 """
702 Sampling using low-dimensional random projections (Johnson-Lindenstrauss lemma).
703 """
704 if not self.prepared:
705 raise ValueError("Sampler not prepared. Call .prepare() first.")
706 logits_p = self.compute_logits(hidden_states)
707 probs = (logits_p / temperature).softmax(dim=1)
708 samples = _fast_multinomial(probs, num_samples)
709 return samples
710
711 def compute_logits(
712 self,

Callers

nothing calls this directly

Calls 2

compute_logitsMethod · 0.95
_fast_multinomialFunction · 0.85

Tested by

no test coverage detected