Restore Klein empty-latent reference sampling

This commit is contained in:
Towsty
2026-09-12 12:18:14 -05:00
parent 7bb4b16c1e
commit e190496eb4
2 changed files with 38 additions and 30 deletions
+14 -10
View File
@@ -22,9 +22,9 @@ async function prepare(request){
for(const sourceId of ['hero','source','']) test(`Klein edit samples source with hero ${sourceId || 'as sole source'}`,async()=>{
const q=validateRequest({folderId:'f',mode:'edit',engine:'flux',imageAId:sourceId,identityStillId:'hero',lockFace:true,lockOutfit:false,prompt:'she at a pool'})
const {graph,record,uploads}=await prepare(q)
assert.deepEqual(graph['19'].inputs.latent_image,['11',0]);assert.equal(graph['14'],undefined)
assert.deepEqual(graph['19'].inputs.sigmas,['source_sigmas',1]);assert.equal(graph.source_sigmas.inputs.denoise,.45)
assert.equal(record.sourceStillId,sourceId||'hero');assert.equal(record.sampleLatent,'source')
assert.deepEqual(graph['19'].inputs.latent_image,['14',0]);assert.equal(graph['14'].class_type,'EmptyFlux2LatentImage')
assert.deepEqual(graph['19'].inputs.sigmas,['17',0]);assert.equal(graph.source_sigmas,undefined)
assert.equal(record.sourceStillId,sourceId||'hero');assert.equal(record.sampleLatent,'empty+reference')
assert.equal(uploads.includes('hero'),sourceId==='source');assert.equal(!!graph.hero_load,sourceId==='source')
assert.match(q.compiledPrompt,/face, glasses, hair/);assert.match(q.compiledPrompt,/do not restore the hero outfit/)
})
@@ -51,22 +51,26 @@ for (const imageAId of ['', 'hero', 'other']) test('Generate samples hero exclus
const {graph,record,uploads}=await prepare(q)
assert.equal(record.graphId,'klein_v2_edit.json')
assert.equal(record.sourceStillId,'hero')
assert.equal(record.sampleLatent,'source')
assert.equal(record.sampleDenoise,.45)
assert.deepEqual(graph['19'].inputs.latent_image,['11',0])
assert.equal(record.sampleLatent,'empty+reference')
assert.equal(record.sampleDenoise,null)
assert.deepEqual(graph['19'].inputs.latent_image,['14',0])
assert.deepEqual(uploads,['source'])
assert.equal(graph.hero_load,undefined)
assert.deepEqual(q.settings.loraStack,[])
assert.doesNotMatch(q.compiledPrompt,/Picture 1/)
})
test('unlocked source uses .65; text-only uses empty latent',async()=>{
test('reference sampling ignores face-lock denoise; text-only uses empty latent',async()=>{
const q=validateRequest({folderId:'f',mode:'edit',engine:'flux',imageAId:'source',lockFace:false,prompt:'pool'})
assert.equal((await prepare(q)).record.sampleDenoise,.65)
assert.equal((await prepare(q)).record.sampleDenoise,null)
const empty=validateRequest({folderId:'f',mode:'generate',engine:'flux',prompt:'pool'})
assert.equal((await prepare(empty)).record.sampleLatent,'empty')
})
test('reject empty sample with source and exclude other engines',()=>{
assert.throws(()=>assertKleinSample(template,'hero'),/empty-latent sampling was rejected/)
test('validate live references and reject direct source sampling',()=>{
assert.equal(assertKleinSample(template,'hero'),'empty+reference')
const broken=structuredClone(template);broken['18'].inputs.positive=['9',0]
assert.throws(()=>assertKleinSample(broken,'hero'),/reference conditioning is missing/)
const copy=structuredClone(template);copy['19'].inputs.latent_image=['11',0]
assert.throws(()=>assertKleinSample(copy,'hero'),/not the source image latent/)
assert.equal(kleinIdentityPlan({engine:'krea',mode:'generate',identityStillId:'hero'}),null)
assert.equal(kleinIdentityPlan({engine:'minimax',mode:'extend'}),null)
})