mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-31 03:27:44 +01:00
Merge pull request #1855 from deciare/llamacpp-sampler-order
Sampler order for llama.cpp server backend
This commit is contained in:
commit
16833fc238
@ -61,6 +61,14 @@
|
||||
"min_p",
|
||||
"mirostat"
|
||||
],
|
||||
"samplers": [
|
||||
"top_k",
|
||||
"tfs_z",
|
||||
"typical_p",
|
||||
"top_p",
|
||||
"min_p",
|
||||
"temperature"
|
||||
],
|
||||
"mirostat_mode": 0,
|
||||
"mirostat_tau": 5,
|
||||
"mirostat_eta": 0.1,
|
||||
|
@ -1550,6 +1550,27 @@
|
||||
<span data-i18n="Load default order">Load default order</span>
|
||||
</div>
|
||||
</div>
|
||||
<div data-newbie-hidden data-tg-type="llamacpp" class="range-block flexFlowColumn wide100p">
|
||||
<hr class="wide100p">
|
||||
<h4 class="range-block-title justifyCenter">
|
||||
<span data-i18n="Samplers Order">Samplers Order</span>
|
||||
<div class="margin5 fa-solid fa-circle-info opacity50p" title="llama.cpp only. Determines the order of samplers. If Mirostat mode is not 0, sampler order is ignored."></div>
|
||||
</h4>
|
||||
<div class="toggle-description widthUnset" data-i18n="llama.cpp only. Determines the order of samplers. If Mirostat mode is not 0, sampler order is ignored.">
|
||||
llama.cpp only. Determines the order of samplers. If Mirostat mode is not 0, sampler order is ignored.
|
||||
</div>
|
||||
<div id="llamacpp_samplers_sortable" class="prompt_order">
|
||||
<div data-name="temperature" draggable="true"><span>Temperature</span><small></small></div>
|
||||
<div data-name="top_k" draggable="true"><span>Top K</span><small></small></div>
|
||||
<div data-name="top_p" draggable="true"><span>Top P</span><small></small></div>
|
||||
<div data-name="typical_p" draggable="true"><span>Typical P</span><small></small></div>
|
||||
<div data-name="tfs_z" draggable="true"><span>Tail Free Sampling</span><small></small></div>
|
||||
<div data-name="min_p" draggable="true"><span>Min P</span><small></small></div>
|
||||
</div>
|
||||
<div id="llamacpp_samplers_default_order" class="menu_button menu_button_icon">
|
||||
<span data-i18n="Load default order">Load default order</span>
|
||||
</div>
|
||||
</div>
|
||||
<div data-newbie-hidden data-tg-type="ooba" class="range-block flexFlowColumn wide100p">
|
||||
<hr class="wide100p">
|
||||
<h4 class="range-block-title justifyCenter">
|
||||
|
@ -35,6 +35,15 @@ export const textgen_types = {
|
||||
};
|
||||
|
||||
const { MANCER, APHRODITE, TABBY, TOGETHERAI, OOBA, OLLAMA, LLAMACPP, INFERMATICAI } = textgen_types;
|
||||
|
||||
const LLAMACPP_DEFAULT_ORDER = [
|
||||
'top_k',
|
||||
'tfs_z',
|
||||
'typical_p',
|
||||
'top_p',
|
||||
'min_p',
|
||||
'temperature',
|
||||
];
|
||||
const OOBA_DEFAULT_ORDER = [
|
||||
'temperature',
|
||||
'dynamic_temperature',
|
||||
@ -113,6 +122,7 @@ const settings = {
|
||||
grammar_string: '',
|
||||
banned_tokens: '',
|
||||
sampler_priority: OOBA_DEFAULT_ORDER,
|
||||
samplers: LLAMACPP_DEFAULT_ORDER,
|
||||
//n_aphrodite: 1,
|
||||
//best_of_aphrodite: 1,
|
||||
ignore_eos_token_aphrodite: false,
|
||||
@ -189,6 +199,7 @@ const setting_names = [
|
||||
//'prompt_log_probs_aphrodite'
|
||||
'sampler_order',
|
||||
'sampler_priority',
|
||||
'samplers',
|
||||
'n',
|
||||
'logit_bias',
|
||||
'custom_model',
|
||||
@ -456,6 +467,16 @@ function sortKoboldItemsByOrder(orderArray) {
|
||||
}
|
||||
}
|
||||
|
||||
function sortLlamacppItemsByOrder(orderArray) {
|
||||
console.debug('Preset samplers order: ', orderArray);
|
||||
const $container = $('#llamacpp_samplers_sortable');
|
||||
|
||||
orderArray.forEach((name) => {
|
||||
const $item = $container.find(`[data-name="${name}"]`).detach();
|
||||
$container.append($item);
|
||||
});
|
||||
}
|
||||
|
||||
function sortOobaItemsByOrder(orderArray) {
|
||||
console.debug('Preset samplers order: ', orderArray);
|
||||
const $container = $('#sampler_priority_container');
|
||||
@ -486,6 +507,26 @@ jQuery(function () {
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#llamacpp_samplers_sortable').sortable({
|
||||
delay: getSortableDelay(),
|
||||
stop: function () {
|
||||
const order = [];
|
||||
$('#llamacpp_samplers_sortable').children().each(function () {
|
||||
order.push($(this).data('name'));
|
||||
});
|
||||
settings.samplers = order;
|
||||
console.log('Samplers reordered:', settings.samplers);
|
||||
saveSettingsDebounced();
|
||||
},
|
||||
});
|
||||
|
||||
$('#llamacpp_samplers_default_order').on('click', function () {
|
||||
sortLlamacppItemsByOrder(LLAMACPP_DEFAULT_ORDER);
|
||||
settings.samplers = LLAMACPP_DEFAULT_ORDER;
|
||||
console.log('Default samplers order loaded:', settings.samplers);
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#sampler_priority_container').sortable({
|
||||
delay: getSortableDelay(),
|
||||
stop: function () {
|
||||
@ -595,7 +636,7 @@ jQuery(function () {
|
||||
for (const [id, value] of Object.entries(inputs)) {
|
||||
const inputElement = $(`#${id}`);
|
||||
if (inputElement.prop('type') === 'checkbox') {
|
||||
inputElement.prop('checked', value);
|
||||
inputElement.prop('checked', value).trigger('input');
|
||||
} else if (inputElement.prop('type') === 'number') {
|
||||
inputElement.val(value).trigger('input');
|
||||
} else {
|
||||
@ -681,6 +722,13 @@ function setSettingByName(setting, value, trigger) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ('samplers' === setting) {
|
||||
value = Array.isArray(value) ? value : LLAMACPP_DEFAULT_ORDER;
|
||||
sortLlamacppItemsByOrder(value);
|
||||
settings.samplers = value;
|
||||
return;
|
||||
}
|
||||
|
||||
if ('logit_bias' === setting) {
|
||||
settings.logit_bias = Array.isArray(value) ? value : [];
|
||||
return;
|
||||
@ -901,6 +949,7 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate,
|
||||
'dynatemp_exponent': settings.dynatemp ? settings.dynatemp_exponent : 1,
|
||||
'smoothing_factor': settings.smoothing_factor,
|
||||
'sampler_priority': settings.type === OOBA ? settings.sampler_priority : undefined,
|
||||
'samplers': settings.type === LLAMACPP ? settings.samplers : undefined,
|
||||
'stopping_strings': getStoppingStrings(isImpersonate, isContinue),
|
||||
'stop': getStoppingStrings(isImpersonate, isContinue),
|
||||
'truncation_length': max_context,
|
||||
|
Loading…
x
Reference in New Issue
Block a user