mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #1811 from kalomaze/sampler-order-ooba
Sampler priority support (for text-generation-webui)
This commit is contained in:
@@ -47,6 +47,20 @@
|
|||||||
"ban_eos_token": false,
|
"ban_eos_token": false,
|
||||||
"skip_special_tokens": true,
|
"skip_special_tokens": true,
|
||||||
"streaming": false,
|
"streaming": false,
|
||||||
|
"sampler_priority": [
|
||||||
|
"temperature",
|
||||||
|
"dynamic_temperature",
|
||||||
|
"quadratic_sampling",
|
||||||
|
"top_k",
|
||||||
|
"top_p",
|
||||||
|
"typical_p",
|
||||||
|
"epsilon_cutoff",
|
||||||
|
"eta_cutoff",
|
||||||
|
"tfs",
|
||||||
|
"top_a",
|
||||||
|
"min_p",
|
||||||
|
"mirostat"
|
||||||
|
],
|
||||||
"mirostat_mode": 0,
|
"mirostat_mode": 0,
|
||||||
"mirostat_tau": 5,
|
"mirostat_tau": 5,
|
||||||
"mirostat_eta": 0.1,
|
"mirostat_eta": 0.1,
|
||||||
|
@@ -1507,7 +1507,7 @@
|
|||||||
</h4>
|
</h4>
|
||||||
<textarea id="grammar_string_textgenerationwebui" rows="4" class="text_pole textarea_compact monospace" data-i18n="[placeholder]Type in the desired custom grammar" placeholder="Type in the desired custom grammar"></textarea>
|
<textarea id="grammar_string_textgenerationwebui" rows="4" class="text_pole textarea_compact monospace" data-i18n="[placeholder]Type in the desired custom grammar" placeholder="Type in the desired custom grammar"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div data-newbie-hidden data-tg-type="koboldcpp" class="range-block flexFlowColumn">
|
<div data-newbie-hidden data-tg-type="koboldcpp" class="range-block flexFlowColumn wide100p">
|
||||||
<hr class="wide100p">
|
<hr class="wide100p">
|
||||||
<div class="range-block-title">
|
<div class="range-block-title">
|
||||||
<span data-i18n="Samplers Order">Samplers Order</span>
|
<span data-i18n="Samplers Order">Samplers Order</span>
|
||||||
@@ -1550,6 +1550,33 @@
|
|||||||
<span data-i18n="Load default order">Load default order</span>
|
<span data-i18n="Load default order">Load default order</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div data-newbie-hidden data-tg-type="ooba" class="range-block flexFlowColumn wide100p">
|
||||||
|
<hr class="wide100p">
|
||||||
|
<h4 class="range-block-title justifyCenter">
|
||||||
|
<span data-i18n="Sampler Priority">Sampler Priority</span>
|
||||||
|
<div class="margin5 fa-solid fa-circle-info opacity50p" title="Ooba only. Determines the order of samplers."></div>
|
||||||
|
</h4>
|
||||||
|
<div class="toggle-description widthUnset" data-i18n="Ooba only. Determines the order of samplers.">
|
||||||
|
Ooba only. Determines the order of samplers.
|
||||||
|
</div>
|
||||||
|
<div id="sampler_priority_container" class="prompt_order">
|
||||||
|
<div data-name="temperature" draggable="true"><span>Temperature</span><small></small></div>
|
||||||
|
<div data-name="dynamic_temperature" draggable="true"><span>Dynamic Temperature</span><small></small></div>
|
||||||
|
<div data-name="quadratic_sampling" draggable="true"><span>Quadratic / Smooth Sampling</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="epsilon_cutoff" draggable="true"><span>Epsilon Cutoff</span><small></small></div>
|
||||||
|
<div data-name="eta_cutoff" draggable="true"><span>Eta Cutoff</span><small></small></div>
|
||||||
|
<div data-name="tfs" draggable="true"><span>Tail Free Sampling</span><small></small></div>
|
||||||
|
<div data-name="top_a" draggable="true"><span>Top A</span><small></small></div>
|
||||||
|
<div data-name="min_p" draggable="true"><span>Min P</span><small></small></div>
|
||||||
|
<div data-name="mirostat" draggable="true"><span>Mirostat</span><small></small></div>
|
||||||
|
</div>
|
||||||
|
<div id="textgenerationwebui_default_order" class="menu_button menu_button_icon">
|
||||||
|
<span data-i18n="Load default order">Load default order</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div><!-- end of textgen settings-->
|
</div><!-- end of textgen settings-->
|
||||||
<div id="openai_settings">
|
<div id="openai_settings">
|
||||||
|
@@ -34,6 +34,20 @@ export const textgen_types = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const { MANCER, APHRODITE, TABBY, TOGETHERAI, OOBA, OLLAMA, LLAMACPP } = textgen_types;
|
const { MANCER, APHRODITE, TABBY, TOGETHERAI, OOBA, OLLAMA, LLAMACPP } = textgen_types;
|
||||||
|
const OOBA_DEFAULT_ORDER = [
|
||||||
|
'temperature',
|
||||||
|
'dynamic_temperature',
|
||||||
|
'quadratic_sampling',
|
||||||
|
'top_k',
|
||||||
|
'top_p',
|
||||||
|
'typical_p',
|
||||||
|
'epsilon_cutoff',
|
||||||
|
'eta_cutoff',
|
||||||
|
'tfs',
|
||||||
|
'top_a',
|
||||||
|
'min_p',
|
||||||
|
'mirostat',
|
||||||
|
];
|
||||||
const BIAS_KEY = '#textgenerationwebui_api-settings';
|
const BIAS_KEY = '#textgenerationwebui_api-settings';
|
||||||
|
|
||||||
// Maybe let it be configurable in the future?
|
// Maybe let it be configurable in the future?
|
||||||
@@ -96,6 +110,7 @@ const settings = {
|
|||||||
negative_prompt: '',
|
negative_prompt: '',
|
||||||
grammar_string: '',
|
grammar_string: '',
|
||||||
banned_tokens: '',
|
banned_tokens: '',
|
||||||
|
sampler_priority: OOBA_DEFAULT_ORDER,
|
||||||
//n_aphrodite: 1,
|
//n_aphrodite: 1,
|
||||||
//best_of_aphrodite: 1,
|
//best_of_aphrodite: 1,
|
||||||
ignore_eos_token_aphrodite: false,
|
ignore_eos_token_aphrodite: false,
|
||||||
@@ -170,6 +185,7 @@ const setting_names = [
|
|||||||
//'log_probs_aphrodite',
|
//'log_probs_aphrodite',
|
||||||
//'prompt_log_probs_aphrodite'
|
//'prompt_log_probs_aphrodite'
|
||||||
'sampler_order',
|
'sampler_order',
|
||||||
|
'sampler_priority',
|
||||||
'n',
|
'n',
|
||||||
'logit_bias',
|
'logit_bias',
|
||||||
'custom_model',
|
'custom_model',
|
||||||
@@ -422,7 +438,7 @@ function loadTextGenSettings(data, loadedSettings) {
|
|||||||
* Sorts the sampler items by the given order.
|
* Sorts the sampler items by the given order.
|
||||||
* @param {any[]} orderArray Sampler order array.
|
* @param {any[]} orderArray Sampler order array.
|
||||||
*/
|
*/
|
||||||
function sortItemsByOrder(orderArray) {
|
function sortKoboldItemsByOrder(orderArray) {
|
||||||
console.debug('Preset samplers order: ' + orderArray);
|
console.debug('Preset samplers order: ' + orderArray);
|
||||||
const $draggableItems = $('#koboldcpp_order');
|
const $draggableItems = $('#koboldcpp_order');
|
||||||
|
|
||||||
@@ -433,6 +449,16 @@ function sortItemsByOrder(orderArray) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortOobaItemsByOrder(orderArray) {
|
||||||
|
console.debug('Preset samplers order: ', orderArray);
|
||||||
|
const $container = $('#sampler_priority_container');
|
||||||
|
|
||||||
|
orderArray.forEach((name) => {
|
||||||
|
const $item = $container.find(`[data-name="${name}"]`).detach();
|
||||||
|
$container.append($item);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
jQuery(function () {
|
jQuery(function () {
|
||||||
$('#koboldcpp_order').sortable({
|
$('#koboldcpp_order').sortable({
|
||||||
delay: getSortableDelay(),
|
delay: getSortableDelay(),
|
||||||
@@ -449,7 +475,27 @@ jQuery(function () {
|
|||||||
|
|
||||||
$('#koboldcpp_default_order').on('click', function () {
|
$('#koboldcpp_default_order').on('click', function () {
|
||||||
settings.sampler_order = KOBOLDCPP_ORDER;
|
settings.sampler_order = KOBOLDCPP_ORDER;
|
||||||
sortItemsByOrder(settings.sampler_order);
|
sortKoboldItemsByOrder(settings.sampler_order);
|
||||||
|
saveSettingsDebounced();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#sampler_priority_container').sortable({
|
||||||
|
delay: getSortableDelay(),
|
||||||
|
stop: function () {
|
||||||
|
const order = [];
|
||||||
|
$('#sampler_priority_container').children().each(function () {
|
||||||
|
order.push($(this).data('name'));
|
||||||
|
});
|
||||||
|
settings.sampler_priority = order;
|
||||||
|
console.log('Samplers reordered:', settings.sampler_priority);
|
||||||
|
saveSettingsDebounced();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#textgenerationwebui_default_order').on('click', function () {
|
||||||
|
sortOobaItemsByOrder(OOBA_DEFAULT_ORDER);
|
||||||
|
settings.sampler_priority = OOBA_DEFAULT_ORDER;
|
||||||
|
console.log('Default samplers order loaded:', settings.sampler_priority);
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -536,6 +582,7 @@ jQuery(function () {
|
|||||||
'penalty_alpha_textgenerationwebui': 0,
|
'penalty_alpha_textgenerationwebui': 0,
|
||||||
'typical_p_textgenerationwebui': 1, // Added entry
|
'typical_p_textgenerationwebui': 1, // Added entry
|
||||||
'guidance_scale_textgenerationwebui': 1,
|
'guidance_scale_textgenerationwebui': 1,
|
||||||
|
'smoothing_factor_textgenerationwebui': 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const [id, value] of Object.entries(inputs)) {
|
for (const [id, value] of Object.entries(inputs)) {
|
||||||
@@ -615,11 +662,18 @@ function setSettingByName(setting, value, trigger) {
|
|||||||
|
|
||||||
if ('sampler_order' === setting) {
|
if ('sampler_order' === setting) {
|
||||||
value = Array.isArray(value) ? value : KOBOLDCPP_ORDER;
|
value = Array.isArray(value) ? value : KOBOLDCPP_ORDER;
|
||||||
sortItemsByOrder(value);
|
sortKoboldItemsByOrder(value);
|
||||||
settings.sampler_order = value;
|
settings.sampler_order = value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('sampler_priority' === setting) {
|
||||||
|
value = Array.isArray(value) ? value : OOBA_DEFAULT_ORDER;
|
||||||
|
sortOobaItemsByOrder(value);
|
||||||
|
settings.sampler_priority = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ('logit_bias' === setting) {
|
if ('logit_bias' === setting) {
|
||||||
settings.logit_bias = Array.isArray(value) ? value : [];
|
settings.logit_bias = Array.isArray(value) ? value : [];
|
||||||
return;
|
return;
|
||||||
@@ -827,6 +881,7 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate,
|
|||||||
'dynatemp_range': settings.dynatemp ? (settings.max_temp - settings.min_temp) / 2 : 0,
|
'dynatemp_range': settings.dynatemp ? (settings.max_temp - settings.min_temp) / 2 : 0,
|
||||||
'dynatemp_exponent': settings.dynatemp ? settings.dynatemp_exponent : 1,
|
'dynatemp_exponent': settings.dynatemp ? settings.dynatemp_exponent : 1,
|
||||||
'smoothing_factor': settings.smoothing_factor,
|
'smoothing_factor': settings.smoothing_factor,
|
||||||
|
'sampler_priority': settings.type === OOBA ? settings.sampler_priority : undefined,
|
||||||
'stopping_strings': getStoppingStrings(isImpersonate, isContinue),
|
'stopping_strings': getStoppingStrings(isImpersonate, isContinue),
|
||||||
'stop': getStoppingStrings(isImpersonate, isContinue),
|
'stop': getStoppingStrings(isImpersonate, isContinue),
|
||||||
'truncation_length': max_context,
|
'truncation_length': max_context,
|
||||||
|
Reference in New Issue
Block a user