refa: auto generate sd samplers from api (#232)

This commit is contained in:
Maiko Sinkyaet Tan 2024-02-28 22:38:45 +08:00 committed by GitHub
parent 179b41bd1e
commit 2540cdca9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 33 deletions

View File

@ -0,0 +1,26 @@
const fsp = require('fs/promises')
const http = require('http')
const path = require('path')
const API_ROOT = process.argv[2] || 'http://localhost:7860'
const SAMPLERS_ENDPOINT = '/sdapi/v1/samplers'
const DATA_JSON_PATH = path.join(__dirname, '..', 'data', 'sd-samplers.json')
;(async () => {
const r = await new Promise((resolve, reject) => {
http.get(API_ROOT + SAMPLERS_ENDPOINT, res => {
let data = ''
res.on('data', chunk => data += chunk)
res.on('end', () => resolve(JSON.parse(data)))
}).on('error', reject)
})
const samplers = r.reduce((acc, sampler) => {
const { name, aliases, options } = sampler
acc[aliases[0]] = name
return acc
}, {})
const json = JSON.stringify(samplers, null, 2)
await fsp.writeFile(DATA_JSON_PATH, json + '\n')
})()

31
data/sd-samplers.json Normal file
View File

@ -0,0 +1,31 @@
{
"k_dpmpp_2m_ka": "DPM++ 2M Karras",
"k_dpmpp_sde_ka": "DPM++ SDE Karras",
"k_dpmpp_2m_sde_exp": "DPM++ 2M SDE Exponential",
"k_dpmpp_2m_sde_ka": "DPM++ 2M SDE",
"k_euler_a": "Euler a",
"k_euler": "Euler",
"k_lms": "LMS",
"k_heun": "Heun",
"k_dpm_2": "DPM2",
"k_dpm_2_a": "DPM2 a",
"k_dpmpp_2s_a": "DPM++ 2S a",
"k_dpmpp_2m": "DPM++ 2M",
"k_dpmpp_sde": "DPM++ SDE",
"k_dpmpp_2m_sde_heun": "DPM++ 2M SDE Heun",
"k_dpmpp_2m_sde_heun_ka": "DPM++ 2M SDE Heun Karras",
"k_dpmpp_2m_sde_heun_exp": "DPM++ 2M SDE Heun Exponential",
"k_dpmpp_3m_sde": "DPM++ 3M SDE",
"k_dpmpp_3m_sde_ka": "DPM++ 3M SDE Karras",
"k_dpmpp_3m_sde_exp": "DPM++ 3M SDE Exponential",
"k_dpm_fast": "DPM fast",
"k_dpm_ad": "DPM adaptive",
"k_lms_ka": "LMS Karras",
"k_dpm_2_ka": "DPM2 Karras",
"k_dpm_2_a_ka": "DPM2 a Karras",
"k_dpmpp_2s_a_ka": "DPM++ 2S a Karras",
"restart": "Restart",
"ddim": "DDIM",
"plms": "PLMS",
"unipc": "UniPC"
}

View File

@ -53,39 +53,8 @@ export namespace sampler {
}
// samplers in stable-diffusion-webui
// https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/sd_samplers_compvis.py#L12
// https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/sd_samplers_kdiffusion.py#L12
export const sd = {
k_dpmpp_2m_ka: 'DPM++ 2M Karras',
k_dpmpp_sde_ka: 'DPM++ SDE Karras',
k_dpmpp_2m_sde_exp: 'DPM++ 2M SDE Exponential',
k_dpmpp_2m_sde_ka: 'DPM++ 2M SDE',
k_euler_a: 'Euler a',
k_euler: 'Euler',
k_lms: 'LMS',
k_heun: 'Heun',
k_dpm_2: 'DPM2',
k_dpm_2_a: 'DPM2 a',
k_dpmpp_2s_a: 'DPM++ 2S a',
k_dpmpp_2m: 'DPM++ 2M',
k_dpmpp_sde: 'DPM++ SDE',
k_dpmpp_2m_sde_heun: 'DPM++ 2M SDE Heun',
k_dpmpp_2m_sde_heun_ka: 'DPM++ 2M SDE Heun Karras',
k_dpmpp_2m_sde_heun_exp: 'DPM++ 2M SDE Heun Exponential',
k_dpmpp_3m_sde: 'DPM++ 3M SDE',
k_dpmpp_3m_sde_ka: 'DPM++ 3M SDE Karras',
k_dpmpp_3m_sde_exp: 'DPM++ 3M SDE Exponential',
k_dpm_fast: 'DPM fast',
k_dpm_ad: 'DPM adaptive',
k_lms_ka: 'LMS Karras',
k_dpm_2_ka: 'DPM2 Karras',
k_dpm_2_a_ka: 'DPM2 a Karras',
k_dpmpp_2s_a_ka: 'DPM++ 2S a Karras',
restart: 'Restart',
ddim: 'DDIM',
plms: 'PLMS',
unipc: 'UniPC',
}
// auto-generated by `build/fetch-sd-samplers.js`
export const sd = require('../data/sd-samplers.json') as Dict<string>
export const horde = {
k_lms: 'LMS',