Skip to content

Commit 7b1a3ee

Browse files
authored
Add top n sigma sampler and other webui fix (#512)
Co-authored-by: firecoperana <firecoperana>
1 parent 4fc3cb4 commit 7b1a3ee

File tree

8 files changed

+36
-26
lines changed

8 files changed

+36
-26
lines changed

common/sampling.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
// sampler types
1313
enum class llama_sampler_type : char {
14+
DRY ='d',
1415
TOP_K = 'k',
1516
TOP_P = 'p',
1617
MIN_P = 'm',
@@ -53,6 +54,7 @@ typedef struct llama_sampling_params {
5354
llama_sampler_type::TYPICAL_P,
5455
llama_sampler_type::TOP_P,
5556
llama_sampler_type::MIN_P,
57+
llama_sampler_type::TOP_N_SIGMA,
5658
llama_sampler_type::TEMPERATURE
5759
};
5860

152 Bytes
Binary file not shown.

examples/server/server.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,9 @@ struct server_context {
970970
slot.sparams.temp = json_value(data, "temperature", default_sparams.temp);
971971
slot.sparams.dynatemp_range = json_value(data, "dynatemp_range", default_sparams.dynatemp_range);
972972
slot.sparams.dynatemp_exponent = json_value(data, "dynatemp_exponent", default_sparams.dynatemp_exponent);
973+
slot.sparams.xtc_probability = json_value(data, "xtc_probability", default_sparams.xtc_probability);
974+
slot.sparams.xtc_threshold = json_value(data, "xtc_threshold", default_sparams.xtc_threshold);
975+
slot.sparams.top_n_sigma = json_value(data, "top_n_sigma", default_sparams.top_n_sigma);
973976
slot.sparams.penalty_last_n = json_value(data, "repeat_last_n", default_sparams.penalty_last_n);
974977
slot.sparams.penalty_repeat = json_value(data, "repeat_penalty", default_sparams.penalty_repeat);
975978
slot.sparams.penalty_freq = json_value(data, "frequency_penalty", default_sparams.penalty_freq);
@@ -1135,17 +1138,17 @@ struct server_context {
11351138
}
11361139

11371140
{
1138-
const auto & samplers_sequence = data.find("samplers");
1139-
if (samplers_sequence != data.end() && samplers_sequence->is_array()) {
1140-
std::vector<std::string> sampler_names;
1141-
for (const auto & sampler_name : *samplers_sequence) {
1142-
if (sampler_name.is_string()) {
1143-
sampler_names.emplace_back(sampler_name);
1144-
}
1141+
const auto samplers = data.find("samplers");
1142+
if (samplers != data.end()) {
1143+
if (samplers->is_array()) {
1144+
slot.sparams.samplers_sequence = llama_sampling_types_from_names(*samplers, false);
1145+
}
1146+
else if (samplers->is_string()) {
1147+
slot.sparams.samplers_sequence = llama_sampling_types_from_chars(samplers->get<std::string>());
1148+
}
1149+
else {
1150+
slot.sparams.samplers_sequence = default_sparams.samplers_sequence;
11451151
}
1146-
slot.sparams.samplers_sequence = llama_sampling_types_from_names(sampler_names, false);
1147-
} else {
1148-
slot.sparams.samplers_sequence = default_sparams.samplers_sequence;
11491152
}
11501153
}
11511154

examples/server/webui/dist/index.html

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

examples/server/webui/src/Config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const CONFIG_DEFAULT = {
1717
showThoughtInProgress: false,
1818
excludeThoughtOnReq: true,
1919
// make sure these default values are in sync with `common.h`
20-
samplers: 'dkypmxt',
20+
samplers: 'dkypmxnt',
2121
temperature: 0.8,
2222
dynatemp_range: 0.0,
2323
dynatemp_exponent: 1.0,
@@ -26,6 +26,7 @@ export const CONFIG_DEFAULT = {
2626
min_p: 0.05,
2727
xtc_probability: 0.0,
2828
xtc_threshold: 0.1,
29+
top_n_sigma: 0.0,
2930
typical_p: 1.0,
3031
repeat_last_n: 64,
3132
repeat_penalty: 1.0,
@@ -44,7 +45,7 @@ export const CONFIG_INFO: Record<string, string> = {
4445
apiKey: 'Set the API Key if you are using --api-key option for the server.',
4546
systemMessage: 'The starting message that defines how model should behave.',
4647
samplers:
47-
'The order at which samplers are applied, in simplified way. Default is "dkypmxt": dry->top_k->typ_p->top_p->min_p->xtc->temperature',
48+
'The order at which samplers are applied, in simplified way. Default is "dkypmxt": dry->top_k->typ_p->top_p->min_p->xtc->top_sigma->temperature',
4849
temperature:
4950
'Controls the randomness of the generated text by affecting the probability distribution of the output tokens. Higher = more random, lower = more focused.',
5051
dynatemp_range:
@@ -60,6 +61,8 @@ export const CONFIG_INFO: Record<string, string> = {
6061
'XTC sampler cuts out top tokens; this parameter controls the chance of cutting tokens at all. 0 disables XTC.',
6162
xtc_threshold:
6263
'XTC sampler cuts out top tokens; this parameter controls the token probability that is required to cut that token.',
64+
top_n_sigma:
65+
'Top-n-sigma sampling filters out low-value tokens by discarding tokens that fall more than n standard deviations below the maximum probability',
6366
typical_p:
6467
'Sorts and limits tokens based on the difference between log-probability and entropy.',
6568
repeat_last_n: 'Last n tokens to consider for penalizing repetition',

examples/server/webui/src/components/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default function Header() {
7070
</svg>
7171
</label>
7272

73-
<div className="grow text-2xl font-bold ml-2">llama.cpp</div>
73+
<div className="grow text-2xl font-bold ml-2">ik_llama.cpp</div>
7474

7575
{/* action buttons (top right) */}
7676
<div className="flex items-center">

examples/server/webui/src/components/SettingDialog.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const SAMPLER_KEYS: SettKey[] = [
2929
'typical_p',
3030
'xtc_probability',
3131
'xtc_threshold',
32+
'top_n_sigma'
3233
];
3334
const PENALTY_KEYS: SettKey[] = [
3435
'repeat_last_n',
@@ -196,7 +197,7 @@ const SETTING_SECTIONS: SettingSection[] = [
196197
label: (
197198
<>
198199
Custom JSON config (For more info, refer to{' '}
199-
<OpenInNewTab href="https://github.com/ggerganov/llama.cpp/blob/master/examples/server/README.md">
200+
<OpenInNewTab href="https://github.com/ikawrakow/ik_llama.cpp/tree/main/examples/server/README.md">
200201
server documentation
201202
</OpenInNewTab>
202203
)
@@ -224,7 +225,7 @@ const SETTING_SECTIONS: SettingSection[] = [
224225
<br />
225226
<br />
226227
If you encounter any problems, create a{' '}
227-
<OpenInNewTab href="https://github.com/ggerganov/llama.cpp/issues/new?template=019-bug-misc.yml">
228+
<OpenInNewTab href="https://github.com/ikawrakow/ik_llama.cpp/issues/new?template=019-bug-misc.yml">
228229
Bug (misc.)
229230
</OpenInNewTab>{' '}
230231
report on Github. Please also specify <b>webui/experimental</b> on
@@ -456,11 +457,11 @@ function SettingsModalLongInput({
456457
<div className="label inline">{label || configKey}</div>
457458
<textarea
458459
className="textarea textarea-bordered h-24"
459-
placeholder={`Default: ${CONFIG_DEFAULT[configKey] || 'none'}`}
460-
value={value}
461-
onChange={(e) => onChange(e.target.value)}
462-
/>
463-
</label>
460+
placeholder={`Default: ${CONFIG_DEFAULT[configKey] || 'none'}`}
461+
value={value}
462+
onChange={(e) => onChange(e.target.value)}
463+
/>
464+
</label>
464465
);
465466
}
466467

@@ -485,7 +486,7 @@ function SettingsModalShortInput({
485486
<div className="block md:hidden mb-1">
486487
<b>{label || configKey}</b>
487488
<br />
488-
<p className="text-xs">{helpMsg}</p>
489+
<p className="text-xs whitespace-normal">{helpMsg}</p>
489490
</div>
490491
)}
491492
<label className="input input-bordered join-item grow flex items-center gap-2 mb-2">
@@ -494,7 +495,7 @@ function SettingsModalShortInput({
494495
{label || configKey}
495496
</div>
496497
{helpMsg && (
497-
<div className="dropdown-content menu bg-base-100 rounded-box z-10 w-64 p-2 shadow mt-4">
498+
<div className="dropdown-content menu bg-base-100 rounded-box z-10 w-64 p-2 shadow mt-4 whitespace-normal break-words">
498499
{helpMsg}
499500
</div>
500501
)}

examples/server/webui/src/utils/app.context.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export const AppContextProvider = ({
200200
typical_p: config.typical_p,
201201
xtc_probability: config.xtc_probability,
202202
xtc_threshold: config.xtc_threshold,
203+
top_n_sigma: config.top_n_sigma,
203204
repeat_last_n: config.repeat_last_n,
204205
repeat_penalty: config.repeat_penalty,
205206
presence_penalty: config.presence_penalty,

0 commit comments

Comments
 (0)