Remove CFG for Novel, fix logitbias and text adventure bans for Erato

This commit is contained in:
Cohee 2024-09-24 08:12:50 +00:00
parent 8775247942
commit 26f4d1a4ad
22 changed files with 51 additions and 96 deletions

View File

@ -14,7 +14,6 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "medium",
"max_context": 7800,
"min_p": 0,

View File

@ -1,5 +1,5 @@
{
"order": [6, 0, 1, 2, 3],
"order": [0, 1, 2, 3],
"temperature": 1,
"max_length": 150,
"min_length": 1,
@ -14,7 +14,6 @@
"return_full_text": false,
"prefix": "vanilla",
"phrase_rep_pen": "medium",
"cfg_scale": 1.55,
"max_context": 7800,
"min_p": 0,
"math1_temp": 1,

View File

@ -1,5 +1,5 @@
{
"order": [6, 2, 3, 1, 0],
"order": [2, 3, 1, 0],
"temperature": 1,
"max_length": 150,
"min_length": 1,
@ -15,7 +15,6 @@
"return_full_text": false,
"prefix": "vanilla",
"phrase_rep_pen": "very_aggressive",
"cfg_scale": 1.3,
"max_context": 7800,
"min_p": 0,
"math1_temp": 1,

View File

@ -15,7 +15,6 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "aggressive",
"max_context": 7800,
"min_p": 0,

View File

@ -1,5 +1,5 @@
{
"order": [8, 6, 5, 0, 3],
"order": [8, 5, 0, 3],
"temperature": 0.9,
"max_length": 150,
"min_length": 1,
@ -15,7 +15,6 @@
"return_full_text": false,
"prefix": "vanilla",
"phrase_rep_pen": "off",
"cfg_scale": 1.48,
"max_context": 7800,
"min_p": 0,
"math1_temp": 1,

View File

@ -15,7 +15,6 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "very_light",
"max_context": 7800,
"min_p": 0,

View File

@ -16,7 +16,6 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "very_light",
"max_context": 7800,
"min_p": 0,

View File

@ -14,7 +14,6 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "off",
"max_context": 7800,
"min_p": 0,

View File

@ -1,5 +1,5 @@
{
"order": [6, 0, 8, 5, 3],
"order": [0, 8, 5, 3],
"temperature": 1.5,
"max_length": 150,
"min_length": 1,
@ -15,7 +15,6 @@
"return_full_text": false,
"prefix": "vanilla",
"phrase_rep_pen": "very_aggressive",
"cfg_scale": 1.4,
"max_context": 7800,
"min_p": 0,
"math1_temp": 1,

View File

@ -16,7 +16,6 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "very_light",
"max_context": 7800,
"min_p": 0,

View File

@ -16,7 +16,6 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "very_light",
"max_context": 7800,
"min_p": 0,

View File

@ -1,5 +1,5 @@
{
"order": [6, 0, 4, 1, 2, 5, 3],
"order": [0, 4, 1, 2, 5, 3],
"temperature": 1.31,
"max_length": 150,
"min_length": 1,
@ -17,7 +17,6 @@
"return_full_text": false,
"prefix": "vanilla",
"phrase_rep_pen": "medium",
"cfg_scale": 1.35,
"max_context": 7800,
"min_p": 0,
"math1_temp": 1,

View File

@ -15,7 +15,6 @@
"return_full_text": false,
"prefix": "vanilla",
"phrase_rep_pen": "medium",
"cfg_scale": 1.0,
"max_context": 7800,
"min_p": 0,
"math1_temp": 1,

View File

@ -16,7 +16,6 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "very_light",
"max_context": 7800,
"min_p": 0,

View File

@ -14,7 +14,6 @@
"return_full_text": false,
"prefix": "vanilla",
"phrase_rep_pen": "aggressive",
"cfg_scale": 1.0,
"max_context": 7800,
"min_p": 0,
"math1_temp": 1,

View File

@ -1,5 +1,5 @@
{
"order": [6, 0, 5],
"order": [0, 5],
"temperature": 0.895,
"max_length": 150,
"min_length": 1,
@ -13,7 +13,6 @@
"return_full_text": false,
"prefix": "vanilla",
"phrase_rep_pen": "aggressive",
"cfg_scale": 1.3,
"max_context": 7800,
"min_p": 0,
"math1_temp": 1,

View File

@ -16,14 +16,12 @@
"math1_quad_entropy_scale": 0,
"min_length": 1,
"prefix": "vanilla",
"cfg_uc": "",
"banned_tokens": "",
"order": [
0,
10
],
"phrase_rep_pen": "off",
"cfg_scale": 1,
"mirostat_lr": 0,
"mirostat_tau": 0
}

View File

@ -16,7 +16,6 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "very_light",
"max_context": 7800,
"min_p": 0,

View File

@ -417,7 +417,6 @@
"preset_settings_novel": "Talker-Chat-Clio",
"streaming_novel": true,
"preamble": "[ Style: chat, complex, sensory, visceral ]",
"cfg_uc": "",
"banned_tokens": "",
"order": [
1,

View File

@ -532,32 +532,6 @@
<div class="logit_bias_list"></div>
</div>
</div>
<div class="range-block">
<hr>
<div class="range-block-title justifyLeft" data-i18n="CFG Scale">
CFG Scale
</div>
<div class="range-block-range-and-counter">
<div class="range-block-range">
<input type="range" id="cfg_scale_novel" name="volume" min="1" max="3" step="0.05">
</div>
<div class="range-block-counter">
<input type="number" min="1" max="3" step="0.05" data-for="cfg_scale_novel" id="cfg_scale_counter_novel">
</div>
</div>
</div>
<div class="range-block">
<div class="range-block-title justifyLeft">
<span data-i18n="Negative Prompt">Negative Prompt</span>
</div>
<div class="wide100p">
<textarea id="nai_cfg_uc" class="text_pole textarea_compact" name="cfg_uc" rows="2" data-i18n="[placeholder]Add text here that would make the AI generate things you don't want in your outputs." placeholder="Add text here that would make the AI generate things you don't want in your outputs."></textarea>
</div>
<small class="margin-bot-10px" data-i18n="Used if CFG Scale is unset globally, per chat or character">
Used if CFG Scale is unset globally, per chat or character
</small>
<hr>
</div>
</div>
<div id="range_block_openai">
<div class="range-block">
@ -1154,12 +1128,7 @@
<small>5</small>
<div class="toggle_button right_menu_button"></div>
</div>
<div data-id="6">
<span data-i18n="CFG">CFG</span>
<small>6</small>
<div class="toggle_button right_menu_button"></div>
</div>
<!-- Yes, there is no 7. It was a removed Top G sampling. RIP. -->
<!-- 6 and 7 were removed samplers. -->
<div data-id="8">
<span data-i18n="Mirostat">Mirostat</span>
<small>8</small>

View File

@ -49,7 +49,6 @@ export const nai_settings = {
streaming_novel: false,
preamble: default_preamble,
prefix: '',
cfg_uc: '',
banned_tokens: '',
order: default_order,
logit_bias: [],
@ -146,12 +145,10 @@ export function loadNovelPreset(preset) {
nai_settings.top_a = preset.top_a;
nai_settings.typical_p = preset.typical_p;
nai_settings.min_length = preset.min_length;
nai_settings.cfg_scale = preset.cfg_scale;
nai_settings.phrase_rep_pen = preset.phrase_rep_pen;
nai_settings.mirostat_lr = preset.mirostat_lr;
nai_settings.mirostat_tau = preset.mirostat_tau;
nai_settings.prefix = preset.prefix;
nai_settings.cfg_uc = preset.cfg_uc || '';
nai_settings.banned_tokens = preset.banned_tokens || '';
nai_settings.order = preset.order || default_order;
nai_settings.logit_bias = preset.logit_bias || [];
@ -187,13 +184,11 @@ export function loadNovelSettings(settings) {
nai_settings.typical_p = settings.typical_p;
nai_settings.min_length = settings.min_length;
nai_settings.phrase_rep_pen = settings.phrase_rep_pen;
nai_settings.cfg_scale = settings.cfg_scale;
nai_settings.mirostat_lr = settings.mirostat_lr;
nai_settings.mirostat_tau = settings.mirostat_tau;
nai_settings.streaming_novel = !!settings.streaming_novel;
nai_settings.preamble = settings.preamble || default_preamble;
nai_settings.prefix = settings.prefix;
nai_settings.cfg_uc = settings.cfg_uc || '';
nai_settings.banned_tokens = settings.banned_tokens || '';
nai_settings.order = settings.order || default_order;
nai_settings.logit_bias = settings.logit_bias || [];
@ -227,8 +222,6 @@ function loadNovelSettingsUi(ui_settings) {
$('#top_a_counter_novel').val(Number(ui_settings.top_a).toFixed(3));
$('#typical_p_novel').val(ui_settings.typical_p);
$('#typical_p_counter_novel').val(Number(ui_settings.typical_p).toFixed(3));
$('#cfg_scale_novel').val(ui_settings.cfg_scale);
$('#cfg_scale_counter_novel').val(Number(ui_settings.cfg_scale).toFixed(2));
$('#phrase_rep_pen_novel').val(ui_settings.phrase_rep_pen || 'off');
$('#mirostat_lr_novel').val(ui_settings.mirostat_lr);
$('#mirostat_lr_counter_novel').val(Number(ui_settings.mirostat_lr).toFixed(2));
@ -238,7 +231,6 @@ function loadNovelSettingsUi(ui_settings) {
$('#min_length_counter_novel').val(Number(ui_settings.min_length).toFixed(0));
$('#nai_preamble_textarea').val(ui_settings.preamble);
$('#nai_prefix').val(ui_settings.prefix || 'vanilla');
$('#nai_cfg_uc').val(ui_settings.cfg_uc || '');
$('#nai_banned_tokens').val(ui_settings.banned_tokens || '');
$('#min_p_novel').val(ui_settings.min_p);
$('#min_p_counter_novel').val(Number(ui_settings.min_p).toFixed(3));
@ -333,24 +325,12 @@ const sliders = [
format: (val) => Number(val).toFixed(2),
setValue: (val) => { nai_settings.mirostat_lr = Number(val).toFixed(2); },
},
{
sliderId: '#cfg_scale_novel',
counterId: '#cfg_scale_counter_novel',
format: (val) => `${val}`,
setValue: (val) => { nai_settings.cfg_scale = Number(val).toFixed(2); },
},
{
sliderId: '#min_length_novel',
counterId: '#min_length_counter_novel',
format: (val) => `${val}`,
setValue: (val) => { nai_settings.min_length = Number(val).toFixed(0); },
},
{
sliderId: '#nai_cfg_uc',
counterId: '#nai_cfg_uc_counter',
format: (val) => val,
setValue: (val) => { nai_settings.cfg_uc = val; },
},
{
sliderId: '#nai_banned_tokens',
counterId: '#nai_banned_tokens_counter',
@ -468,11 +448,8 @@ function getBadWordPermutations(text) {
return result.filter(onlyUnique);
}
export function getNovelGenerationData(finalPrompt, settings, maxLength, isImpersonate, isContinue, cfgValues, type) {
export function getNovelGenerationData(finalPrompt, settings, maxLength, isImpersonate, isContinue, _cfgValues, type) {
console.debug('NovelAI generation data for', type);
if (cfgValues && cfgValues.guidanceScale && cfgValues.guidanceScale?.value !== 1) {
cfgValues.negativePrompt = (getCfgPrompt(cfgValues.guidanceScale, true))?.value;
}
const tokenizerType = getTokenizerTypeForModel(nai_settings.model_novel);
const stopSequences = (tokenizerType !== tokenizers.NONE)
@ -528,8 +505,6 @@ export function getNovelGenerationData(finalPrompt, settings, maxLength, isImper
'typical_p': Number(nai_settings.typical_p),
'mirostat_lr': Number(nai_settings.mirostat_lr),
'mirostat_tau': Number(nai_settings.mirostat_tau),
'cfg_scale': cfgValues?.guidanceScale?.value ?? Number(nai_settings.cfg_scale),
'cfg_uc': cfgValues?.negativePrompt ?? substituteParams(nai_settings.cfg_uc) ?? '',
'phrase_rep_pen': nai_settings.phrase_rep_pen,
'stop_sequences': stopSequences,
'bad_words_ids': badWordIds,

View File

@ -48,6 +48,11 @@ const logitBiasExp = [
{ 'sequence': [21], 'bias': -0.08, 'ensure_sequence_finish': false, 'generate_once': false },
];
const eratoLogitBiasExp = [
{ 'sequence': [12488], 'bias': -0.08, 'ensure_sequence_finish': false, 'generate_once': false },
{ 'sequence': [128041], 'bias': -0.08, 'ensure_sequence_finish': false, 'generate_once': false },
];
function getBadWordsList(model) {
let list = [];
@ -63,6 +68,28 @@ function getBadWordsList(model) {
return list.slice();
}
function getLogitBiasList(model) {
let list = [];
if (model.includes('erato')) {
list = eratoLogitBiasExp;
}
if (model.includes('clio') || model.includes('kayra')) {
list = logitBiasExp;
}
return list.slice();
}
function getRepPenaltyWhitelist(model) {
if (model.includes('clio') || model.includes('kayra')) {
return repPenaltyAllowList.flat();
}
return null;
}
const router = express.Router();
router.post('/status', jsonParser, async function (req, res) {
@ -116,11 +143,10 @@ router.post('/generate', jsonParser, async function (req, res) {
controller.abort();
});
const isNewModel = (req.body.model.includes('clio') || req.body.model.includes('kayra') || req.body.model.includes('erato'));
// Add customized bad words for Clio, Kayra, and Erato
const badWordsList = getBadWordsList(req.body.model);
// Add customized bad words for Clio, Kayra, and Erato
if (isNewModel && Array.isArray(req.body.bad_words_ids)) {
if (Array.isArray(badWordsList) && Array.isArray(req.body.bad_words_ids)) {
for (const badWord of req.body.bad_words_ids) {
if (Array.isArray(badWord) && badWord.every(x => Number.isInteger(x))) {
badWordsList.push(badWord);
@ -136,12 +162,14 @@ router.post('/generate', jsonParser, async function (req, res) {
}
// Add default biases for dinkus and asterism
const logit_bias_exp = isNewModel ? logitBiasExp.slice() : [];
const logitBiasList = getLogitBiasList(req.body.model);
if (Array.isArray(logit_bias_exp) && Array.isArray(req.body.logit_bias_exp)) {
logit_bias_exp.push(...req.body.logit_bias_exp);
if (Array.isArray(logitBiasList) && Array.isArray(req.body.logit_bias_exp)) {
logitBiasList.push(...req.body.logit_bias_exp);
}
const repPenWhitelist = getRepPenaltyWhitelist(req.body.model);
const data = {
'input': req.body.input,
'model': req.body.model,
@ -156,19 +184,17 @@ router.post('/generate', jsonParser, async function (req, res) {
'repetition_penalty_slope': req.body.repetition_penalty_slope,
'repetition_penalty_frequency': req.body.repetition_penalty_frequency,
'repetition_penalty_presence': req.body.repetition_penalty_presence,
'repetition_penalty_whitelist': isNewModel ? repPenaltyAllowList.flat() : null,
'repetition_penalty_whitelist': repPenWhitelist,
'top_a': req.body.top_a,
'top_p': req.body.top_p,
'top_k': req.body.top_k,
'typical_p': req.body.typical_p,
'mirostat_lr': req.body.mirostat_lr,
'mirostat_tau': req.body.mirostat_tau,
'cfg_scale': req.body.cfg_scale,
'cfg_uc': req.body.cfg_uc,
'phrase_rep_pen': req.body.phrase_rep_pen,
'stop_sequences': req.body.stop_sequences,
'bad_words_ids': badWordsList.length ? badWordsList : null,
'logit_bias_exp': logit_bias_exp,
'logit_bias_exp': logitBiasList,
'generate_until_sentence': req.body.generate_until_sentence,
'use_cache': req.body.use_cache,
'return_full_text': req.body.return_full_text,
@ -183,8 +209,13 @@ router.post('/generate', jsonParser, async function (req, res) {
};
// Tells the model to stop generation at '>'
if ('theme_textadventure' === req.body.prefix && isNewModel && !req.body.model.includes('erato')) {
data.parameters.eos_token_id = 49405;
if ('theme_textadventure' === req.body.prefix) {
if (req.body.model.includes('clio') || req.body.model.includes('kayra')) {
data.parameters.eos_token_id = 49405;
}
if (req.body.model.includes('erato')) {
data.parameters.eos_token_id = 29;
}
}
console.log(util.inspect(data, { depth: 4 }));