mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-09-03 11:35:48 +02:00
lots of tweaks for ace step
This commit is contained in:
@@ -1685,14 +1685,16 @@
|
||||
"vocal_language": "en",
|
||||
"task_type": "text2music",
|
||||
"seed": 622315,
|
||||
"thinking": false,
|
||||
"lm_temperature": 0.85,
|
||||
"lm_cfg_scale": 2.0,
|
||||
"lm_top_p": 0.9,
|
||||
"lm_temperature": 1.0,
|
||||
"lm_cfg_scale": 3.0,
|
||||
"lm_top_p": 0.95,
|
||||
"lm_top_k": 40,
|
||||
"lm_rep_pen": 1.03,
|
||||
"lm_negative_prompt": "",
|
||||
"inference_steps": 8,
|
||||
"guidance_scale": 1.0,
|
||||
"shift": 3.0,
|
||||
"rewrite_caption": true,
|
||||
"audio_codes": ""
|
||||
},
|
||||
"schema": {
|
||||
|
||||
@@ -67,7 +67,7 @@ label{font-size:12px;color:var(--muted);}
|
||||
}
|
||||
.compact-row{
|
||||
display:grid;
|
||||
grid-template-columns:repeat(auto-fit,minmax(100px,1fr));
|
||||
grid-template-columns:repeat(auto-fit,minmax(80px,1fr));
|
||||
gap:8px;
|
||||
}
|
||||
button{
|
||||
@@ -173,7 +173,8 @@ input[type="checkbox"] {
|
||||
<div class="panel">
|
||||
<h2>Song Setup</h2>
|
||||
|
||||
<label>Caption</label>
|
||||
<label>Caption</label> <div style="float:right"><input id="rewrite_caption" type="checkbox" style="width: auto;vertical-align: middle;" checked><label>Rewrite Caption</label></div>
|
||||
|
||||
<input id="caption" placeholder="Describe the song">
|
||||
|
||||
<div style="margin-top:10px">
|
||||
@@ -196,7 +197,12 @@ input[type="checkbox"] {
|
||||
<div class="compact-row" style="margin-top:10px">
|
||||
<div><label>Temp</label><input id="lm_temperature" type="number" step="0.01"></div>
|
||||
<div><label>CFG</label><input id="lm_cfg_scale" type="number" step="0.1"></div>
|
||||
<div><label>Top P</label><input id="lm_top_p" type="number" step="0.01"></div>
|
||||
<div><label>Top-P</label><input id="lm_top_p" type="number" step="0.01"></div>
|
||||
<div><label>Top-K</label><input id="lm_top_k" type="number"></div>
|
||||
<div><label>RepPen</label><input id="lm_rep_pen" type="number"></div>
|
||||
<div><label>Codes Top-P</label><input id="codes_top_p" type="number"></div>
|
||||
<div><label>Codes Top-K</label><input id="codes_top_k" type="number"></div>
|
||||
<div><label>Codes Temp</label><input id="codes_temperature" type="number"></div>
|
||||
<div><label>Steps</label><input id="inference_steps" type="number"></div>
|
||||
<div><label>Guidance</label><input id="guidance_scale" type="number"></div>
|
||||
<div><label>Shift</label><input id="shift" type="number"></div>
|
||||
@@ -306,7 +312,8 @@ function toggleAdvanced(){
|
||||
|
||||
function getFormData(){
|
||||
const ids=["caption","lyrics","bpm","duration","keyscale","timesignature",
|
||||
"vocal_language","seed","lm_temperature","lm_cfg_scale","lm_top_p","inference_steps",
|
||||
"vocal_language","seed","lm_temperature","lm_cfg_scale","lm_top_p","lm_top_k","lm_rep_pen","inference_steps",
|
||||
"codes_top_p","codes_top_k","codes_temperature",
|
||||
"guidance_scale","shift","audio_codes"];
|
||||
const data={};
|
||||
ids.forEach(id=>{
|
||||
@@ -317,6 +324,7 @@ function getFormData(){
|
||||
});
|
||||
data["stereo"] = (document.getElementById("stereo").checked ? true : false);
|
||||
data["gen_codes"] = (document.getElementById("gen_codes").checked ? true : false);
|
||||
data["rewrite_caption"] = (document.getElementById("rewrite_caption").checked ? true : false);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
+19
-190
@@ -3548,7 +3548,7 @@ Current version indicated by LITEVER below.
|
||||
const favivon_normal =rootStyles.getPropertyValue('--img_favicon_normal').match(/url\("(.*)"\)/)[1];
|
||||
|
||||
// whitelisted auto selected horde model names
|
||||
const defaultmodels = ["gpt4all","supercot","pygmalion-6","pygmalion-v8","pygmalion-2","hermes","airoboros","chrono","wizard","mantis","vicuna","manticore","alpaca","myth","xwin","spicyboros","mlewd","mxlewd","westlake","anubis","skyfall","llama2","llama3","llama-2","llama-3-","llama-3.","mistral","maid","mixtral","estopia","fighter","fimbul","euryale","nemo","gemma","lunaris","stheno","magnum","cydonia","qwen2.5-32b","behemoth","exaone","glm4","glm-4","tutu","deepseek","tlacuilo","rocinante"];
|
||||
const defaultmodels = ["gpt4all","supercot","pygmalion-6","pygmalion-v8","pygmalion-2","hermes","airoboros","chrono","wizard","mantis","vicuna","manticore","alpaca","myth","xwin","spicyboros","mlewd","mxlewd","westlake","anubis","skyfall","llama2","llama3","llama-2","llama-3-","llama-3.","mistral","maid","mixtral","estopia","fighter","fimbul","euryale","nemo","gemma","lunaris","stheno","magnum","cydonia","qwen2.5-32b","behemoth","exaone","glm4","glm-4","tutu","deepseek","tlacuilo","rocinante","-14B","-32B","-27B","-35B"];
|
||||
const ignoredmodels = ["tinyllama","debug-","-1b","-270m"]; //blacklisted model names
|
||||
|
||||
const instructstartplaceholder = "\n{{[INPUT]}}\n";
|
||||
@@ -4138,7 +4138,6 @@ Current version indicated by LITEVER below.
|
||||
const alltalk_voices_endpoint = "/api/voices";
|
||||
const alltalk_rvc_voices_endpoint = "/api/rvcvoices";
|
||||
|
||||
const pollinations_img_endpoint = "https://image.pollinations.ai/prompt";
|
||||
const pollinations_text_endpoint = "https://text.pollinations.ai/openai";
|
||||
const dummy_api_key = "kobo";
|
||||
|
||||
@@ -4169,7 +4168,6 @@ Current version indicated by LITEVER below.
|
||||
const XTTS_ID = 3;
|
||||
const ALLTALK_ID = 4;
|
||||
const OAI_TTS_ID = 5;
|
||||
const POLLINATIONS_TTS_ID = 6;
|
||||
|
||||
const HD_RES_PX = 768;
|
||||
const VHD_RES_PX = 960;
|
||||
@@ -4362,7 +4360,7 @@ Current version indicated by LITEVER below.
|
||||
prev_custom_endpoint_type: 0, //show a reconnect box to custom endpoint if needed. 0 is horde, otherwise its dropdown value+1
|
||||
prev_custom_endpoint_model: "", //we may not be able to match, but set it if we do
|
||||
prev_custom_endpoint_ischatcmpl: true,
|
||||
generate_images_mode: (localflag?0:1), //0=off, 1=horde, 2=a1111, 3=dalle, 4=comfy, 5=pollinations
|
||||
generate_images_mode: (localflag?0:1), //0=off, 1=horde, 2=a1111, 3=dalle, 4=comfy
|
||||
|
||||
autoscroll: true, //automatically scroll to bottom on render
|
||||
printer_view: false, //automatically scroll to bottom on render
|
||||
@@ -9076,71 +9074,6 @@ Current version indicated by LITEVER below.
|
||||
},true);
|
||||
}
|
||||
|
||||
function generate_pollinations_image(req_payload, autoappend)
|
||||
{
|
||||
let splits = req_payload.prompt.split("###");
|
||||
let prompt = splits[0].trim();
|
||||
let negprompt = (splits.length > 1 ? splits[1] : "");
|
||||
|
||||
const pollinations_params = new URLSearchParams({
|
||||
model:req_payload.models[0],
|
||||
seed:Math.floor(Math.random() * 99999999),
|
||||
width: req_payload.params.width,
|
||||
height: req_payload.params.height,
|
||||
nologo: true,
|
||||
private: true,
|
||||
referrer: "koboldai"
|
||||
});
|
||||
|
||||
let gen_endpoint = `${pollinations_img_endpoint}/${encodeURIComponent(prompt)}?${pollinations_params.toString()}`;
|
||||
|
||||
console.log(gen_endpoint);
|
||||
let imgid = "PollAIimg"+(Math.floor(10000 + Math.random() * 90000)).toString();
|
||||
let nimgtag = "[<|p|" + imgid + "|p|>]";
|
||||
if (localsettings.img_newturn) {
|
||||
if(localsettings.opmode == 4)
|
||||
{
|
||||
nimgtag = wrap_newgen_instruct_format(nimgtag,false);
|
||||
}
|
||||
else if(localsettings.opmode == 3)
|
||||
{
|
||||
nimgtag = wrap_newgen_chat_format(nimgtag);
|
||||
}
|
||||
}
|
||||
if(autoappend)
|
||||
{
|
||||
gametext_arr.push(nimgtag);
|
||||
}
|
||||
image_db[imgid] = { done: false, queue: "Generating", result: "", prompt:prompt, poll_category:0 };
|
||||
image_db[imgid].aspect = (req_payload.params.width>=req_payload.params.height*2?5:(req_payload.params.height>=req_payload.params.width*2?4:(req_payload.params.width>req_payload.params.height?2:(req_payload.params.width<req_payload.params.height?1:0))));
|
||||
image_db[imgid].imsource = 0; //0=generated,1=uploaded
|
||||
image_db[imgid].imrefid = "";
|
||||
image_db[imgid].type = 0; //0=image, 1=audio
|
||||
|
||||
fetch(gen_endpoint, {
|
||||
method: 'GET',
|
||||
})
|
||||
.then((response) => {
|
||||
return response.blob(); // Convert the response into a Blob
|
||||
})
|
||||
.then((finalimg) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => {
|
||||
let origImg = reader.result;
|
||||
let imgres = localsettings.img_allowhd?VHD_RES_PX:NO_HD_RES_PX;
|
||||
compressImage(origImg, (newDataUri) => {
|
||||
image_db[imgid].done = true;
|
||||
image_db[imgid].result = newDataUri;
|
||||
}, false, imgres);
|
||||
};
|
||||
reader.readAsDataURL(finalimg);
|
||||
}).catch((error) => {
|
||||
console.log("Generation Error: " + error);
|
||||
msgbox("Image Generation Failed!\n\nCould not generate image with Pollinations.ai, maybe you are rate limited. Try again later.\n");
|
||||
});
|
||||
return imgid;
|
||||
}
|
||||
|
||||
function set_horde_key()
|
||||
{
|
||||
inputBox("Enter AI Horde API Key.\n\nThe same key is used for image and text generation in AI Horde.","AI Horde API Key",localsettings.my_api_key,"Input AI Horde API Key", ()=>{
|
||||
@@ -9154,7 +9087,7 @@ Current version indicated by LITEVER below.
|
||||
|
||||
function set_dalle_key()
|
||||
{
|
||||
inputBox("Enter DALL-E API Key.\n\nNote: DALL-E is known to rephrase and rewrite submitted image prompts before generating, for censorship purposes. There is nothing KoboldAI Lite can do about that. ","DALL-E API Key",localsettings.saved_dalle_key,"Input DALL-E API Key", ()=>{
|
||||
inputBox("Enter OpenAI Compatible Image API Key.\n\nNote: DALL-E is known to rephrase and rewrite submitted image prompts before generating, for censorship purposes. There is nothing KoboldAI Lite can do about that. ","OpenAI Compatible Image API Key",localsettings.saved_dalle_key,"Input OpenAI Compatible Image API Key", ()=>{
|
||||
let userinput = getInputBoxValue();
|
||||
userinput = userinput.trim();
|
||||
if (userinput != null && userinput!="") {
|
||||
@@ -9164,7 +9097,7 @@ Current version indicated by LITEVER below.
|
||||
}
|
||||
function set_dalle_url()
|
||||
{
|
||||
inputBox("Enter DALL-E API URL.\n\nNote: DALL-E is known to rephrase and rewrite submitted image prompts before generating, for censorship purposes. There is nothing KoboldAI Lite can do about that. ","DALL-E API URL",localsettings.saved_dalle_url,"Input DALL-E API URL", ()=>{
|
||||
inputBox("Enter OpenAI Compatible Image API URL.\n\nNote: DALL-E is known to rephrase and rewrite submitted image prompts before generating, for censorship purposes. There is nothing KoboldAI Lite can do about that. ","OpenAI Compatible Image API URL",localsettings.saved_dalle_url,"Input OpenAI Compatible Image API URL", ()=>{
|
||||
let userinput = getInputBoxValue();
|
||||
userinput = userinput.trim();
|
||||
if (userinput != null && userinput!="") {
|
||||
@@ -9176,7 +9109,7 @@ Current version indicated by LITEVER below.
|
||||
}
|
||||
function set_dalle_model()
|
||||
{
|
||||
inputBox("Enter DALL-E API Model Identifier.","DALL-E API Model Identifier",localsettings.saved_dalle_model,"Input DALL-E Model Identifier", ()=>{
|
||||
inputBox("Enter OpenAI Compatible Image API Model Identifier.","OpenAI Compatible Image API Model Identifier",localsettings.saved_dalle_model,"Input OpenAI Compatible Image Model Identifier", ()=>{
|
||||
let userinput = getInputBoxValue();
|
||||
userinput = userinput.trim();
|
||||
if (userinput != null && userinput!="") {
|
||||
@@ -15518,6 +15451,10 @@ Current version indicated by LITEVER below.
|
||||
mainmenu_untab(true);
|
||||
document.getElementById("settingscontainer").classList.remove("hidden");
|
||||
display_settings_tab(current_settings_tab_idx);
|
||||
|
||||
if(localsettings.generate_images_mode>=5){localsettings.generate_images_mode=0;} //todo: temp hack to remove pollinations images
|
||||
if(localsettings.tts_mode>=6){localsettings.tts_mode=0;} //todo: temp hack to remove pollinations tts
|
||||
|
||||
document.getElementById("max_context_length").value = document.getElementById("max_context_length_slide").value = localsettings.max_context_length;
|
||||
document.getElementById("max_length").value = document.getElementById("max_length_slide").value = localsettings.max_length;
|
||||
document.getElementById("temperature").value = document.getElementById("temperature_slide").value = localsettings.temperature;
|
||||
@@ -16864,7 +16801,6 @@ Current version indicated by LITEVER below.
|
||||
document.getElementById("generate_images_dalle_container").classList.add("hidden");
|
||||
document.getElementById("generate_images_local_model_container").classList.add("hidden");
|
||||
document.getElementById("generate_images_comfy_container").classList.add("hidden");
|
||||
document.getElementById("generate_images_pollinations_container").classList.add("hidden");
|
||||
if(document.getElementById("generate_images_mode").value==1){
|
||||
document.getElementById("generate_images_model_container").classList.remove("hidden");
|
||||
if(!image_models_fetched)
|
||||
@@ -16883,9 +16819,6 @@ Current version indicated by LITEVER below.
|
||||
}else if(document.getElementById("generate_images_mode").value==4){
|
||||
document.getElementById("generate_images_comfy_container").classList.remove("hidden");
|
||||
connect_to_comfyui(silent);
|
||||
}else if(document.getElementById("generate_images_mode").value==5)
|
||||
{
|
||||
document.getElementById("generate_images_pollinations_container").classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18633,7 +18566,7 @@ Current version indicated by LITEVER below.
|
||||
}
|
||||
let speakprompt = "Enter phrase to speak. Currently selected TTS will be used.";
|
||||
|
||||
if(ssval==XTTS_ID || ssval==ALLTALK_ID || ssval==OAI_TTS_ID || ssval==KCPP_TTS_ID || ssval==POLLINATIONS_TTS_ID)
|
||||
if(ssval==XTTS_ID || ssval==ALLTALK_ID || ssval==OAI_TTS_ID || ssval==KCPP_TTS_ID)
|
||||
{
|
||||
speakprompt = `Enter phrase to speak. Currently selected TTS will be used.<br>
|
||||
<div style="display: inline-flex;">
|
||||
@@ -18669,7 +18602,6 @@ Current version indicated by LITEVER below.
|
||||
{
|
||||
document.getElementById("xtts_container").classList.add("hidden");
|
||||
document.getElementById("oai_tts_container").classList.add("hidden");
|
||||
document.getElementById("pollinations_tts_container").classList.add("hidden");
|
||||
document.getElementById("alltalk_specific_controls").classList.add("hidden");
|
||||
document.getElementById("kcpp_tts_container").classList.add("hidden");
|
||||
document.getElementById("webbrowser_tts_container").classList.add("hidden");
|
||||
@@ -18702,11 +18634,6 @@ Current version indicated by LITEVER below.
|
||||
document.getElementById("oai_tts_container").classList.remove("hidden");
|
||||
document.getElementById("savenarrationsdiv").classList.remove("hidden");
|
||||
document.getElementById("narratestreamingdiv").classList.remove("hidden");
|
||||
}else if(selectedTTS == POLLINATIONS_TTS_ID)
|
||||
{
|
||||
document.getElementById("pollinations_tts_container").classList.remove("hidden");
|
||||
document.getElementById("savenarrationsdiv").classList.remove("hidden");
|
||||
document.getElementById("narratestreamingdiv").classList.remove("hidden");
|
||||
}
|
||||
else if(selectedTTS == KCPP_TTS_ID) {
|
||||
document.getElementById("kcpp_tts_container").classList.remove("hidden");
|
||||
@@ -18839,12 +18766,13 @@ Current version indicated by LITEVER below.
|
||||
function tts_speak(text, do_download=false, do_embed_tts=false, is_test=false)
|
||||
{
|
||||
let ssval = localsettings.tts_mode;
|
||||
let streamallowed = (ssval==XTTS_ID || ssval==ALLTALK_ID || ssval==OAI_TTS_ID || ssval==KCPP_TTS_ID || ssval==POLLINATIONS_TTS_ID);
|
||||
let streamallowed = (ssval==XTTS_ID || ssval==ALLTALK_ID || ssval==OAI_TTS_ID || ssval==KCPP_TTS_ID);
|
||||
if(streamallowed && localsettings.tts_stream && !is_test)
|
||||
{
|
||||
//split into chunks by newline
|
||||
tts_speak_output_queue = [];
|
||||
tts_speak_input_queue = text.split("\n").map(chunk => chunk.trim()).filter(chunk => chunk.length > 0);
|
||||
let text2 = text.replaceAll(". ", ".\n").replaceAll("! ", "!\n").replaceAll("? ", "?\n");
|
||||
tts_speak_input_queue = text2.split("\n").map(chunk => chunk.trim()).filter(chunk => chunk.length > 0);
|
||||
tts_queue_embed = do_embed_tts;
|
||||
tts_queue_download = do_download;
|
||||
}
|
||||
@@ -18928,12 +18856,11 @@ Current version indicated by LITEVER below.
|
||||
}
|
||||
|
||||
|
||||
if(ssval==XTTS_ID || ssval==ALLTALK_ID || ssval==OAI_TTS_ID || ssval==KCPP_TTS_ID || ssval==POLLINATIONS_TTS_ID) //xtts api server
|
||||
if(ssval==XTTS_ID || ssval==ALLTALK_ID || ssval==OAI_TTS_ID || ssval==KCPP_TTS_ID) //xtts api server
|
||||
{
|
||||
let is_xtts = (ssval==XTTS_ID);
|
||||
let is_oai_tts = (ssval==OAI_TTS_ID);
|
||||
let is_kcpp_tts = (ssval==KCPP_TTS_ID);
|
||||
let is_pollinations_tts = (ssval==POLLINATIONS_TTS_ID);
|
||||
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
||||
let audiofile_ref = null;
|
||||
|
||||
@@ -19019,62 +18946,6 @@ Current version indicated by LITEVER below.
|
||||
console.log("XTTS Speak Error: " + error);
|
||||
});
|
||||
}
|
||||
else if(is_pollinations_tts)
|
||||
{
|
||||
const pollinations_params = new URLSearchParams({
|
||||
model:"openai-audio",
|
||||
voice:document.getElementById("pollinations_voices").value,
|
||||
private: true,
|
||||
referrer: "koboldai"
|
||||
});
|
||||
const speechprompt = `Please narrate the following text:\n\n${text}`;
|
||||
|
||||
let gen_endpoint = `${pollinations_text_endpoint}/${encodeURIComponent(speechprompt)}?${pollinations_params.toString()}`;
|
||||
|
||||
fetch(gen_endpoint, {
|
||||
method: 'GET',
|
||||
})
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(data => {
|
||||
audiofile_ref = data.slice(0);
|
||||
return audioContext.decodeAudioData(data);
|
||||
})
|
||||
.then(decodedData => {
|
||||
if(do_download)
|
||||
{
|
||||
tts_download(audiofile_ref);
|
||||
}
|
||||
if(do_embed_tts)
|
||||
{
|
||||
tts_embed_audio(audiofile_ref);
|
||||
}
|
||||
tts_is_processing = false;
|
||||
if(append_to_outqueue)
|
||||
{
|
||||
tts_speak_output_queue.push(decodedData);
|
||||
}
|
||||
else
|
||||
{
|
||||
const playSound = audioContext.createBufferSource();
|
||||
playSound.buffer = decodedData;
|
||||
playSound.connect(audioContext.destination);
|
||||
tts_is_playing = true;
|
||||
update_submit_button(false);
|
||||
playSound.start(audioContext.currentTime);
|
||||
playSound.onended = function() {
|
||||
setTimeout(() => {
|
||||
tts_is_playing = false;
|
||||
update_submit_button(false);
|
||||
console.log("Audio finished playing");
|
||||
},300);
|
||||
};
|
||||
}
|
||||
}).catch((error) => {
|
||||
tts_is_playing = false;
|
||||
tts_is_processing = false;
|
||||
console.log("Pollinations Speak Error: " + error);
|
||||
});
|
||||
}
|
||||
else if(xtts_is_connected)
|
||||
{
|
||||
if(is_xtts)
|
||||
@@ -21668,7 +21539,7 @@ Current version indicated by LITEVER below.
|
||||
{
|
||||
if(localsettings.saved_dalle_key=="" || localsettings.saved_dalle_url=="")
|
||||
{
|
||||
msgbox("Error: A valid DALL-E URL and Key is required to generate images with DALL-E.\nThis is usually the same as your OpenAI API key, but can be customized in settings.","Invalid DALL-E Key");
|
||||
msgbox("Error: A valid OpenAI Compatible Image URL and Key is required to generate images with DALL-E.\nThis is usually the same as your OpenAI API key, but can be customized in settings.","Invalid OpenAI Compatible Image Key");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -21716,12 +21587,6 @@ Current version indicated by LITEVER below.
|
||||
genimg_payload.models = [desired_model];
|
||||
imgid = generate_comfy_image(genimg_payload, autoappend);
|
||||
}
|
||||
else if(localsettings.generate_images_mode==5) //pollinations
|
||||
{
|
||||
let desired_model = document.getElementById("generate_images_pollinations_model").value;
|
||||
genimg_payload.models = [desired_model];
|
||||
imgid = generate_pollinations_image(genimg_payload, autoappend);
|
||||
}
|
||||
|
||||
return imgid;
|
||||
}
|
||||
@@ -22848,7 +22713,8 @@ Current version indicated by LITEVER below.
|
||||
console.log("Replacing with Image: " + matchstr);
|
||||
gametext_arr[i] = gametext_arr[i].replace(matchstr, newstr);
|
||||
//default to llava if supported, and image is self uploaded
|
||||
let desiredvismode = ((image_db[key].imsource==1 && ((is_using_kcpp_with_vision() && image_db[key].type==0) || (is_using_kcpp_with_audio() && image_db[key].type==1)))?3:0);
|
||||
let isoaichat = (document.getElementById("useoaichatcompl").checked && custom_oai_key!="");
|
||||
let desiredvismode = ((image_db[key].imsource==1 && (((is_using_kcpp_with_vision() || isoaichat) && image_db[key].type==0) || ((is_using_kcpp_with_audio() || isoaichat) && image_db[key].type==1)))?3:0);
|
||||
completed_imgs_meta[metaid] = JSON.parse(JSON.stringify(default_imgs_meta));
|
||||
completed_imgs_meta[metaid].prompt = image_db[key].prompt;
|
||||
completed_imgs_meta[metaid].visionmode = desiredvismode;
|
||||
@@ -29711,9 +29577,8 @@ Current version indicated by LITEVER below.
|
||||
<option value="0">[Disabled]</option>
|
||||
<option value="1">AI Horde</option>
|
||||
<option value="2">KCPP / Forge / A1111</option>
|
||||
<option value="3">OpenAI DALL-E</option>
|
||||
<option value="3">OpenAI Compatible Img</option>
|
||||
<option value="4">ComfyUI</option>
|
||||
<option value="5">Pollinations.ai</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -29772,16 +29637,6 @@ Current version indicated by LITEVER below.
|
||||
</tr></table>
|
||||
</div>
|
||||
|
||||
<div id="generate_images_pollinations_container" class="settinglabel hidden settingsbox">
|
||||
<div class="settinglabel" style="display: flex; width: 100%">
|
||||
<div class="justifyleft">Model</div>
|
||||
<select title="Select Image Model" class="form-control push-right" id="generate_images_pollinations_model">
|
||||
<option value="flux" selected>flux</option>
|
||||
<option value="turbo">turbo</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="settinglabel">
|
||||
<div class="justifyleft">Add positive prompt</div>
|
||||
@@ -29901,7 +29756,6 @@ Current version indicated by LITEVER below.
|
||||
<option value="3">XTTS API Server</option>
|
||||
<option value="4">AllTalk API Server</option>
|
||||
<option value="5">OpenAI-Compat. API Server</option>
|
||||
<option value="6">PollinationsAI TTS API</option>
|
||||
</select>
|
||||
</div>
|
||||
<button id="manual_tts" type="button" class="bg_green btn btn-primary" style="margin-left: 2px;" onclick="test_tts()">Test</button>
|
||||
@@ -29972,25 +29826,6 @@ Current version indicated by LITEVER below.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="pollinations_tts_container" class="hidden">
|
||||
<div class="settinglabel">
|
||||
<div class="justifyleft">Voice </div>
|
||||
<div class="push-right">
|
||||
<select class="form-control" id="pollinations_voices" style="margin:0px 0 0;">
|
||||
<option value="alloy">alloy</option>
|
||||
<option value="ash">ash</option>
|
||||
<option value="ballad">ballad</option>
|
||||
<option value="coral">coral</option>
|
||||
<option value="echo">echo</option>
|
||||
<option value="fable">fable</option>
|
||||
<option value="nova" selected>nova</option>
|
||||
<option value="onyx">onyx</option>
|
||||
<option value="sage">sage</option>
|
||||
<option value="shimmer">shimmer</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="kcpp_tts_container" class="hidden">
|
||||
<div class="color_red hidden justifyright" id="nokcpptts">KoboldCpp TTS Unavailable</div>
|
||||
<div class="settinglabel">
|
||||
@@ -30988,13 +30823,7 @@ Current version indicated by LITEVER below.
|
||||
<option style="display:none;" class="custom_model_option" value="custom">[Custom]</option>
|
||||
</select>
|
||||
<select title="Pollinations AI Model Selection" style="padding:4px;display:inline;width:calc(100% - 200px)" class="form-control hidden" id="custom_pollinations_model" onchange="oai_model_change(true)">
|
||||
<option value="bidara">bidara</option>
|
||||
<option value="chickytutor">chickytutor</option>
|
||||
<option value="gemini">gemini</option>
|
||||
<option value="midijourney">midijourney</option>
|
||||
<option value="mistral">mistral</option>
|
||||
<option value="openai">openai</option>
|
||||
<option value="openai-fast">openai-fast</option>
|
||||
<option value="openai-fast" selected>openai-fast</option>
|
||||
<option style="display:none;" class="custom_model_option" value="custom">[Custom]</option>
|
||||
</select>
|
||||
<select title="Nvidia NIM AI Model Selection" style="padding:4px;display:inline;width:calc(100% - 200px)" class="form-control hidden" id="custom_nvidianim_model" onchange="oai_model_change(true)">
|
||||
|
||||
@@ -348,6 +348,7 @@ struct music_generation_inputs
|
||||
const bool is_planner_mode = false; //if true, generate codes, else, generate diffusion music
|
||||
const bool stereo = false;
|
||||
const bool gen_codes = false;
|
||||
const bool rewrite_caption = true;
|
||||
const char * input_json = nullptr;
|
||||
};
|
||||
struct music_generation_outputs
|
||||
|
||||
@@ -462,6 +462,7 @@ class music_generation_inputs(ctypes.Structure):
|
||||
_fields_ = [("is_planner_mode", ctypes.c_bool),
|
||||
("stereo", ctypes.c_bool),
|
||||
("gen_codes", ctypes.c_bool),
|
||||
("rewrite_caption", ctypes.c_bool),
|
||||
("input_json", ctypes.c_char_p)]
|
||||
|
||||
class music_generation_outputs(ctypes.Structure):
|
||||
@@ -2492,6 +2493,7 @@ def music_generate_codes(genparams):
|
||||
inputs.is_planner_mode = True
|
||||
inputs.stereo = genparams.get('stereo', False)
|
||||
inputs.gen_codes = genparams.get('gen_codes', False)
|
||||
inputs.rewrite_caption = genparams.get('rewrite_caption', True)
|
||||
inputs.input_json = input_json.encode("UTF-8")
|
||||
ret = handle.music_generate(inputs)
|
||||
outstr = ""
|
||||
@@ -2507,6 +2509,7 @@ def music_generate_audio(genparams):
|
||||
inputs.is_planner_mode = False
|
||||
inputs.stereo = genparams.get('stereo', False)
|
||||
inputs.gen_codes = genparams.get('gen_codes', False)
|
||||
inputs.rewrite_caption = genparams.get('rewrite_caption', True)
|
||||
inputs.input_json = input_json.encode("UTF-8")
|
||||
ret = handle.music_generate(inputs)
|
||||
outstr = ""
|
||||
|
||||
+78
-273
@@ -173,6 +173,7 @@ static std::mt19937 acestep_lm_rng;
|
||||
static bool acestep_lm_dbg = false;
|
||||
static std::vector<int32_t> forced_tokens;
|
||||
static std::vector<int> caption_tokens = std::vector<int>(); //will be filled with caption tokens
|
||||
const int rep_pen_range = 48;
|
||||
|
||||
//
|
||||
// CoT parsing (extract metadata + lyrics from LLM Phase1 output)
|
||||
@@ -481,9 +482,11 @@ struct MetadataFSM {
|
||||
};
|
||||
|
||||
State state = DISABLED;
|
||||
int caption_newline_counter = 0;
|
||||
int name_pos = 0;
|
||||
std::vector<int> value_acc;
|
||||
bool enabled = false;
|
||||
bool rewrite_caption = false;
|
||||
|
||||
std::vector<int> bpm_name, caption_name, duration_name;
|
||||
std::vector<int> keyscale_name, language_name, timesig_name;
|
||||
@@ -513,7 +516,7 @@ struct MetadataFSM {
|
||||
}
|
||||
}
|
||||
|
||||
void init(BPETokenizer & bpe, int vsize) {
|
||||
void init(BPETokenizer & bpe, int vsize, bool rew_caption) {
|
||||
vocab_size = vsize;
|
||||
auto nl = bpe_encode(&bpe, "\n", false);
|
||||
newline_tok = nl.empty() ? -1 : nl[0];
|
||||
@@ -531,10 +534,10 @@ struct MetadataFSM {
|
||||
for (int v = 30; v <= 300; v++) vals.push_back(std::to_string(v));
|
||||
build_value_tree(bpe, bpm_tree, "bpm:", vals);
|
||||
}
|
||||
// Duration 10-300
|
||||
// Duration 50-450
|
||||
{
|
||||
std::vector<std::string> vals;
|
||||
for (int v = 10; v <= 300; v++) vals.push_back(std::to_string(v));
|
||||
for (int v = 50; v <= 450; v++) vals.push_back(std::to_string(v));
|
||||
build_value_tree(bpe, duration_tree, "duration:", vals);
|
||||
}
|
||||
// Keyscale
|
||||
@@ -574,12 +577,15 @@ struct MetadataFSM {
|
||||
enabled = true;
|
||||
state = BPM_NAME;
|
||||
name_pos = 0;
|
||||
caption_newline_counter = 0;
|
||||
rewrite_caption = rew_caption;
|
||||
value_acc.clear();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
state = BPM_NAME;
|
||||
name_pos = 0;
|
||||
caption_newline_counter = 0;
|
||||
value_acc.clear();
|
||||
}
|
||||
|
||||
@@ -707,7 +713,27 @@ struct MetadataFSM {
|
||||
}
|
||||
|
||||
if (state == CAPTION_VALUE) {
|
||||
if (token == newline_tok) {
|
||||
if(token==newline_tok && !rewrite_caption)
|
||||
{
|
||||
//not changing caption, so end it now
|
||||
caption_newline_counter = 0;
|
||||
state = DURATION_NAME;
|
||||
name_pos = 0;
|
||||
value_acc.clear();
|
||||
}
|
||||
else if (token == newline_tok) {
|
||||
// caption_newline_counter += 1;
|
||||
// if(caption_newline_counter>=3) //ingest 3 newlines for the caption, making it longer
|
||||
// {
|
||||
caption_newline_counter = 0;
|
||||
state = DURATION_NAME;
|
||||
name_pos = 0;
|
||||
value_acc.clear();
|
||||
// }
|
||||
}
|
||||
else if(token == 17021) // fallback for duration token, immediately go next
|
||||
{
|
||||
caption_newline_counter = 0;
|
||||
state = DURATION_NAME;
|
||||
name_pos = 0;
|
||||
value_acc.clear();
|
||||
@@ -779,7 +805,7 @@ const std::vector<int> think_chain = {271,2,15953,2216,198}; // "\n# Lyric\n"
|
||||
static std::vector<std::string> generate_phase1_batch(
|
||||
Qwen3LM * m, BPETokenizer * bpe,
|
||||
const std::vector<int> & prompt_tokens,
|
||||
int max_new_tokens, float temperature, float top_p,
|
||||
int max_new_tokens, float temperature, float top_p, int top_k, float rep_pen,
|
||||
long long base_seed, int N,
|
||||
MetadataFSM * fsm_template,
|
||||
bool lyrics_mode,
|
||||
@@ -791,6 +817,8 @@ static std::vector<std::string> generate_phase1_batch(
|
||||
bool use_cfg = cfg_scale > 1.0f && uncond_tokens && !uncond_tokens->empty();
|
||||
forced_tokens.clear();
|
||||
|
||||
std::vector<int32_t> quicklastntoks;
|
||||
|
||||
// KV sets: cond [0..N-1], uncond [N..2N-1] if CFG
|
||||
for (int i = 0; i < N; i++) qw3lm_reset_kv(m, i);
|
||||
if (use_cfg)
|
||||
@@ -846,7 +874,11 @@ static std::vector<std::string> generate_phase1_batch(
|
||||
if (fsm_template && fsm_template->enabled)
|
||||
seqs[i].fsm.apply_mask(lg.data());
|
||||
|
||||
int tok = kcpp_quick_sample(lg.data(),V,std::vector<int32_t>(),1.03f,top_p,40,temperature,acestep_lm_rng);
|
||||
int tok = kcpp_quick_sample(lg.data(),V,quicklastntoks,rep_pen,top_p,top_k,temperature,acestep_lm_rng);
|
||||
quicklastntoks.push_back(tok);
|
||||
if (quicklastntoks.size()>rep_pen_range) {
|
||||
quicklastntoks.erase(quicklastntoks.begin());
|
||||
}
|
||||
|
||||
if (tok == TOKEN_IM_END) {
|
||||
seqs[i].done = true;
|
||||
@@ -890,8 +922,6 @@ static std::vector<std::string> generate_phase1_batch(
|
||||
for (int i = 0; i < N; i++)
|
||||
if (seqs[i].done) n_active--;
|
||||
|
||||
std::vector<int32_t> quicklastntoks;
|
||||
|
||||
for (int step = 0; step < max_new_tokens && n_active > 0; step++) {
|
||||
for (int i = 0; i < N; i++)
|
||||
tokens[i] = seqs[i].last_token;
|
||||
@@ -938,9 +968,9 @@ static std::vector<std::string> generate_phase1_batch(
|
||||
if (v != TOKEN_IM_END) lc[v] = -1e9f;
|
||||
}
|
||||
|
||||
int tok = kcpp_quick_sample(lc,V,quicklastntoks,1.03f,top_p,40,temperature,acestep_lm_rng);
|
||||
int tok = kcpp_quick_sample(lc,V,quicklastntoks,rep_pen,top_p,top_k,temperature,acestep_lm_rng);
|
||||
quicklastntoks.push_back(tok);
|
||||
if (quicklastntoks.size()>32) {
|
||||
if (quicklastntoks.size()>rep_pen_range) {
|
||||
quicklastntoks.erase(quicklastntoks.begin());
|
||||
}
|
||||
|
||||
@@ -1008,13 +1038,15 @@ static std::vector<std::string> generate_phase1_batch(
|
||||
// Returns N code strings. Seeds = base_seed + 0, 1, ..., N-1.
|
||||
static std::vector<std::string> run_phase2_batch(
|
||||
Qwen3LM * m, BPETokenizer & bpe, const std::vector<AcePrompt> & aces,
|
||||
float temperature, float top_p, long long base_seed, int N,
|
||||
float temperature, float top_p, int top_k, float rep_pen, long long base_seed, int N,
|
||||
float cfg_scale, const char * negative_prompt) {
|
||||
|
||||
int V = m->cfg.vocab_size;
|
||||
bool use_cfg = cfg_scale > 1.0f;
|
||||
bool shared_prompt = ((int)aces.size() == 1);
|
||||
|
||||
std::vector<int32_t> quicklastntoks;
|
||||
|
||||
// Build per-element prompts
|
||||
std::vector<std::vector<int>> prompts(N), unconds(N);
|
||||
int max_tokens = 0;
|
||||
@@ -1101,7 +1133,12 @@ static std::vector<std::string> run_phase2_batch(
|
||||
for (int v = 0; v < AUDIO_CODE_BASE; v++)
|
||||
if (v != TOKEN_IM_END) lg[v] = -1e9f;
|
||||
|
||||
int tok = kcpp_quick_sample(lg.data(),V,std::vector<int32_t>(),1.03f,top_p,40,temperature,acestep_lm_rng);
|
||||
int tok = kcpp_quick_sample(lg.data(),V,quicklastntoks,rep_pen,top_p,top_k,temperature,acestep_lm_rng);
|
||||
quicklastntoks.push_back(tok);
|
||||
if (quicklastntoks.size()>rep_pen_range) {
|
||||
quicklastntoks.erase(quicklastntoks.begin());
|
||||
}
|
||||
|
||||
seqs[i].last_token = tok;
|
||||
|
||||
if (tok == TOKEN_IM_END) {
|
||||
@@ -1139,7 +1176,6 @@ static std::vector<std::string> run_phase2_batch(
|
||||
for (int i = 0; i < N; i++)
|
||||
if (seqs[i].done) n_active--;
|
||||
|
||||
std::vector<int32_t> quicklastntoks;
|
||||
for (int step = 0; step < max_tokens && n_active > 0; step++) {
|
||||
// Collect tokens (done sequences feed their last token, result ignored)
|
||||
for (int i = 0; i < N; i++)
|
||||
@@ -1173,9 +1209,9 @@ static std::vector<std::string> run_phase2_batch(
|
||||
for (int v = 0; v < AUDIO_CODE_BASE; v++)
|
||||
if (v != TOKEN_IM_END) lc[v] = -1e9f;
|
||||
|
||||
int tok = kcpp_quick_sample(lc,V,quicklastntoks,1.03f,top_p,40,temperature,acestep_lm_rng);
|
||||
int tok = kcpp_quick_sample(lc,V,quicklastntoks,rep_pen,top_p,top_k,temperature,acestep_lm_rng);
|
||||
quicklastntoks.push_back(tok);
|
||||
if (quicklastntoks.size()>32) {
|
||||
if (quicklastntoks.size()>rep_pen_range) {
|
||||
quicklastntoks.erase(quicklastntoks.begin());
|
||||
}
|
||||
seqs[i].last_token = tok;
|
||||
@@ -1236,253 +1272,6 @@ static void usage(const char * prog) {
|
||||
, prog);
|
||||
}
|
||||
|
||||
/*
|
||||
int main(int argc, char ** argv) {
|
||||
const char * model_path = nullptr;
|
||||
const char * request_path = nullptr;
|
||||
int max_seq = 8192;
|
||||
int batch_size = 1;
|
||||
bool use_fsm = true;
|
||||
const char * dump_logits = nullptr;
|
||||
const char * dump_tokens = nullptr;
|
||||
|
||||
if (argc < 2) {
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (!strcmp(argv[i], "--model") && i + 1 < argc)
|
||||
model_path = argv[++i];
|
||||
else if (!strcmp(argv[i], "--request") && i + 1 < argc)
|
||||
request_path = argv[++i];
|
||||
else if (!strcmp(argv[i], "--max-seq") && i + 1 < argc)
|
||||
max_seq = atoi(argv[++i]);
|
||||
else if (!strcmp(argv[i], "--batch") && i + 1 < argc)
|
||||
batch_size = atoi(argv[++i]);
|
||||
else if (!strcmp(argv[i], "--no-fsm"))
|
||||
use_fsm = false;
|
||||
else if (!strcmp(argv[i], "--dump-logits") && i + 1 < argc)
|
||||
dump_logits = argv[++i];
|
||||
else if (!strcmp(argv[i], "--dump-tokens") && i + 1 < argc)
|
||||
dump_tokens = argv[++i];
|
||||
else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Unknown option: %s\n", argv[i]);
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!model_path) {
|
||||
fprintf(stderr, "ERROR: --model required\n");
|
||||
usage(argv[0]); return 1;
|
||||
}
|
||||
if (!request_path) {
|
||||
fprintf(stderr, "ERROR: --request required\n");
|
||||
usage(argv[0]); return 1;
|
||||
}
|
||||
|
||||
// Read request JSON
|
||||
AceRequest req;
|
||||
if (!request_parse(&req, request_path)) return 1;
|
||||
request_dump(&req, stderr);
|
||||
|
||||
if (req.caption.empty()) {
|
||||
fprintf(stderr, "ERROR: caption is empty in %s\n", request_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Resolve seed
|
||||
long long seed = req.seed;
|
||||
if (seed < 0) {
|
||||
std::random_device rd;
|
||||
seed = (int64_t)rd() << 32 | rd();
|
||||
if (seed < 0) seed = -seed; // keep positive
|
||||
}
|
||||
req.seed = seed;
|
||||
|
||||
// Generation params from request
|
||||
float temperature = req.lm_temperature;
|
||||
float top_p = req.lm_top_p;
|
||||
int top_k = req.lm_top_k;
|
||||
float cfg_scale = req.lm_cfg_scale;
|
||||
const char * neg_prompt = req.lm_negative_prompt.c_str();
|
||||
|
||||
Timer t_total;
|
||||
|
||||
// Load BPE tokenizer from model GGUF
|
||||
BPETokenizer bpe;
|
||||
if (!load_bpe_from_gguf(&bpe, model_path)) return 1;
|
||||
|
||||
// Load model
|
||||
int n_kv_sets = (cfg_scale > 1.0f) ? 2 * batch_size : batch_size;
|
||||
Timer t_load;
|
||||
Qwen3LM model;
|
||||
if (!qw3lm_load(&model, model_path, max_seq, n_kv_sets)) return 1;
|
||||
double load_ms = t_load.ms();
|
||||
|
||||
// FSM
|
||||
MetadataFSM fsm;
|
||||
if (use_fsm) fsm.init(bpe, model.cfg.vocab_size);
|
||||
|
||||
// Copy request -> AcePrompt (internal LLM struct)
|
||||
AcePrompt ace = {};
|
||||
ace.caption = req.caption;
|
||||
ace.lyrics = req.lyrics;
|
||||
ace.duration = req.duration;
|
||||
ace.bpm = req.bpm;
|
||||
ace.keyscale = req.keyscale;
|
||||
ace.timesignature = req.timesignature;
|
||||
ace.vocal_language = req.vocal_language;
|
||||
|
||||
bool user_has_codes = !req.audio_codes.empty();
|
||||
bool need_lm_codes = req.thinking && !user_has_codes;
|
||||
|
||||
bool is_simple = ace.lyrics.empty() &&
|
||||
ace.bpm <= 0 && ace.duration <= 0 &&
|
||||
ace.keyscale.empty() && ace.timesignature.empty();
|
||||
|
||||
std::vector<int> prompt;
|
||||
std::vector<AcePrompt> aces; // populated by Phase 1 (simple or partial)
|
||||
|
||||
// Preprocessor: simple mode generates lyrics + metas from caption
|
||||
if (is_simple) {
|
||||
fprintf(stderr, "[Simple] Inspiration\n");
|
||||
|
||||
const char * sys =
|
||||
"# Instruction\n"
|
||||
"Expand the user's input into a more detailed"
|
||||
" and specific musical description:\n";
|
||||
std::string user_msg = ace.caption + "\n\ninstrumental: "
|
||||
+ std::string(req.instrumental ? "true" : "false");
|
||||
prompt = build_custom_prompt(bpe, sys, user_msg.c_str());
|
||||
|
||||
// FSM: reset then optionally force language (shared for both paths)
|
||||
fsm.reset();
|
||||
if (use_fsm && ace.vocal_language != "unknown" && !ace.vocal_language.empty())
|
||||
fsm.force_language(bpe, ace.vocal_language);
|
||||
|
||||
// Phase 1: N lyrics + metadata generations (always batched, N=batch_size)
|
||||
fprintf(stderr, "[Simple] %zu tokens, N=%d, seeds: %lld..%lld\n",
|
||||
prompt.size(), batch_size, seed, seed + batch_size - 1);
|
||||
|
||||
auto phase1_texts = generate_phase1_batch(
|
||||
&model, &bpe, prompt, 2048, temperature, 1.0f, 0,
|
||||
seed, batch_size, use_fsm ? &fsm : nullptr, true);
|
||||
|
||||
parse_phase1_into_aces(phase1_texts, ace, aces, seed, "Simple", true);
|
||||
|
||||
for (int i = 0; i < batch_size; i++) qw3lm_reset_kv(&model, i);
|
||||
}
|
||||
|
||||
// Re-evaluate after possible simple enrichment
|
||||
const AcePrompt & ace_ref = aces.empty() ? ace : aces[0];
|
||||
bool has_all_metas = (ace_ref.bpm > 0 && ace_ref.duration > 0 &&
|
||||
!ace_ref.keyscale.empty() && !ace_ref.timesignature.empty());
|
||||
|
||||
if (!has_all_metas) {
|
||||
// Partial-metas: Phase 1 with CFG to fill missing fields
|
||||
prompt = build_lm_prompt(bpe, ace);
|
||||
std::vector<int> uncond;
|
||||
if (cfg_scale > 1.0f)
|
||||
uncond = build_lm_prompt_uncond(bpe, ace, neg_prompt);
|
||||
|
||||
fprintf(stderr, "[Partial] %zu tokens, CFG: %.2f, N=%d, seeds: %lld..%lld\n",
|
||||
prompt.size(), cfg_scale, batch_size, seed, seed + batch_size - 1);
|
||||
|
||||
fsm.reset();
|
||||
auto phase1_texts = generate_phase1_batch(
|
||||
&model, &bpe, prompt, 2048, temperature, top_p, top_k,
|
||||
seed, batch_size, use_fsm ? &fsm : nullptr, false,
|
||||
cfg_scale, uncond.empty() ? nullptr : &uncond, true);
|
||||
|
||||
parse_phase1_into_aces(phase1_texts, ace, aces, seed, "Partial", false);
|
||||
|
||||
for (int i = 0; i < 2 * batch_size; i++) qw3lm_reset_kv(&model, i);
|
||||
}
|
||||
|
||||
// Guarantee aces is populated (all-metas: single shared ace for prefill optimization)
|
||||
if (aces.empty()) aces = {ace};
|
||||
|
||||
// Debug: dump tokens/logits
|
||||
if (need_lm_codes && (dump_logits || dump_tokens)) {
|
||||
std::string cot = build_cot_yaml(aces[0]);
|
||||
auto dbg_prompt = build_lm_prompt_with_cot(bpe, aces[0], cot);
|
||||
|
||||
if (dump_tokens) {
|
||||
FILE * f = fopen(dump_tokens, "w");
|
||||
if (f) {
|
||||
for (size_t j = 0; j < dbg_prompt.size(); j++)
|
||||
fprintf(f, "%s%d", j ? "," : "", dbg_prompt[j]);
|
||||
fprintf(f, "\n");
|
||||
fclose(f);
|
||||
fprintf(stderr, "[Debug] Tokens -> %s (%zu)\n",
|
||||
dump_tokens, dbg_prompt.size());
|
||||
}
|
||||
}
|
||||
if (dump_logits) {
|
||||
std::vector<float> dbg_logits(model.cfg.vocab_size);
|
||||
qw3lm_forward(&model, dbg_prompt.data(), (int)dbg_prompt.size(), 0, dbg_logits.data());
|
||||
FILE * f = fopen(dump_logits, "wb");
|
||||
if (f) {
|
||||
fwrite(dbg_logits.data(), sizeof(float), model.cfg.vocab_size, f);
|
||||
fclose(f);
|
||||
fprintf(stderr, "[Debug] Logits -> %s (%d floats, argmax=%d)\n",
|
||||
dump_logits, model.cfg.vocab_size,
|
||||
(int)(std::max_element(dbg_logits.begin(), dbg_logits.end()) - dbg_logits.begin()));
|
||||
}
|
||||
qw3lm_reset_kv(&model, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 2: generate audio codes (always batched, N=batch_size)
|
||||
std::vector<std::string> batch_codes(batch_size);
|
||||
if (need_lm_codes) {
|
||||
batch_codes = run_phase2_batch(&model, bpe, aces,
|
||||
temperature, top_p, top_k, seed, batch_size, cfg_scale, neg_prompt);
|
||||
} else {
|
||||
fprintf(stderr, "[Skip] %s, no code generation\n",
|
||||
user_has_codes ? "user codes present" : "thinking=false");
|
||||
}
|
||||
|
||||
// Write N output files: request0.json, request1.json, ...
|
||||
{
|
||||
std::string base(request_path);
|
||||
std::string ext = ".json";
|
||||
size_t dot = base.rfind('.');
|
||||
if (dot != std::string::npos) { ext = base.substr(dot); base = base.substr(0, dot); }
|
||||
for (int b = 0; b < batch_size; b++) {
|
||||
AceRequest rr = req;
|
||||
const AcePrompt & a = aces[b < (int)aces.size() ? b : 0];
|
||||
rr.caption = a.caption;
|
||||
rr.lyrics = a.lyrics;
|
||||
rr.bpm = a.bpm;
|
||||
rr.duration = a.duration;
|
||||
rr.keyscale = a.keyscale;
|
||||
rr.timesignature = a.timesignature;
|
||||
rr.vocal_language = a.vocal_language;
|
||||
if (!batch_codes[b].empty()) rr.audio_codes = batch_codes[b];
|
||||
rr.seed = seed + b;
|
||||
char path[512];
|
||||
snprintf(path, sizeof(path), "%s%d%s", base.c_str(), b, ext.c_str());
|
||||
request_write(&rr, path);
|
||||
fprintf(stderr, "[Output] Wrote %s\n", path);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "[Ace-Qwen3] Load %.0f | Total %.0fms | seed=%lld\n",
|
||||
load_ms, t_total.ms(), seed);
|
||||
|
||||
qw3lm_free(&model);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
//kcpp stuff
|
||||
|
||||
static Qwen3LM acestep_llm;
|
||||
@@ -1538,11 +1327,13 @@ std::string acestep_prepare_request(const music_generation_inputs inputs)
|
||||
}
|
||||
}
|
||||
|
||||
bool rewrite_caption = inputs.rewrite_caption;
|
||||
|
||||
const int batch_size = 1;
|
||||
bool use_fsm = true;
|
||||
MetadataFSM fsm;
|
||||
if (use_fsm) {
|
||||
fsm.init(acestep_bpe, acestep_llm.cfg.vocab_size);
|
||||
fsm.init(acestep_bpe, acestep_llm.cfg.vocab_size,rewrite_caption);
|
||||
}
|
||||
|
||||
// Read request and set essentials
|
||||
@@ -1570,8 +1361,13 @@ std::string acestep_prepare_request(const music_generation_inputs inputs)
|
||||
float temperature = req.lm_temperature;
|
||||
float top_p = req.lm_top_p;
|
||||
int top_k = req.lm_top_k;
|
||||
float rep_pen = req.lm_rep_pen;
|
||||
float cfg_scale = req.lm_cfg_scale;
|
||||
float phase1cfg = 1.0f;
|
||||
const char * neg_prompt = req.lm_negative_prompt.c_str();
|
||||
float codes_temperature = req.codes_temperature;
|
||||
float codes_top_p = req.codes_top_p;
|
||||
int codes_top_k = req.codes_top_k;
|
||||
|
||||
// Copy request -> AcePrompt (internal LLM struct)
|
||||
AcePrompt ace = {};
|
||||
@@ -1592,10 +1388,10 @@ std::string acestep_prepare_request(const music_generation_inputs inputs)
|
||||
std::vector<AcePrompt> aces; // populated by Phase 1 (simple or partial)
|
||||
|
||||
caption_tokens.clear();
|
||||
// if(ace.caption!="")
|
||||
// {
|
||||
// caption_tokens = bpe_encode(&acestep_bpe, ace.caption+"\n", false);
|
||||
// }
|
||||
if(ace.caption!="" && !rewrite_caption)
|
||||
{
|
||||
caption_tokens = bpe_encode(&acestep_bpe, ace.caption+"\n", false);
|
||||
}
|
||||
|
||||
// Preprocessor: simple mode generates lyrics + metas from caption
|
||||
if (is_simple) {
|
||||
@@ -1619,7 +1415,7 @@ std::string acestep_prepare_request(const music_generation_inputs inputs)
|
||||
prompt.size(), batch_size, seed, seed + batch_size - 1);
|
||||
|
||||
auto phase1_texts = generate_phase1_batch(
|
||||
&acestep_llm, &acestep_bpe, prompt, 2048, temperature, top_p,
|
||||
&acestep_llm, &acestep_bpe, prompt, 2048, temperature, top_p, top_k, rep_pen,
|
||||
seed, batch_size, use_fsm ? &fsm : nullptr, true);
|
||||
|
||||
parse_phase1_into_aces(phase1_texts, ace, aces, seed, "Simple", true);
|
||||
@@ -1636,17 +1432,17 @@ std::string acestep_prepare_request(const music_generation_inputs inputs)
|
||||
// Partial-metas: Phase 1 with CFG to fill missing fields
|
||||
prompt = build_lm_prompt(acestep_bpe, ace);
|
||||
std::vector<int> uncond;
|
||||
if (cfg_scale > 1.0f)
|
||||
if (phase1cfg > 1.0f)
|
||||
uncond = build_lm_prompt_uncond(acestep_bpe, ace, neg_prompt);
|
||||
|
||||
fprintf(stderr, "[Partial] %zu tokens, CFG: %.2f, N=%d, seeds: %lld..%lld\n",
|
||||
prompt.size(), cfg_scale, batch_size, seed, seed + batch_size - 1);
|
||||
prompt.size(), phase1cfg, batch_size, seed, seed + batch_size - 1);
|
||||
|
||||
fsm.reset();
|
||||
auto phase1_texts = generate_phase1_batch(
|
||||
&acestep_llm, &acestep_bpe, prompt, 2048, temperature, top_p,
|
||||
&acestep_llm, &acestep_bpe, prompt, 2048, temperature, top_p, top_k, rep_pen,
|
||||
seed, batch_size, use_fsm ? &fsm : nullptr, false,
|
||||
cfg_scale, uncond.empty() ? nullptr : &uncond, true);
|
||||
phase1cfg, uncond.empty() ? nullptr : &uncond, true);
|
||||
|
||||
parse_phase1_into_aces(phase1_texts, ace, aces, seed, "Partial", false);
|
||||
|
||||
@@ -1663,7 +1459,7 @@ std::string acestep_prepare_request(const music_generation_inputs inputs)
|
||||
std::vector<std::string> batch_codes(batch_size);
|
||||
if (need_lm_codes) {
|
||||
batch_codes = run_phase2_batch(&acestep_llm, acestep_bpe, aces,
|
||||
temperature, top_p, seed, batch_size, cfg_scale, neg_prompt);
|
||||
temperature, top_p, top_k, rep_pen, seed, batch_size, cfg_scale, neg_prompt);
|
||||
} else {
|
||||
fprintf(stderr, "[Skip] %s, no code generation\n",
|
||||
user_has_codes ? "user codes present" : "thinking=false");
|
||||
@@ -1693,6 +1489,10 @@ std::string acestep_prepare_request(const music_generation_inputs inputs)
|
||||
rr.keyscale = rr.keyscale.substr(prefix_erase.size()); // Returns a new string starting after the prefix
|
||||
}
|
||||
|
||||
std::string delimiter = "durationduration";
|
||||
size_t ddpos = rr.caption.find(delimiter);
|
||||
rr.caption = ((ddpos != std::string::npos) ? rr.caption.substr(0, ddpos) : rr.caption);
|
||||
|
||||
//now convert to string
|
||||
std::ostringstream oss;
|
||||
oss << "{\n";
|
||||
@@ -1712,6 +1512,11 @@ std::string acestep_prepare_request(const music_generation_inputs inputs)
|
||||
oss << " \"lm_temperature\": " << std::fixed << std::setprecision(2) << rr.lm_temperature << ",\n";
|
||||
oss << " \"lm_cfg_scale\": " << std::fixed << std::setprecision(1) << rr.lm_cfg_scale << ",\n";
|
||||
oss << " \"lm_top_p\": " << std::fixed << std::setprecision(2) << rr.lm_top_p << ",\n";
|
||||
oss << " \"lm_top_k\": " << std::fixed << std::setprecision(1) << rr.lm_top_k << ",\n";
|
||||
oss << " \"codes_temperature\": " << std::fixed << std::setprecision(2) << rr.codes_temperature << ",\n";
|
||||
oss << " \"codes_top_p\": " << std::fixed << std::setprecision(2) << rr.codes_top_p << ",\n";
|
||||
oss << " \"codes_top_k\": " << std::fixed << std::setprecision(1) << rr.codes_top_k << ",\n";
|
||||
oss << " \"lm_rep_pen\": " << std::fixed << std::setprecision(2) << rr.lm_rep_pen << ",\n";
|
||||
oss << " \"lm_negative_prompt\": \"" << json_escape(rr.lm_negative_prompt) << "\",\n";
|
||||
oss << " \"inference_steps\": " << rr.inference_steps << ",\n";
|
||||
oss << " \"guidance_scale\": " << std::fixed << std::setprecision(1) << rr.guidance_scale << ",\n";
|
||||
|
||||
@@ -23,10 +23,14 @@ void request_init(AceRequest * r) {
|
||||
r->task_type = "text2music";
|
||||
r->seed = -1;
|
||||
r->thinking = false;
|
||||
r->lm_temperature = 1.0f;
|
||||
r->lm_temperature = 0.85f;
|
||||
r->lm_cfg_scale = 3.0f;
|
||||
r->lm_top_p = 0.95f;
|
||||
r->lm_top_k = 0;
|
||||
r->lm_top_p = 0.9f;
|
||||
r->lm_top_k = 50;
|
||||
r->codes_temperature = 1.0f;
|
||||
r->codes_top_p = 0.99f;
|
||||
r->codes_top_k = 1000;
|
||||
r->lm_rep_pen = 1.03f;
|
||||
r->lm_negative_prompt = "";
|
||||
r->audio_codes = "";
|
||||
r->inference_steps = 8;
|
||||
@@ -241,11 +245,16 @@ bool request_parse_from_str(AceRequest * r, std::string json) {
|
||||
else if (k == "lm_temperature") r->lm_temperature = (float)atof(v.c_str());
|
||||
else if (k == "lm_cfg_scale") r->lm_cfg_scale = (float)atof(v.c_str());
|
||||
else if (k == "lm_top_p") r->lm_top_p = (float)atof(v.c_str());
|
||||
else if (k == "lm_rep_pen") r->lm_rep_pen = (float)atof(v.c_str());
|
||||
else if (k == "lm_top_k") r->lm_top_k = atoi(v.c_str());
|
||||
else if (k == "inference_steps") r->inference_steps = atoi(v.c_str());
|
||||
else if (k == "guidance_scale") r->guidance_scale = (float)atof(v.c_str());
|
||||
else if (k == "shift") r->shift = (float)atof(v.c_str());
|
||||
|
||||
else if (k == "codes_temperature") r->codes_temperature = (float)atof(v.c_str());
|
||||
else if (k == "codes_top_p") r->codes_top_p = (float)atof(v.c_str());
|
||||
else if (k == "codes_top_k") r->codes_top_k = atoi(v.c_str());
|
||||
|
||||
// bools
|
||||
else if (k == "thinking") r->thinking = (v == "true");
|
||||
else if (k == "instrumental") r->instrumental = (v == "true");
|
||||
@@ -279,7 +288,11 @@ bool request_write(const AceRequest * r, const char * path) {
|
||||
fprintf(f, " \"lm_temperature\": %.2f,\n", r->lm_temperature);
|
||||
fprintf(f, " \"lm_cfg_scale\": %.1f,\n", r->lm_cfg_scale);
|
||||
fprintf(f, " \"lm_top_p\": %.2f,\n", r->lm_top_p);
|
||||
fprintf(f, " \"lm_rep_pen\": %.2f,\n", r->lm_rep_pen);
|
||||
fprintf(f, " \"lm_top_k\": %d,\n", r->lm_top_k);
|
||||
fprintf(f, " \"codes_temperature\": %.2f,\n", r->codes_temperature);
|
||||
fprintf(f, " \"codes_top_p\": %.2f,\n", r->codes_top_p);
|
||||
fprintf(f, " \"codes_top_k\": %d,\n", r->codes_top_k);
|
||||
fprintf(f, " \"lm_negative_prompt\": \"%s\",\n", json_escape(r->lm_negative_prompt).c_str());
|
||||
fprintf(f, " \"inference_steps\": %d,\n", r->inference_steps);
|
||||
fprintf(f, " \"guidance_scale\": %.1f,\n", r->guidance_scale);
|
||||
@@ -302,8 +315,10 @@ void request_dump(const AceRequest * r, FILE * f) {
|
||||
fprintf(f, " bpm=%d dur=%.0f key=%s ts=%s lang=%s\n",
|
||||
r->bpm, r->duration, r->keyscale.c_str(),
|
||||
r->timesignature.c_str(), r->vocal_language.c_str());
|
||||
fprintf(f, " lm: temp=%.2f cfg=%.1f top_p=%.2f top_k=%d\n",
|
||||
r->lm_temperature, r->lm_cfg_scale, r->lm_top_p, r->lm_top_k);
|
||||
fprintf(f, " lm: temp=%.2f cfg=%.1f top_p=%.2f top_k=%d rep_pen=%d\n",
|
||||
r->lm_temperature, r->lm_cfg_scale, r->lm_top_p, r->lm_top_k, r->lm_rep_pen);
|
||||
fprintf(f, " codes: temp=%.2f top_p=%.2f top_k=%d \n",
|
||||
r->lm_temperature, r->lm_top_p, r->lm_top_k);
|
||||
fprintf(f, " dit: steps=%d guidance=%.1f shift=%.1f\n",
|
||||
r->inference_steps, r->guidance_scale, r->shift);
|
||||
fprintf(f, " audio_codes: %s\n",
|
||||
|
||||
@@ -32,8 +32,13 @@ struct AceRequest {
|
||||
float lm_cfg_scale; // 2.0
|
||||
float lm_top_p; // 0.9
|
||||
int lm_top_k; // 0 = disabled (matches Python None)
|
||||
float lm_rep_pen; // 1.03
|
||||
std::string lm_negative_prompt; // "NO USER INPUT"
|
||||
|
||||
int codes_top_k;
|
||||
float codes_top_p;
|
||||
float codes_temperature;
|
||||
|
||||
// codes (Python-compatible string: "3101,11837,27514,...")
|
||||
// empty = text2music (silence context), non-empty = cover mode
|
||||
std::string audio_codes; // ""
|
||||
|
||||
Reference in New Issue
Block a user