Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refa: auto generate sd samplers from api #232

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions build/fetch-sd-samplers.js
Original file line number Diff line number Diff line change
@@ -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 changes: 31 additions & 0 deletions data/sd-samplers.json
Original file line number Diff line number Diff line change
@@ -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"
}
35 changes: 2 additions & 33 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading