MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS-TTS / multinomial

Function multinomial

moss_tts_delay/llama_cpp/sampling.py:94–101  ·  view source on GitHub ↗

Sample one token per row via multinomial distribution.

(probs: np.ndarray)

Source from the content-addressed store, hash-verified

92
93
94def multinomial(probs: np.ndarray) -> np.ndarray:
95 """Sample one token per row via multinomial distribution."""
96 N = probs.shape[0]
97 cum = np.cumsum(probs, axis=-1)
98 r = np.random.random(N)[:, None]
99 # Clamp to valid range: float32 cumsum may not reach 1.0 exactly,
100 # so r > cumsum[-1] would produce an out-of-bounds index.
101 return np.minimum((cum < r).sum(axis=-1), probs.shape[-1] - 1).astype(np.int64)
102
103
104def sample_token(

Callers 1

sample_tokenFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected