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

Function shift_logits_negative

src/fused_mm_sampling/testing.py:211–238  ·  view source on GitHub ↗

Shift all logits by -offset without touching the existing weights. Appends a bias column so that ``h_new @ W_new^T = h @ W^T - offset``. Since softmax is shift-invariant the expected sampling distribution is unchanged, but the all-negative logits exercise masked-fill handling in par

(
    weights: torch.Tensor,
    hidden_states: torch.Tensor,
    offset: float,
)

Source from the content-addressed store, hash-verified

209def assert_sampling_distribution_large_vocab(
210 vocab_size: int = 32_768,
211 num_samples: int = 1_000_000,
212 samples_per_call: int = 10_000,
213 hidden_size: int = 16,
214) -> None:
215 """Verify FMMS sampling against random-Gaussian logits at realistic vocabulary size."""
216
217 device = torch.device("cuda")
218 torch.manual_seed(0)
219
220 hidden_states = torch.randn(
221 (1, hidden_size),
222 dtype=torch.bfloat16,
223 device=device,
224 )
225 weights = torch.randn(
226 (vocab_size, hidden_size),
227 dtype=torch.bfloat16,
228 device=device,
229 )
230 weights.div_(math.sqrt(hidden_size))
231 inputs = SyntheticInputs(
232 weights=weights,
233 hidden_states=hidden_states,
234 logits=hidden_states.float() @ weights.float().T,
235 vocab_size=vocab_size,
236 hidden_size=hidden_size,
237 )
238 assert_sampling_distribution(
239 provider="fused-triton",
240 vocab_size=vocab_size,
241 n_hidden_states=1,

Callers 1

make_synthetic_inputsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected