MCPcopy Create free account
hub / github.com/AnswerDotAI/gpu.cpp / sample_mult

Function sample_mult

experimental/kernels/gpt2_webgpu.cpp:637–648  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

635}
636
637int sample_mult(float* probabilities, int n, float coin) {
638 // sample index from probabilities (they must sum to 1!)
639 // coin is a random number in [0, 1), usually from random_f32()
640 float cdf = 0.0f;
641 for (int i = 0; i < n; i++) {
642 cdf += probabilities[i];
643 if (coin < cdf) {
644 return i;
645 }
646 }
647 return n - 1; // in case of rounding errors
648}
649
650// ----------------------------------------------------------------------------
651// main training loop

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected