MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / llama_sample_xtc_apply

Function llama_sample_xtc_apply

smallthinker/src/llama-sampling.cpp:1131–1159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1129}
1130
1131static void llama_sample_xtc_apply(struct llama_sampler * smpl, llama_token_data_array * cur_p) {
1132 auto * ctx = (llama_sampler_xtc *) smpl->ctx;
1133
1134 if (ctx->probability <= 0.0f
1135 || ctx->threshold > 0.5f
1136 || cur_p->size < 2) {
1137 return;
1138 }
1139
1140 std::uniform_real_distribution<float> distribution(0.0f, 1.0f);
1141 float chance = distribution(ctx->rng);
1142 if (chance > ctx->probability) return;
1143
1144 // in case it's not sorted/recalculated yet
1145 llama_sampler_softmax_impl(cur_p);
1146
1147 int pos_last = 0;
1148
1149 for (size_t i = 0; i < cur_p->size; ++i) {
1150 if (cur_p->data[i].p >= ctx->threshold) {
1151 pos_last = i;
1152 } else break;
1153 }
1154
1155 if (cur_p->size - pos_last >= ctx->min_keep && pos_last > 0) {
1156 cur_p->data += pos_last;
1157 cur_p->size -= pos_last;
1158 }
1159}
1160
1161static struct llama_sampler * llama_sampler_xtc_clone(const struct llama_sampler * smpl) {
1162 const auto * ctx = (const llama_sampler_xtc *) smpl->ctx;

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected