Skip to content

Commit 2107882

Browse files
committed
Renamed parameters, fixed info and defaults
* probability is at 0 by default, but XTC is included in sampling queue * threshold higher than 0.5 switches XTC off
1 parent ba29d31 commit 2107882

File tree

6 files changed

+28
-27
lines changed

6 files changed

+28
-27
lines changed

common/arg.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -967,24 +967,24 @@ gpt_params_context gpt_params_parser_init(gpt_params & params, llama_example ex,
967967
}
968968
).set_sparam());
969969
add_opt(llama_arg(
970-
{"--xtc-p"}, "N",
971-
format("xtc probability (default: %.1f, 0.0 = disabled)", (double)params.sparams.xtc_p),
970+
{"-xtc-p", "--xtc-probability"}, "N",
971+
format("xtc probability (default: %.1f, 0.0 = disabled)", (double)params.sparams.xtc_probability),
972972
[](gpt_params & params, const std::string & value) {
973-
params.sparams.xtc_p = std::stof(value);
973+
params.sparams.xtc_probability = std::stof(value);
974974
}
975975
).set_sparam());
976976
add_opt(llama_arg(
977-
{"--xtc-t"}, "N",
978-
format("xtc threshold (default: %.1f, 1.0 = disabled)", (double)params.sparams.xtc_t),
977+
{"-xtc-t", "--xtc-threshold"}, "N",
978+
format("xtc threshold (default: %.1f, 1.0 = disabled)", (double)params.sparams.xtc_threshold),
979979
[](gpt_params & params, const std::string & value) {
980-
params.sparams.xtc_t = std::stof(value);
980+
params.sparams.xtc_threshold = std::stof(value);
981981
}
982982
).set_sparam());
983983
add_opt(llama_arg(
984-
{"--xtc-t-max"}, "N",
985-
format("xtc upper threshold (default: %.1f, 0.0 = disabled)", (double)params.sparams.xtc_t_max),
984+
{"-xtc-t-max", "--xtc-threshold-max"}, "N",
985+
format("xtc upper threshold (default: %.1f, 0.0 = disabled)", (double)params.sparams.xtc_threshold_max),
986986
[](gpt_params & params, const std::string & value) {
987-
params.sparams.xtc_t_max = std::stof(value);
987+
params.sparams.xtc_threshold_max = std::stof(value);
988988
}
989989
).set_sparam());
990990
add_opt(llama_arg(

common/common.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,9 +2088,9 @@ void yaml_dump_non_result_info(FILE * stream, const gpt_params & params, const l
20882088
fprintf(stream, "top_k: %d # default: 40\n", sparams.top_k);
20892089
fprintf(stream, "top_p: %f # default: 0.95\n", sparams.top_p);
20902090
fprintf(stream, "min_p: %f # default: 0.0\n", sparams.min_p);
2091-
fprintf(stream, "xtc_p: %f # default: 0.5\n", sparams.xtc_p);
2092-
fprintf(stream, "xtc_t: %f # default: 0.1\n", sparams.xtc_t);
2093-
fprintf(stream, "xtc_t_max: %f # default: 1.0\n", sparams.xtc_t_max);
2091+
fprintf(stream, "xtc_probability: %f # default: 0.5\n", sparams.xtc_probability);
2092+
fprintf(stream, "xtc_threshold: %f # default: 0.1\n", sparams.xtc_threshold);
2093+
fprintf(stream, "xtc_threshold_max: %f # default: 1.0\n", sparams.xtc_threshold_max);
20942094
fprintf(stream, "typ_p: %f # default: 1.0\n", sparams.typ_p);
20952095
fprintf(stream, "verbose_prompt: %s # default: false\n", params.verbose_prompt ? "true" : "false");
20962096
fprintf(stream, "display_prompt: %s # default: true\n", params.display_prompt ? "true" : "false");

common/common.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ struct gpt_sampler_params {
109109
int32_t top_k = 40; // <= 0 to use vocab size
110110
float top_p = 0.95f; // 1.0 = disabled
111111
float min_p = 0.05f; // 0.0 = disabled
112-
float xtc_p = 0.50f; // 0.0 = disabled
113-
float xtc_t = 0.10f; // 1.0 = disabled
114-
float xtc_t_max = 1.00f; // 0.0 = disabled
112+
float xtc_probability = 0.00f; // 0.0 = disabled
113+
float xtc_threshold = 0.10f; // 0.5 = disabled
114+
float xtc_threshold_max = 1.00f; // 0.0 = disabled
115115
float tfs_z = 1.00f; // 1.0 = disabled
116116
float typ_p = 1.00f; // typical_p, 1.0 = disabled
117117
float temp = 0.80f; // <= 0.0 to sample greedily, 0.0 to not output probabilities
@@ -134,6 +134,7 @@ struct gpt_sampler_params {
134134
GPT_SAMPLER_TYPE_TYPICAL_P,
135135
GPT_SAMPLER_TYPE_TOP_P,
136136
GPT_SAMPLER_TYPE_MIN_P,
137+
GPT_SAMPLER_TYPE_XTC,
137138
GPT_SAMPLER_TYPE_TEMPERATURE
138139
};
139140

common/sampling.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ std::string gpt_sampler_params::print() const {
130130

131131
snprintf(result, sizeof(result),
132132
"\trepeat_last_n = %d, repeat_penalty = %.3f, frequency_penalty = %.3f, presence_penalty = %.3f\n"
133-
"\ttop_k = %d, tfs_z = %.3f, top_p = %.3f, min_p = %.3f, xtc_p = %.3f, xtc_t = %.3f, xtc_t_max = %.3f, typical_p = %.3f, temp = %.3f\n"
133+
"\ttop_k = %d, tfs_z = %.3f, top_p = %.3f, min_p = %.3f, xtc_probability = %.3f, xtc_threshold = %.3f, xtc_threshold_max = %.3f, typical_p = %.3f, temp = %.3f\n"
134134
"\tmirostat = %d, mirostat_lr = %.3f, mirostat_ent = %.3f",
135135
penalty_last_n, penalty_repeat, penalty_freq, penalty_present,
136-
top_k, tfs_z, top_p, min_p, xtc_p, xtc_t, xtc_t_max, typ_p, temp,
136+
top_k, tfs_z, top_p, min_p, xtc_probability, xtc_threshold, xtc_threshold_max, typ_p, temp,
137137
mirostat, mirostat_eta, mirostat_tau);
138138

139139
return std::string(result);
@@ -185,7 +185,7 @@ struct gpt_sampler * gpt_sampler_init(const struct llama_model * model, const st
185185
llama_sampler_chain_add(result->chain, llama_sampler_init_min_p (params.min_p, params.min_keep));
186186
break;
187187
case GPT_SAMPLER_TYPE_XTC:
188-
llama_sampler_chain_add(result->chain, llama_sampler_init_xtc (params.xtc_p, params.xtc_t, params.xtc_t_max, params.min_keep, params.seed));
188+
llama_sampler_chain_add(result->chain, llama_sampler_init_xtc (params.xtc_probability, params.xtc_threshold, params.xtc_threshold_max, params.min_keep, params.seed));
189189
break;
190190
case GPT_SAMPLER_TYPE_TFS_Z:
191191
llama_sampler_chain_add(result->chain, llama_sampler_init_tail_free(params.tfs_z, params.min_keep));

examples/main/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,19 @@ Example usage: `--mirostat 2 --mirostat-lr 0.05 --mirostat-ent 3.0`
243243

244244
### XTC Sampling
245245

246-
- `--xtc-p N`: Sets the chance for token removal (checked once on sampler start) (default: 0.5).
247-
- `--xtc-t N`: Sets a minimum probability threshold for tokens to be removed (default: 0.1).
248-
- `--xtc-t-max N`: Sets a maximum probability threshold for tokens to be removed (highly expetrimental) (default: 1.0).
246+
- `--xtc-probability N`: Sets the chance for token removal (checked once on sampler start) (default: 0.0).
247+
- `--xtc-threshold N`: Sets a minimum probability threshold for tokens to be removed (default: 0.1).
248+
- `--xtc-threshold-max N`: Sets a maximum probability threshold for tokens to be removed (highly experimental) (default: 1.0).
249249

250-
Exclude Top Choices (XTC) is a unique sampler that is designed to remove top tokens from consideration and avoid more obvious and repetitive answers. With a chance of `xtc-p` it searches for tokens with probabilities of `xtc-t` threshold and above, then removes all such tokens except the least probable one.
250+
Exclude Top Choices (XTC) is a unique sampler that is designed to remove top tokens from consideration and avoid more obvious and repetitive outputs. With a chance of `xtc-p` it searches for tokens with probabilities of `xtc-threshold` and above, then removes all such tokens except the least probable one.
251251

252-
By removing top tokens XTC can improve variety of answers, break writing clichés and inhibit repition, since clichés and repeated phrases are usually more likely to appear. By keeping the last top token XTC ensures that the answer is still coherent. XTC is meant to be used for creative tasks, but feel free to experiment with different settings for different models.
252+
By removing top tokens XTC can improve the variety of answers, break writing clichés and inhibit repition, since clichés and repeated phrases are usually more likely to appear. By keeping the last token above the threshold, XTC ensures that the answer is still coherent. XTC is meant to be used for creative tasks, but feel free to experiment with different settings for different models.
253253

254-
The additional `xtc-t-max` parameter may help with finetuned models that already give relatively creative output, meaning that clichés and repetitive phrases may appear at lower probabilities. It allows to remove tokens from a middle range which will always be specific to a model, requiring careful experimenting. Leave `xtc-t-max` on default 1.0 for all base/instruct models.
254+
The additional `xtc-threshold-max` parameter may help with finetuned models that already give relatively creative output, meaning that clichés and repetitive phrases may appear at lower probabilities. It allows to remove tokens from a middle range which will always be specific to a model, requiring careful experimenting. Leave `xtc-threshold-max` on default 1.0 for all base/instruct models.
255255

256-
Being experimental and unique, XTC is not included in the default sampling queue. You can start from a recommended combination of Min-P followed by XTC on its default settings: `--sampling-seq mx --min-p 0.02`.
256+
Being experimental and unique, XTC is disabled by default. The recommended combination of samplers is Min-P followed by XTC on its default settings: `--sampling-seq mx --min-p 0.02 -xtc-p 0.5`.
257257

258-
Example usage: `--xtc-p 0.5 --xtc-t 0.1 --xtc-t-max 1.0`
258+
Example usage: `-xtc-p 0.5 -xtc-t 0.1 -xtc-t-max 1.0`
259259

260260
### Logit Bias
261261

src/llama-sampling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ static void llama_sample_xtc_apply(struct llama_sampler * smpl, llama_token_data
10811081
auto * ctx = (llama_sampler_xtc *) smpl->ctx;
10821082

10831083
if (ctx->probability <= 0.0f
1084-
|| ctx->threshold >= 1.0f
1084+
|| ctx->threshold > 0.5f
10851085
|| ctx->threshold_max <= 0.0f
10861086
|| ctx->threshold_max <= ctx->threshold
10871087
|| cur_p->size <= 2) {

0 commit comments

Comments
 (0)