embetterify Sampler Select function

7acc78db0ac4fe81b8a97c8018ab2b61c990686d

RossAscends <124905043+RossAscends@users.noreply.github.com>

2 files changed, +142 -146Showing whitespace changes
public/index.html+8 -8
@@ -1273,7 +1273,7 @@
1273 <input class="neo-range-slider" type="range" id="max_tokens_second_textgenerationwebui" name="volume" min="0" max="20" step="1" />1273 <input class="neo-range-slider" type="range" id="max_tokens_second_textgenerationwebui" name="volume" min="0" max="20" step="1" />
1274 <input class="neo-range-input" type="number" min="0" max="20" step="1" data-for="max_tokens_second_textgenerationwebui" id="max_tokens_second_counter_textgenerationwebui">1274 <input class="neo-range-input" type="number" min="0" max="20" step="1" data-for="max_tokens_second_textgenerationwebui" id="max_tokens_second_counter_textgenerationwebui">
1275 </div>1275 </div>
1276 <div data-newbie-hidden data-tg-type="mancer, ooba, koboldcpp, aphrodite, tabby" name="smoothingBlock" class="wide100p">1276 <div data-newbie-hidden data-tg-type="mancer, ooba, koboldcpp, aphrodite, tabby" id="smoothingBlock" name="smoothingBlock" class="wide100p">
1277 <h4 class="wide100p textAlignCenter">1277 <h4 class="wide100p textAlignCenter">
1278 <label data-i18n="Smooth Sampling">Smooth Sampling</label>1278 <label data-i18n="Smooth Sampling">Smooth Sampling</label>
1279 <div class=" fa-solid fa-circle-info opacity50p " data-i18n="[title]Smooth_Sampling_desc" title="Allows you to use quadratic/cubic transformations to adjust the distribution. Lower Smoothing Factor values will be more creative, usually between 0.2-0.3 is the sweetspot (assuming the curve = 1). Higher Smoothing Curve values will make the curve steeper, which will punish low probability choices more aggressively. 1.0 curve is equivalent to only using Smoothing Factor."></div>1279 <div class=" fa-solid fa-circle-info opacity50p " data-i18n="[title]Smooth_Sampling_desc" title="Allows you to use quadratic/cubic transformations to adjust the distribution. Lower Smoothing Factor values will be more creative, usually between 0.2-0.3 is the sweetspot (assuming the curve = 1). Higher Smoothing Curve values will make the curve steeper, which will punish low probability choices more aggressively. 1.0 curve is equivalent to only using Smoothing Factor."></div>
@@ -1387,7 +1387,7 @@
1387 </div>1387 </div>
1388 </div>1388 </div>
1389 </div>1389 </div>
1390 <div data-newbie-hidden data-tg-type="ooba, vllm" name="beamSearchBlock" class="wide100p">1390 <div data-newbie-hidden data-tg-type="ooba, vllm" id="beamSearchBlock" name="beamSearchBlock" class="wide100p">
1391 <h4 class="wide100p textAlignCenter">1391 <h4 class="wide100p textAlignCenter">
1392 <label>1392 <label>
1393 <span data-i18n="Beam search">Beam Search</span>1393 <span data-i18n="Beam search">Beam Search</span>
@@ -1413,7 +1413,7 @@
1413 </div>1413 </div>
1414 </div>1414 </div>
1415 </div>1415 </div>
1416 <div data-tg-type="ooba" data-newbie-hidden name="contrastiveSearchBlock" class="alignitemscenter flex-container flexFlowColumn flexBasis48p flexGrow flexShrink gap0">1416 <div data-tg-type="ooba" data-newbie-hidden id="contrastiveSearchBlock" name="contrastiveSearchBlock" class="alignitemscenter flex-container flexFlowColumn flexBasis48p flexGrow flexShrink gap0">
1417 <h4 class="textAlignCenter" data-i18n="Contrastive search">Contrastive Search1417 <h4 class="textAlignCenter" data-i18n="Contrastive search">Contrastive Search
1418 <div class=" fa-solid fa-circle-info opacity50p " data-i18n="Contrastive_search_txt" title="A sampler that encourages diversity while maintaining coherence, by exploiting the isotropicity of the representation space of most LLMs. For details, see the paper A Contrastive Framework for Neural Text Generation by Su et al. (2022)."></div>1418 <div class=" fa-solid fa-circle-info opacity50p " data-i18n="Contrastive_search_txt" title="A sampler that encourages diversity while maintaining coherence, by exploiting the isotropicity of the representation space of most LLMs. For details, see the paper A Contrastive Framework for Neural Text Generation by Su et al. (2022)."></div>
1419 </h4>1419 </h4>
@@ -1554,13 +1554,13 @@
1554 </h4>1554 </h4>
1555 <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>1555 <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>
1556 </div>1556 </div>
1557 <div id="sampler_order_block" data-newbie-hidden data-tg-type="koboldcpp" class="range-block flexFlowColumn wide100p">1557 <div id="sampler_order_block_kcpp" data-newbie-hidden data-tg-type="koboldcpp" class="range-block flexFlowColumn wide100p">
1558 <hr class="wide100p">1558 <hr class="wide100p">
1559 <div class="range-block-title">1559 <div class="range-block-title">
1560 <span data-i18n="Samplers Order">Samplers Order</span>1560 <span data-i18n="Samplers Order">Samplers Order</span>
1561 </div>1561 </div>
1562 <div class="toggle-description widthUnset" data-i18n="Samplers will be applied in a top-down order. Use with caution.">1562 <div class="toggle-description widthUnset" data-i18n="Samplers will be applied in a top-down order. Use with caution.">
1563 Samplers will be applied in a top-down order.1563 kcpp only. Samplers will be applied in a top-down order.
1564 Use with caution.1564 Use with caution.
1565 </div>1565 </div>
1566 <div id="koboldcpp_order" class="prompt_order">1566 <div id="koboldcpp_order" class="prompt_order">
@@ -1597,10 +1597,10 @@
1597 <span data-i18n="Load default order">Load default order</span>1597 <span data-i18n="Load default order">Load default order</span>
1598 </div>1598 </div>
1599 </div>1599 </div>
1600 <div data-newbie-hidden data-tg-type="llamacpp" class="range-block flexFlowColumn wide100p">1600 <div id="sampler_order_block_lcpp" data-newbie-hidden data-tg-type="llamacpp" class="range-block flexFlowColumn wide100p">
1601 <hr class="wide100p">1601 <hr class="wide100p">
1602 <h4 class="range-block-title justifyCenter">1602 <h4 class="range-block-title justifyCenter">
1603 <span data-i18n="Samplers Order">Samplers Order</span>1603 <span data-i18n="Sampler Order">Sampler Order</span>
1604 <div class="margin5 fa-solid fa-circle-info opacity50p" data-i18n="[title]llama.cpp only. Determines the order of samplers. If Mirostat mode is not 0, sampler order is ignored." title="llama.cpp only. Determines the order of samplers. If Mirostat mode is not 0, sampler order is ignored."></div>1604 <div class="margin5 fa-solid fa-circle-info opacity50p" data-i18n="[title]llama.cpp only. Determines the order of samplers. If Mirostat mode is not 0, sampler order is ignored." title="llama.cpp only. Determines the order of samplers. If Mirostat mode is not 0, sampler order is ignored."></div>
1605 </h4>1605 </h4>
1606 <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.">1606 <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.">
@@ -1618,7 +1618,7 @@
1618 <span data-i18n="Load default order">Load default order</span>1618 <span data-i18n="Load default order">Load default order</span>
1619 </div>1619 </div>
1620 </div>1620 </div>
1621 <div data-newbie-hidden data-tg-type="ooba" class="range-block flexFlowColumn wide100p">1621 <div id="sampler_priority_block_ooba" data-newbie-hidden data-tg-type="ooba" class="range-block flexFlowColumn wide100p">
1622 <hr class="wide100p">1622 <hr class="wide100p">
1623 <h4 class="range-block-title justifyCenter">1623 <h4 class="range-block-title justifyCenter">
1624 <span data-i18n="Sampler Priority">Sampler Priority</span>1624 <span data-i18n="Sampler Priority">Sampler Priority</span>
public/scripts/samplerSelect.js+134 -138
@@ -1,9 +1,7 @@
1import {1import {
2 main_api,2 main_api,
3 saveSettingsDebounced,3 saveSettingsDebounced,
4 novelai_setting_names,
5 callPopup,4 callPopup,
6 settings,
7} from '../script.js';5} from '../script.js';
8import { power_user } from './power-user.js';6import { power_user } from './power-user.js';
9//import { BIAS_CACHE, displayLogitBias, getLogitBiasListResult } from './logit-bias.js';7//import { BIAS_CACHE, displayLogitBias, getLogitBiasListResult } from './logit-bias.js';
@@ -20,132 +18,6 @@ const forcedOffColoring = 'filter: sepia(1) hue-rotate(308deg) contrast(0.7) sat
2018
21let userDisabledSamplers, userShownSamplers;19let userDisabledSamplers, userShownSamplers;
2220
23/*
24
25for reference purposes:
26
27//NAI
28const nai_settings = {
29 temperature: 1.5,
30 repetition_penalty: 2.25,
31 repetition_penalty_range: 2048,
32 repetition_penalty_slope: 0.09,
33 repetition_penalty_frequency: 0,
34 repetition_penalty_presence: 0.005,
35 tail_free_sampling: 0.975,
36 top_k: 10,
37 top_p: 0.75,
38 top_a: 0.08,
39 typical_p: 0.975,
40 min_length: 1,
41 model_novel: 'clio-v1',
42 preset_settings_novel: 'Talker-Chat-Clio',
43 streaming_novel: false,
44 preamble: default_preamble,
45 prefix: '',
46 cfg_uc: '',
47 banned_tokens: '',
48 order: default_order,
49 logit_bias: [],
50};
51
52// TG Types
53export const textgen_types = {
54 OOBA: 'ooba',
55 MANCER: 'mancer',
56 VLLM: 'vllm',
57 APHRODITE: 'aphrodite',
58 TABBY: 'tabby',
59 KOBOLDCPP: 'koboldcpp',
60 TOGETHERAI: 'togetherai',
61 LLAMACPP: 'llamacpp',
62 OLLAMA: 'ollama',
63 INFERMATICAI: 'infermaticai',
64 DREAMGEN: 'dreamgen',
65 OPENROUTER: 'openrouter',
66};
67
68//KAI and TextGen
69const setting_names = [
70 'temp',
71 'temperature_last',
72 'rep_pen',
73 'rep_pen_range',
74 'no_repeat_ngram_size',
75 'top_k',
76 'top_p',
77 'top_a',
78 'tfs',
79 'epsilon_cutoff',
80 'eta_cutoff',
81 'typical_p',
82 'min_p',
83 'penalty_alpha',
84 'num_beams',
85 'length_penalty',
86 'min_length',
87 'dynatemp',
88 'min_temp',
89 'max_temp',
90 'dynatemp_exponent',
91 'smoothing_factor',
92 'smoothing_curve',
93 'max_tokens_second',
94 'encoder_rep_pen',
95 'freq_pen',
96 'presence_pen',
97 'do_sample',
98 'early_stopping',
99 'seed',
100 'add_bos_token',
101 'ban_eos_token',
102 'skip_special_tokens',
103 'streaming',
104 'mirostat_mode',
105 'mirostat_tau',
106 'mirostat_eta',
107 'guidance_scale',
108 'negative_prompt',
109 'grammar_string',
110 'json_schema',
111 'banned_tokens',
112 'legacy_api',
113 //'n_aphrodite',
114 //'best_of_aphrodite',
115 'ignore_eos_token',
116 'spaces_between_special_tokens',
117 //'logits_processors_aphrodite',
118 //'log_probs_aphrodite',
119 //'prompt_log_probs_aphrodite'
120 'sampler_order',
121 'sampler_priority',
122 'samplers',
123 'n',
124 'logit_bias',
125 'custom_model',
126 'bypass_status_check',
127];
128
129//OAI settings
130
131const default_settings = {
132 preset_settings_openai: 'Default',
133 temp_openai: 1.0,
134 freq_pen_openai: 0,
135 pres_pen_openai: 0,
136 count_pen: 0.0,
137 top_p_openai: 1.0,
138 top_k_openai: 0,
139 min_p_openai: 0,
140 top_a_openai: 1,
141 repetition_penalty_openai: 1,
142 stream_openai: false,
143 //...
144}
145
146
147*/
148
149// Goal 1: show popup with all samplers for active API21// Goal 1: show popup with all samplers for active API
150async function showSamplerSelectPopup() {22async function showSamplerSelectPopup() {
151 const popup = $('#dialogue_popup');23 const popup = $('#dialogue_popup');
@@ -190,6 +62,15 @@ async function showSamplerSelectPopup() {
190 power_user.selectSamplers.forceHidden = [];62 power_user.selectSamplers.forceHidden = [];
191 await validateDisabledSamplers(true);63 await validateDisabledSamplers(true);
192 });64 });
65
66 $('#textgen_type').on('change', async function () {
67 console.log('changed TG Type, resetting custom samplers'); //unfortunate, but necessary unless we save custom samplers for each TGTytpe
68 userDisabledSamplers = [];
69 userShownSamplers = [];
70 power_user.selectSamplers.forceShown = [];
71 power_user.selectSamplers.forceHidden = [];
72 await validateDisabledSamplers();
73 });
193}74}
19475
195function setSamplerListListeners() {76function setSamplerListListeners() {
@@ -221,6 +102,11 @@ function setSamplerListListeners() {
221 targetDisplayType = 'block';102 targetDisplayType = 'block';
222 }103 }
223104
105 if (samplerName === 'dry_multiplier') {
106 relatedDOMElement = $('#dryBlock');
107 targetDisplayType = 'block';
108 }
109
224 if (samplerName === 'dynatemp') {110 if (samplerName === 'dynatemp') {
225 relatedDOMElement = $('#dynatemp_block_ooba');111 relatedDOMElement = $('#dynatemp_block_ooba');
226 targetDisplayType = 'block';112 targetDisplayType = 'block';
@@ -231,9 +117,30 @@ function setSamplerListListeners() {
231 targetDisplayType = 'block';117 targetDisplayType = 'block';
232 }118 }
233119
234 if (samplerName === 'sampler_order') {120 if (samplerName === 'sampler_order') { //this is for kcpp sampler order
235 relatedDOMElement = $('#sampler_order_block');121 relatedDOMElement = $('#sampler_order_block_kcpp');
236 targetDisplayType = 'flex';122 }
123
124 if (samplerName === 'samplers') { //this is for lcpp sampler order
125 relatedDOMElement = $('#sampler_order_block_lcpp');
126 }
127
128 if (samplerName === 'sampler_priority') { //this is for ooba's sampler priority
129 relatedDOMElement = $('#sampler_priority_block_ooba');
130 }
131
132 if (samplerName === 'penalty_alpha') { //contrastive search only has one sampler, does it need its own block?
133 relatedDOMElement = $('#contrastiveSearchBlock');
134 }
135
136 if (samplerName === 'num_beams') { // num_beams is the killswitch for Beam Search
137 relatedDOMElement = $('#beamSearchBlock');
138 targetDisplayType = 'block';
139 }
140
141 if (samplerName === 'smoothing_factor') { // num_beams is the killswitch for Beam Search
142 relatedDOMElement = $('#smoothingBlock');
143 targetDisplayType = 'block';
237 }144 }
238145
239 // Get the current state of the custom data attribute146 // Get the current state of the custom data attribute
@@ -301,7 +208,7 @@ async function listSamplers(main_api, arrayOnly = false) {
301 let availableSamplers;208 let availableSamplers;
302 if (main_api === 'textgenerationwebui') {209 if (main_api === 'textgenerationwebui') {
303 availableSamplers = TGsamplerNames;210 availableSamplers = TGsamplerNames;
304 const valuesToRemove = new Set(['streaming', 'seed', 'bypass_status_check', 'custom_model', 'legacy_api', 'samplers']);211 const valuesToRemove = new Set(['streaming', 'bypass_status_check', 'custom_model', 'legacy_api']);
305 availableSamplers = availableSamplers.filter(sampler => !valuesToRemove.has(sampler));212 availableSamplers = availableSamplers.filter(sampler => !valuesToRemove.has(sampler));
306 availableSamplers.sort();213 availableSamplers.sort();
307 }214 }
@@ -312,8 +219,70 @@ async function listSamplers(main_api, arrayOnly = false) {
312 }219 }
313220
314 const samplersListHTML = availableSamplers.reduce((html, sampler) => {221 const samplersListHTML = availableSamplers.reduce((html, sampler) => {
315 let customColor;222 let customColor, displayname;
316 const targetDOMelement = $(`#${sampler}_${main_api}`);223 let targetDOMelement = $(`#${sampler}_${main_api}`);
224
225 if (sampler === 'sampler_order') { //this is for kcpp sampler order
226 targetDOMelement = $('#sampler_order_block_kcpp');
227 displayname = 'KCPP Sampler Order Block';
228 }
229
230 if (sampler === 'samplers') { //this is for lcpp sampler order
231 targetDOMelement = $('#sampler_order_block_lcpp');
232 displayname = 'LCPP Sampler Order Block';
233 }
234
235 if (sampler === 'sampler_priority') { //this is for ooba's sampler priority
236 targetDOMelement = $('#sampler_priority_block_ooba');
237 displayname = 'Ooba Sampler Priority Block';
238 }
239
240 if (sampler === 'penalty_alpha') { //contrastive search only has one sampler, does it need its own block?
241 targetDOMelement = $('#contrastiveSearchBlock');
242 displayname = 'Contrast Search Block';
243 }
244
245 if (sampler === 'num_beams') { // num_beams is the killswitch for Beam Search
246 targetDOMelement = $('#beamSearchBlock');
247 displayname = 'Beam Search Block';
248 }
249
250 if (sampler === 'smoothing_factor') { // num_beams is the killswitch for Beam Search
251 targetDOMelement = $('#smoothingBlock');
252 displayname = 'Smoothing Block';
253 }
254
255 if (sampler === 'dry_multiplier') {
256 targetDOMelement = $('#dryBlock');
257 displayname = 'DRY Rep Pen Block';
258 }
259
260 if (sampler === 'dynatemp') {
261 targetDOMelement = $('#dynatemp_block_ooba');
262 displayname = 'DynaTemp Block';
263 }
264
265 if (sampler === 'json_schema') {
266 targetDOMelement = $('#json_schema_block');
267 displayname = 'JSON Schema Block';
268 }
269
270 if (sampler === 'grammar_string') {
271 targetDOMelement = $('#grammar_block_ooba');
272 displayname = 'Grammar Block';
273 }
274
275 if (sampler === 'guidance_scale') {
276 targetDOMelement = $('#cfg_block_ooba');
277 displayname = 'CFG Block';
278 }
279
280 if (sampler === 'mirostat_mode') {
281 targetDOMelement = $('#mirostat_block_ooba');
282 displayname = 'Mirostat Block';
283 }
284
285
317286
318 const isInForceHiddenArray = userDisabledSamplers.includes(sampler);287 const isInForceHiddenArray = userDisabledSamplers.includes(sampler);
319 const isInForceShownArray = userShownSamplers.includes(sampler);288 const isInForceShownArray = userShownSamplers.includes(sampler);
@@ -335,11 +304,12 @@ async function listSamplers(main_api, arrayOnly = false) {
335 }304 }
336 else { return isVisibleInDOM; }305 else { return isVisibleInDOM; }
337 };306 };
338 console.log(sampler, isInDefaultState(), isInForceHiddenArray, shouldBeChecked());307 console.log(sampler, targetDOMelement.prop('id'), isInDefaultState(), isInForceShownArray, isInForceHiddenArray, shouldBeChecked());
308 if (displayname === undefined) { displayname = sampler; }
339 return html + `309 return html + `
340 <div class="sampler_view_list_item wide50p flex-container">310 <div class="sampler_view_list_item wide50p flex-container">
341 <input type="checkbox" name="${sampler}_checkbox" ${shouldBeChecked() ? 'checked' : ''}>311 <input type="checkbox" name="${sampler}_checkbox" ${shouldBeChecked() ? 'checked' : ''}>
342 <small class="sampler_name" style="${customColor}">${sampler}</small>312 <small class="sampler_name" style="${customColor}">${displayname}</small>
343 </div>313 </div>
344 `;314 `;
345 }, '');315 }, '');
@@ -391,8 +361,33 @@ export async function validateDisabledSamplers(redraw = false) {
391 targetDisplayType = 'block';361 targetDisplayType = 'block';
392 }362 }
393363
394 if (sampler === 'sampler_order') {364 if (sampler === 'sampler_order') { //this is for kcpp sampler order
395 relatedDOMElement = $('#sampler_order_block');365 relatedDOMElement = $('#sampler_order_block_kcpp');
366 }
367
368 if (sampler === 'samplers') { //this is for lcpp sampler order
369 relatedDOMElement = $('#sampler_order_block_lcpp');
370 }
371
372 if (sampler === 'sampler_priority') { //this is for ooba's sampler priority
373 relatedDOMElement = $('#sampler_priority_block_ooba');
374 }
375
376 if (sampler === 'dry_multiplier') {
377 relatedDOMElement = $('#dryBlock');
378 targetDisplayType = 'block';
379 }
380
381 if (sampler === 'penalty_alpha') { //contrastive search only has one sampler, does it need its own block?
382 relatedDOMElement = $('#contrastiveSearchBlock');
383 }
384
385 if (sampler === 'num_beams') { // num_beams is the killswitch for Beam Search
386 relatedDOMElement = $('#beamSearchBlock');
387 }
388
389 if (sampler === 'smoothing_factor') { // num_beams is the killswitch for Beam Search
390 relatedDOMElement = $('#smoothingBlock');
396 }391 }
397392
398 if (power_user?.selectSamplers?.forceHidden.includes(sampler)) {393 if (power_user?.selectSamplers?.forceHidden.includes(sampler)) {
@@ -418,6 +413,7 @@ export async function validateDisabledSamplers(redraw = false) {
418 setSamplerListListeners();413 setSamplerListListeners();
419 }414 }
420415
416 await saveSettingsDebounced();
421417
422 }418 }
423}419}